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

Method bytesErr

close.go:309–322  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

307const maxCloseReason = maxControlPayload - 2
308
309func (ce CloseError) bytesErr() ([]byte, error) {
310 if len(ce.Reason) > maxCloseReason {
311 return nil, fmt.Errorf("reason string max is %v but got %q with length %v", maxCloseReason, ce.Reason, len(ce.Reason))
312 }
313
314 if !validWireCloseCode(ce.Code) {
315 return nil, fmt.Errorf("status code %v cannot be set", ce.Code)
316 }
317
318 buf := make([]byte, 2+len(ce.Reason))
319 binary.BigEndian.PutUint16(buf, uint16(ce.Code))
320 copy(buf[2:], ce.Reason)
321 return buf, nil
322}
323
324func (c *Conn) casClosing() bool {
325 return c.closing.Swap(true)

Callers 2

bytesMethod · 0.95
TestCloseErrorFunction · 0.80

Calls 1

validWireCloseCodeFunction · 0.85

Tested by 1

TestCloseErrorFunction · 0.64