上一篇文章我们知道了客户端是如何来处理取消功能的,那么,本篇文章我们从服务器端一侧来了解取消功能的原理。
1、分析入口 |
帧接收器接收到RST帧,交由RST处理器处理。
进入到帧接收器里
进入grpc-go/internal/transport/http2_server.go文件中的HandleStreams方法里:
1.func (t *http2Server) HandleStreams(handle func(*Stream), traceCtx func(context.Context, string) context.Context) {
2. //---省略掉不相关代码--
3. frame, err := t.framer.fr.ReadFrame()
4. //---省略掉不相关代码--
5.
6. switch frame := frame.(type) {
7. case *http2.RSTStreamFrame:
8. t.handleRSTStream(frame)
9. //---省略掉不相关代码--
10. }
11.}
主要处理流程说明:
- 第3行:读取帧
- 第6行:获取帧的类型
- 第7-8行:当真的类型是http2.RSTStr