MCPcopy Index your code
hub / github.com/coder/websocket / Read

Method Read

ws_js.go:133–152  ·  view source on GitHub ↗

Read attempts to read a message from the connection. The maximum time spent waiting is bounded by the context.

(ctx context.Context)

Source from the content-addressed store, hash-verified

131// Read attempts to read a message from the connection.
132// The maximum time spent waiting is bounded by the context.
133func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) {
134 c.closeReadMu.Lock()
135 closedRead := c.closeReadCtx != nil
136 c.closeReadMu.Unlock()
137 if closedRead {
138 return 0, nil, errors.New("WebSocket connection read closed")
139 }
140
141 typ, p, err := c.read(ctx)
142 if err != nil {
143 return 0, nil, fmt.Errorf("failed to read: %w", err)
144 }
145 readLimit := c.msgReadLimit.Load()
146 if readLimit >= 0 && int64(len(p)) > readLimit {
147 reason := fmt.Errorf("read limited at %d bytes", c.msgReadLimit.Load())
148 c.Close(StatusMessageTooBig, reason.Error())
149 return 0, nil, fmt.Errorf("%w: %v", ErrMessageTooBig, reason)
150 }
151 return typ, p, nil
152}
153
154func (c *Conn) read(ctx context.Context) (MessageType, []byte, error) {
155 select {

Callers 1

ReaderMethod · 0.95

Calls 4

readMethod · 0.95
CloseMethod · 0.95
LockMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected