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

Method read

read.go:457–498  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

455}
456
457func (mr *msgReader) read(p []byte) (int, error) {
458 for {
459 if mr.payloadLength == 0 {
460 if mr.fin {
461 if mr.flate {
462 return mr.flateTail.Read(p)
463 }
464 return 0, io.EOF
465 }
466
467 h, err := mr.c.readLoop(mr.ctx)
468 if err != nil {
469 return 0, err
470 }
471 if h.opcode != opContinuation {
472 err := errors.New("received new data message without finishing the previous message")
473 mr.c.writeError(StatusProtocolError, err)
474 return 0, err
475 }
476 mr.setFrame(h)
477
478 continue
479 }
480
481 if int64(len(p)) > mr.payloadLength {
482 p = p[:mr.payloadLength]
483 }
484
485 n, err := mr.c.readFramePayload(mr.ctx, p)
486 if err != nil {
487 return n, err
488 }
489
490 mr.payloadLength -= int64(n)
491
492 if !mr.c.client {
493 mr.maskKey = mask(p, mr.maskKey)
494 }
495
496 return n, nil
497 }
498}
499
500type limitReader struct {
501 c *Conn

Callers

nothing calls this directly

Calls 6

setFrameMethod · 0.95
readLoopMethod · 0.80
writeErrorMethod · 0.80
readFramePayloadMethod · 0.80
maskFunction · 0.70
ReadMethod · 0.45

Tested by

no test coverage detected