MCPcopy
hub / github.com/nats-io/nats.go / wsEnqueueCloseMsgLocked

Method wsEnqueueCloseMsgLocked

ws.go:727–749  ·  view source on GitHub ↗
(status int, payload string)

Source from the content-addressed store, hash-verified

725}
726
727func (nc *Conn) wsEnqueueCloseMsgLocked(status int, payload string) {
728 wr, ok := nc.bw.w.(*websocketWriter)
729 if !ok || wr.cmDone {
730 return
731 }
732 statusAndPayloadLen := 2 + len(payload)
733 frame := make([]byte, 2+4+statusAndPayloadLen)
734 n, key := wsFillFrameHeader(frame, false, wsCloseMessage, statusAndPayloadLen)
735 // Set the status
736 binary.BigEndian.PutUint16(frame[n:], uint16(status))
737 // If there is a payload, copy
738 if len(payload) > 0 {
739 copy(frame[n+2:], payload)
740 }
741 // Mask status + payload
742 wsMaskBuf(key, frame[n:n+statusAndPayloadLen])
743 wr.cm = frame
744 wr.cmDone = true
745 nc.bw.flush()
746 if c := wr.compressor; c != nil {
747 c.Close()
748 }
749}
750
751func (nc *Conn) wsEnqueueControlMsg(needsLock bool, frameType wsOpCode, payload []byte) {
752 // In some low-level unit tests it will happen...

Callers 2

wsCloseMethod · 0.95
wsEnqueueCloseMsgMethod · 0.95

Calls 4

wsFillFrameHeaderFunction · 0.85
wsMaskBufFunction · 0.85
flushMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected