MCPcopy
hub / github.com/coder/websocket / Write

Method Write

ws_js.go:198–211  ·  view source on GitHub ↗

Write writes a message of the given type to the connection. Always non blocking.

(ctx context.Context, typ MessageType, p []byte)

Source from the content-addressed store, hash-verified

196// Write writes a message of the given type to the connection.
197// Always non blocking.
198func (c *Conn) Write(ctx context.Context, typ MessageType, p []byte) error {
199 err := c.write(typ, p)
200 if err != nil {
201 // Have to ensure the WebSocket is closed after a write error
202 // to match the Go API. It can only error if the message type
203 // is unexpected or the passed bytes contain invalid UTF-8 for
204 // MessageText.
205 err := fmt.Errorf("failed to write: %w", err)
206 c.setCloseErr(err)
207 c.closeWithInternal()
208 return err
209 }
210 return nil
211}
212
213func (c *Conn) write(typ MessageType, p []byte) error {
214 if c.isClosed() {

Callers 14

TestConnFunction · 0.45
BenchmarkConnFunction · 0.45
TestConnClosePropagationFunction · 0.45
BenchmarkFlateWriterFunction · 0.45
BenchmarkFlateReaderFunction · 0.45
RecordBytesWrittenMethod · 0.45
secWebSocketAcceptFunction · 0.45
WriteMethod · 0.45
CloseMethod · 0.45

Calls 3

writeMethod · 0.95
setCloseErrMethod · 0.95
closeWithInternalMethod · 0.95

Tested by 9

TestConnFunction · 0.36
BenchmarkConnFunction · 0.36
TestConnClosePropagationFunction · 0.36
BenchmarkFlateWriterFunction · 0.36
BenchmarkFlateReaderFunction · 0.36
RecordBytesWrittenMethod · 0.36