MCPcopy Create free account
hub / github.com/subtrace/subtrace / readFull

Method readFull

cmd/run/socket/proxy.go:665–690  ·  view source on GitHub ↗

readFull reads len(p) bytes from the client or server reader, enforcing a shared byte limit across both. Returns an error if the limit is exceeded. Safe for both the client and server to call concurrently.

(isClient bool, p []byte)

Source from the content-addressed store, hash-verified

663// byte limit across both. Returns an error if the limit is exceeded. Safe for both
664// the client and server to call concurrently.
665func (w *websocket) readFull(isClient bool, p []byte) (int, error) {
666 l := uint64(len(p))
667
668 for {
669 remaining := w.n.Load()
670 if remaining < l {
671 return 0, fmt.Errorf("%w: limit=%d, have=%d, want=%d, msgsRead=%d", errWebsocketPayloadLimitExceeded, tracer.PayloadLimitBytes, remaining, l, len(w.getMessages()))
672 }
673
674 if w.n.CompareAndSwap(remaining, remaining-l) {
675 var r io.Reader
676 if isClient {
677 r = w.cli
678 } else {
679 r = w.srv
680 }
681
682 n, err := io.ReadFull(r, p)
683 if err != nil {
684 w.n.Add(l - uint64(n))
685 return n, err
686 }
687 return n, nil
688 }
689 }
690}
691
692func (w *websocket) readFrame(isClient bool) (*websocketFrame, error) {
693 header := make([]byte, 2)

Callers 1

readFrameMethod · 0.95

Calls 3

getMessagesMethod · 0.95
LoadMethod · 0.80
AddMethod · 0.80

Tested by

no test coverage detected