From 5fbb54eaca57e2626e24f1982d28a7de9f91ac49 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 18 Apr 2013 17:36:25 -0700 Subject: [PATCH] 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 --- src/pkg/io/io.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pkg/io/io.go b/src/pkg/io/io.go index f901afe423..ec2cd6056f 100644 --- a/src/pkg/io/io.go +++ b/src/pkg/io/io.go @@ -34,6 +34,11 @@ var EOF = errors.New("EOF") // middle of reading a fixed-size block or data structure. var ErrUnexpectedEOF = errors.New("unexpected EOF") +// ErrNoProgress is returned by some clients of an io.Reader when +// many calls to Read have failed to return any data or error, +// usually the sign of a broken io.Reader implementation. +var ErrNoProgress = errors.New("multiple Read calls return no data or error") + // Reader is the interface that wraps the basic Read method. // // 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") // considering the error err. Doing so correctly handles I/O errors // that happen after reading some bytes and also both of the // allowed EOF behaviors. +// +// Implementations of Read are discouraged from returning a +// zero byte count with a nil error, and callers should treat +// that situation as a no-op. type Reader interface { Read(p []byte) (n int, err error) } -- 2.48.1