MCPcopy
hub / github.com/gorilla/websocket / readPump

Method readPump

examples/chat/client.go:56–75  ·  view source on GitHub ↗

readPump pumps messages from the websocket connection to the hub. The application runs readPump in a per-connection goroutine. The application ensures that there is at most one reader on a connection by executing all reads from this goroutine.

()

Source from the content-addressed store, hash-verified

54// ensures that there is at most one reader on a connection by executing all
55// reads from this goroutine.
56func (c *Client) readPump() {
57 defer func() {
58 c.hub.unregister <- c
59 c.conn.Close()
60 }()
61 c.conn.SetReadLimit(maxMessageSize)
62 c.conn.SetReadDeadline(time.Now().Add(pongWait))
63 c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
64 for {
65 _, message, err := c.conn.ReadMessage()
66 if err != nil {
67 if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
68 log.Printf("error: %v", err)
69 }
70 break
71 }
72 message = bytes.TrimSpace(bytes.Replace(message, newline, space, -1))
73 c.hub.broadcast <- message
74 }
75}
76
77// writePump pumps messages from the hub to the websocket connection.
78//

Callers 1

serveWsFunction · 0.95

Calls 6

IsUnexpectedCloseErrorFunction · 0.92
SetReadLimitMethod · 0.80
SetPongHandlerMethod · 0.80
ReadMessageMethod · 0.80
CloseMethod · 0.45
SetReadDeadlineMethod · 0.45

Tested by

no test coverage detected