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

Method NextReader

conn.go:998–1034  ·  conn.go::Conn.NextReader

NextReader returns the next data message received from the peer. The returned messageType is either TextMessage or BinaryMessage. There can be at most one open reader on a connection. NextReader discards the previous message if the application has not already consumed it. Applications must break o

()

Source from the content-addressed store, hash-verified

996// permanent. Once this method returns a non-nil error, all subsequent calls to
997// this method return the same error.
998func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
999 // Close previous reader, only relevant for decompression.
1000 if c.reader != nil {
1001 c.reader.Close()
1002 c.reader = nil
1003 }
1004
1005 c.messageReader = nil
1006 c.readLength = 0
1007
1008 for c.readErr == nil {
1009 frameType, err := c.advanceFrame()
1010 if err != nil {
1011 c.readErr = hideTempErr(err)
1012 break
1013 }
1014
1015 if frameType == TextMessage || frameType == BinaryMessage {
1016 c.messageReader = &messageReader{c}
1017 c.reader = c.messageReader
1018 if c.readDecompress {
1019 c.reader = c.newDecompressionReader(c.reader)
1020 }
1021 return frameType, c.reader, nil
1022 }
1023 }
1024
1025 // Applications that do handle the error returned from this method spin in
1026 // tight loop on connection failure. To help application developers detect
1027 // this error, panic on repeated reads to the failed connection.
1028 c.readErrCount++
1029 if c.readErrCount >= 1000 {
1030 panic("repeated read on failed websocket connection")
1031 }
1032
1033 return noFrame, nil, c.readErr
1034}
1035
1036type messageReader struct{ c *Conn }
1037

Callers 12

ReadMessageMethod · 0.95
ReadJSONMethod · 0.95
TestFramingFunction · 0.80
TestControlFunction · 0.80
TestEOFWithinFrameFunction · 0.80
TestEOFBeforeFinalFrameFunction · 0.80
TestReadLimitFunction · 0.80
TestBufioReadBytesFunction · 0.80
ServeHTTPMethod · 0.80
ReadMethod · 0.80
echoCopyFunction · 0.80

Calls 3

advanceFrameMethod · 0.95
hideTempErrFunction · 0.85
CloseMethod · 0.45

Tested by 8

TestFramingFunction · 0.64
TestControlFunction · 0.64
TestEOFWithinFrameFunction · 0.64
TestEOFBeforeFinalFrameFunction · 0.64
TestReadLimitFunction · 0.64
TestBufioReadBytesFunction · 0.64
ServeHTTPMethod · 0.64