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

Method beginMessage

conn.go:475–508  ·  view source on GitHub ↗

beginMessage prepares a connection and message writer for a new message.

(mw *messageWriter, messageType int)

Source from the content-addressed store, hash-verified

473
474// beginMessage prepares a connection and message writer for a new message.
475func (c *Conn) beginMessage(mw *messageWriter, messageType int) error {
476 // Close previous writer if not already closed by the application. It's
477 // probably better to return an error in this situation, but we cannot
478 // change this without breaking existing applications.
479 if c.writer != nil {
480 c.writer.Close()
481 c.writer = nil
482 }
483
484 if !isControl(messageType) && !isData(messageType) {
485 return errBadWriteOpCode
486 }
487
488 c.writeErrMu.Lock()
489 err := c.writeErr
490 c.writeErrMu.Unlock()
491 if err != nil {
492 return err
493 }
494
495 mw.c = c
496 mw.frameType = messageType
497 mw.pos = maxFrameHeaderSize
498
499 if c.writeBuf == nil {
500 wpd, ok := c.writePool.Get().(writePoolData)
501 if ok {
502 c.writeBuf = wpd.buf
503 } else {
504 c.writeBuf = make([]byte, c.writeBufSize)
505 }
506 }
507 return nil
508}
509
510// NextWriter returns a writer for the next message to send. The writer's Close
511// method flushes the complete message to the network.

Callers 2

NextWriterMethod · 0.95
WriteMessageMethod · 0.95

Calls 4

isControlFunction · 0.85
isDataFunction · 0.85
GetMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected