Skip to content

Commit 7e45516

Browse files
committed
net: update documentation on Conn and PacketConn
Fixes #17982 Change-Id: I4884a6b57905420ac0e37210c411de98c582de1d Reviewed-on: https://go-review.googlesource.com/33473 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 1110649 commit 7e45516

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/net/net.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ type Addr interface {
116116
// Multiple goroutines may invoke methods on a Conn simultaneously.
117117
type Conn interface {
118118
// Read reads data from the connection.
119-
// Read can be made to time out and return a Error with Timeout() == true
119+
// Read can be made to time out and return an Error with Timeout() == true
120120
// after a fixed time limit; see SetDeadline and SetReadDeadline.
121121
Read(b []byte) (n int, err error)
122122

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

@@ -143,7 +143,8 @@ type Conn interface {
143143
// fail with a timeout (see type Error) instead of
144144
// blocking. The deadline applies to all future and pending
145145
// I/O, not just the immediately following call to Read or
146-
// Write.
146+
// Write. After a deadline has been exceeded, the connection
147+
// can be refreshed by setting a deadline in the future.
147148
//
148149
// An idle timeout can be implemented by repeatedly extending
149150
// the deadline after successful Read or Write calls.
@@ -309,13 +310,13 @@ type PacketConn interface {
309310
// bytes copied into b and the return address that
310311
// was on the packet.
311312
// ReadFrom can be made to time out and return
312-
// an error with Timeout() == true after a fixed time limit;
313+
// an Error with Timeout() == true after a fixed time limit;
313314
// see SetDeadline and SetReadDeadline.
314315
ReadFrom(b []byte) (n int, addr Addr, err error)
315316

316317
// WriteTo writes a packet with payload b to addr.
317318
// WriteTo can be made to time out and return
318-
// an error with Timeout() == true after a fixed time limit;
319+
// an Error with Timeout() == true after a fixed time limit;
319320
// see SetDeadline and SetWriteDeadline.
320321
// On packet-oriented connections, write timeouts are rare.
321322
WriteTo(b []byte, addr Addr) (n int, err error)
@@ -328,21 +329,32 @@ type PacketConn interface {
328329
LocalAddr() Addr
329330

330331
// SetDeadline sets the read and write deadlines associated
331-
// with the connection.
332+
// with the connection. It is equivalent to calling both
333+
// SetReadDeadline and SetWriteDeadline.
334+
//
335+
// A deadline is an absolute time after which I/O operations
336+
// fail with a timeout (see type Error) instead of
337+
// blocking. The deadline applies to all future and pending
338+
// I/O, not just the immediately following call to ReadFrom or
339+
// WriteTo. After a deadline has been exceeded, the connection
340+
// can be refreshed by setting a deadline in the future.
341+
//
342+
// An idle timeout can be implemented by repeatedly extending
343+
// the deadline after successful ReadFrom or WriteTo calls.
344+
//
345+
// A zero value for t means I/O operations will not time out.
332346
SetDeadline(t time.Time) error
333347

334-
// SetReadDeadline sets the deadline for future Read calls.
335-
// If the deadline is reached, Read will fail with a timeout
336-
// (see type Error) instead of blocking.
337-
// A zero value for t means Read will not time out.
348+
// SetReadDeadline sets the deadline for future ReadFrom calls
349+
// and any currently-blocked ReadFrom call.
350+
// A zero value for t means ReadFrom will not time out.
338351
SetReadDeadline(t time.Time) error
339352

340-
// SetWriteDeadline sets the deadline for future Write calls.
341-
// If the deadline is reached, Write will fail with a timeout
342-
// (see type Error) instead of blocking.
343-
// A zero value for t means Write will not time out.
353+
// SetWriteDeadline sets the deadline for future WriteTo calls
354+
// and any currently-blocked WriteTo call.
344355
// Even if write times out, it may return n > 0, indicating that
345356
// some of the data was successfully written.
357+
// A zero value for t means WriteTo will not time out.
346358
SetWriteDeadline(t time.Time) error
347359
}
348360

0 commit comments

Comments
 (0)