diff --git a/fasthttputil/pipeconns.go b/fasthttputil/pipeconns.go index f125182..5dedfe6 100644 --- a/fasthttputil/pipeconns.go +++ b/fasthttputil/pipeconns.go @@ -121,7 +121,7 @@ func (c *pipeConn) Write(p []byte) (int, error) { select { case <-c.pc.stopCh: releaseByteBuffer(b) - return 0, errConnectionClosed + return 0, ErrConnectionClosed default: } @@ -135,7 +135,7 @@ func (c *pipeConn) Write(p []byte) (int, error) { return 0, ErrTimeout case <-c.pc.stopCh: releaseByteBuffer(b) - return 0, errConnectionClosed + return 0, ErrConnectionClosed } } @@ -218,10 +218,10 @@ func (c *pipeConn) readNextByteBuffer(mayBlock bool) error { return nil } -var ( - errWouldBlock = errors.New("would block") - errConnectionClosed = errors.New("connection closed") -) +var errWouldBlock = errors.New("would block") + +// ErrConnectionClosed indicates that the underlying connection is closed. It could mean that the client has disconnected. +var ErrConnectionClosed = errors.New("connection closed") type timeoutError struct{} diff --git a/fasthttputil/pipeconns_test.go b/fasthttputil/pipeconns_test.go index 3479251..26e5c9c 100644 --- a/fasthttputil/pipeconns_test.go +++ b/fasthttputil/pipeconns_test.go @@ -162,7 +162,7 @@ func testPipeConnsCloseWhileReadWrite(t *testing.T) { go func() { var err error if _, err = io.Copy(io.Discard, c1); err != nil { - if err != errConnectionClosed { + if err != ErrConnectionClosed { err = fmt.Errorf("unexpected error: %w", err) } else { err = nil @@ -176,7 +176,7 @@ func testPipeConnsCloseWhileReadWrite(t *testing.T) { var err error for { if _, err = c2.Write([]byte("foobar")); err != nil { - if err != errConnectionClosed { + if err != ErrConnectionClosed { err = fmt.Errorf("unexpected error: %w", err) } else { err = nil