Skip to content

Commit b465202

Browse files
net: consistently document deadline handling
After CL 228645 some mentions of the Deadline methods referred to the Timeout method, and some to os.ErrDeadlineExceeded. Stop referring to the Timeout method, to encourage ErrDeadlineExceeded. For #31449 Change-Id: I27b8ff34f31798f38b06437546886af8cce98ca4 Reviewed-on: https://go-review.googlesource.com/c/go/+/239705 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Damien Neil <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 7eb5941 commit b465202

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/net/net.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ type Addr interface {
111111
// Multiple goroutines may invoke methods on a Conn simultaneously.
112112
type Conn interface {
113113
// Read reads data from the connection.
114-
// Read can be made to time out and return an Error with Timeout() == true
115-
// after a fixed time limit; see SetDeadline and SetReadDeadline.
114+
// Read can be made to time out and return an error after a fixed
115+
// time limit; see SetDeadline and SetReadDeadline.
116116
Read(b []byte) (n int, err error)
117117

118118
// Write writes data to the connection.
119-
// Write can be made to time out and return an Error with Timeout() == true
120-
// after a fixed time limit; see SetDeadline and SetWriteDeadline.
119+
// Write can be made to time out and return an error after a fixed
120+
// time limit; see SetDeadline and SetWriteDeadline.
121121
Write(b []byte) (n int, err error)
122122

123123
// Close closes the connection.
@@ -313,15 +313,13 @@ type PacketConn interface {
313313
// It returns the number of bytes read (0 <= n <= len(p))
314314
// and any error encountered. Callers should always process
315315
// the n > 0 bytes returned before considering the error err.
316-
// ReadFrom can be made to time out and return
317-
// an Error with Timeout() == true after a fixed time limit;
318-
// see SetDeadline and SetReadDeadline.
316+
// ReadFrom can be made to time out and return an error after a
317+
// fixed time limit; see SetDeadline and SetReadDeadline.
319318
ReadFrom(p []byte) (n int, addr Addr, err error)
320319

321320
// WriteTo writes a packet with payload p to addr.
322-
// WriteTo can be made to time out and return
323-
// an Error with Timeout() == true after a fixed time limit;
324-
// see SetDeadline and SetWriteDeadline.
321+
// WriteTo can be made to time out and return an Error after a
322+
// fixed time limit; see SetDeadline and SetWriteDeadline.
325323
// On packet-oriented connections, write timeouts are rare.
326324
WriteTo(p []byte, addr Addr) (n int, err error)
327325

@@ -337,11 +335,17 @@ type PacketConn interface {
337335
// SetReadDeadline and SetWriteDeadline.
338336
//
339337
// A deadline is an absolute time after which I/O operations
340-
// fail with a timeout (see type Error) instead of
341-
// blocking. The deadline applies to all future and pending
342-
// I/O, not just the immediately following call to ReadFrom or
343-
// WriteTo. After a deadline has been exceeded, the connection
344-
// can be refreshed by setting a deadline in the future.
338+
// fail instead of blocking. The deadline applies to all future
339+
// and pending I/O, not just the immediately following call to
340+
// Read or Write. After a deadline has been exceeded, the
341+
// connection can be refreshed by setting a deadline in the future.
342+
//
343+
// If the deadline is exceeded a call to Read or Write or to other
344+
// I/O methods will return an error that wraps os.ErrDeadlineExceeded.
345+
// This can be tested using errors.Is(err, os.ErrDeadlineExceeded).
346+
// The error's Timeout method will return true, but note that there
347+
// are other possible errors for which the Timeout method will
348+
// return true even if the deadline has not been exceeded.
345349
//
346350
// An idle timeout can be implemented by repeatedly extending
347351
// the deadline after successful ReadFrom or WriteTo calls.

0 commit comments

Comments
 (0)