MCPcopy
hub / github.com/tinode/chat / writeGrpcLoop

Method writeGrpcLoop

server/hdl_grpc.go:89–137  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87}
88
89func (sess *Session) writeGrpcLoop() {
90 defer func() {
91 sess.closeGrpc() // exit MessageLoop
92 }()
93
94 for {
95 select {
96 case msg, ok := <-sess.send:
97 if !ok {
98 // channel closed
99 return
100 }
101 switch v := msg.(type) {
102 case []*ServerComMessage: // batch of unserialized messages
103 for _, msg := range v {
104 w := sess.serializeAndUpdateStats(msg)
105 if !sess.sendMessageGrpc(w) {
106 return
107 }
108 }
109 case *ServerComMessage: // single unserialized message
110 w := sess.serializeAndUpdateStats(v)
111 if !sess.sendMessageGrpc(w) {
112 return
113 }
114 default: // serialized message
115 if !sess.sendMessageGrpc(v) {
116 return
117 }
118 }
119
120 case <-sess.bkgTimer.C:
121 if sess.background {
122 sess.background = false
123 sess.onBackgroundTimer()
124 }
125
126 case msg := <-sess.stop:
127 // Shutdown requested, don't care if the message is delivered
128 if msg != nil {
129 grpcWrite(sess, msg)
130 }
131 return
132
133 case topic := <-sess.detach:
134 sess.delSub(topic)
135 }
136 }
137}
138
139func grpcWrite(sess *Session, msg any) error {
140 if out := sess.grpcnode; out != nil {

Callers 1

MessageLoopMethod · 0.95

Calls 6

closeGrpcMethod · 0.95
sendMessageGrpcMethod · 0.95
onBackgroundTimerMethod · 0.95
delSubMethod · 0.95
grpcWriteFunction · 0.85

Tested by

no test coverage detected