Skip to content

Commit 5fbb54e

Browse files
committed
io: explain what (0,nil) means from Read
Also add a new variable ErrNoProgress that io.Readers can use to report ineffectual Read calls. Fixes #5310. R=golang-dev, dsymonds, bradfitz CC=golang-dev https://golang.org/cl/8845043
1 parent db6ddff commit 5fbb54e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/pkg/io/io.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ var EOF = errors.New("EOF")
3434
// middle of reading a fixed-size block or data structure.
3535
var ErrUnexpectedEOF = errors.New("unexpected EOF")
3636

37+
// ErrNoProgress is returned by some clients of an io.Reader when
38+
// many calls to Read have failed to return any data or error,
39+
// usually the sign of a broken io.Reader implementation.
40+
var ErrNoProgress = errors.New("multiple Read calls return no data or error")
41+
3742
// Reader is the interface that wraps the basic Read method.
3843
//
3944
// Read reads up to len(p) bytes into p. It returns the number of bytes
@@ -55,6 +60,10 @@ var ErrUnexpectedEOF = errors.New("unexpected EOF")
5560
// considering the error err. Doing so correctly handles I/O errors
5661
// that happen after reading some bytes and also both of the
5762
// allowed EOF behaviors.
63+
//
64+
// Implementations of Read are discouraged from returning a
65+
// zero byte count with a nil error, and callers should treat
66+
// that situation as a no-op.
5867
type Reader interface {
5968
Read(p []byte) (n int, err error)
6069
}

0 commit comments

Comments
 (0)