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

Method WriteMessage

conn.go:758–781  ·  conn.go::Conn.WriteMessage

WriteMessage is a helper method for getting a writer using NextWriter, writing the message and closing the writer.

(messageType int, data []byte)

Source from the content-addressed store, hash-verified

756// WriteMessage is a helper method for getting a writer using NextWriter,
757// writing the message and closing the writer.
758func (c *Conn) WriteMessage(messageType int, data []byte) error {
759
760 if c.isServer && (c.newCompressionWriter == nil || !c.enableWriteCompression) {
761 // Fast path with no allocations and single frame.
762
763 var mw messageWriter
764 if err := c.beginMessage(&mw, messageType); err != nil {
765 return err
766 }
767 n := copy(c.writeBuf[mw.pos:], data)
768 mw.pos += n
769 data = data[n:]
770 return mw.flushFrame(true, data)
771 }
772
773 w, err := c.NextWriter(messageType)
774 if err != nil {
775 return err
776 }
777 if _, err = w.Write(data); err != nil {
778 return err
779 }
780 return w.Close()
781}
782
783// SetWriteDeadline sets the write deadline on the underlying network
784// connection. After a write has timed out, the websocket state is corrupt and

Callers 15

frameMethod · 0.95
TestWriteBufferPoolFunction · 0.80
TestWriteBufferPoolSyncFunction · 0.80
TestWriteBufferPoolErrorFunction · 0.80
TestReadLimitFunction · 0.80
TestConcurrentWritePanicFunction · 0.80
sendRecvFunction · 0.80
TestPreparedMessageFunction · 0.80
makeConnsMethod · 0.80
TestJoinMessagesFunction · 0.80
TestPartialJSONReadFunction · 0.80

Calls 5

beginMessageMethod · 0.95
flushFrameMethod · 0.95
NextWriterMethod · 0.95
WriteMethod · 0.45
CloseMethod · 0.45

Tested by 12

TestWriteBufferPoolFunction · 0.64
TestWriteBufferPoolSyncFunction · 0.64
TestWriteBufferPoolErrorFunction · 0.64
TestReadLimitFunction · 0.64
TestConcurrentWritePanicFunction · 0.64
sendRecvFunction · 0.64
TestPreparedMessageFunction · 0.64
makeConnsMethod · 0.64
TestJoinMessagesFunction · 0.64
TestPartialJSONReadFunction · 0.64