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

Method readLoop

server/hdl_websock.go:39–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37}
38
39func (sess *Session) readLoop() {
40 defer func() {
41 sess.closeWS()
42 sess.cleanUp(false)
43 }()
44
45 sess.ws.SetReadLimit(globals.maxMessageSize)
46 sess.ws.SetReadDeadline(time.Now().Add(pongWait))
47 sess.ws.SetPongHandler(func(string) error {
48 sess.ws.SetReadDeadline(time.Now().Add(pongWait))
49 return nil
50 })
51
52 for {
53 // Read a ClientComMessage
54 _, raw, err := sess.ws.ReadMessage()
55 if err != nil {
56 if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure,
57 websocket.CloseNormalClosure) {
58 logs.Err.Println("ws: readLoop", sess.sid, err)
59 }
60 return
61 }
62 statsInc("IncomingMessagesWebsockTotal", 1)
63 sess.dispatchRaw(raw)
64 }
65}
66
67func (sess *Session) sendMessage(msg any) bool {
68 if len(sess.send) > sendQueueLimit {

Callers 1

serveWebSocketFunction · 0.95

Calls 6

closeWSMethod · 0.95
cleanUpMethod · 0.95
dispatchRawMethod · 0.95
statsIncFunction · 0.85
PrintlnMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected