Skip to content

Commit

Permalink
feat: add method to acknowledge expected read errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeckett committed Apr 25, 2024
1 parent 09a6bab commit 8654034
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,9 @@ func (c *Conn) handleProtocolError(message string) error {
//
// Applications must break out of the application's read loop when this method
// returns a non-nil error value. Errors returned from this method are
// permanent. Once this method returns a non-nil error, all subsequent calls to
// this method return the same error.
// permanent, unless explicitly cleared using ClearReadError. Once this method
// returns a non-nil error, all subsequent calls to this method return the
// same error.
func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
// Close previous reader, only relevant for decompression.
if c.reader != nil {
Expand Down Expand Up @@ -1047,6 +1048,15 @@ func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
return noFrame, nil, c.readErr
}

// ClearReadError clears the read error state of the connection. This is
// primarily useful for handling expected errors such as read timeouts with
// non-blocking I/O. Applications must be careful to ensure errors are
// temporary before clearing them as not doing so will lead to busy loops.
func (c *Conn) ClearReadError() {
c.readErr = nil
c.readErrCount--
}

type messageReader struct{ c *Conn }

func (r *messageReader) Read(b []byte) (int, error) {
Expand Down

0 comments on commit 8654034

Please sign in to comment.