diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2012-01-18 16:24:06 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2012-01-18 16:24:06 -0800 |
| commit | b71883e9b0eff7e89081d20204bf33f369cdf735 (patch) | |
| tree | bf3ded01d2aae9f06a8e24759eb8fa0635377b2e /src/pkg/exp/ssh | |
| parent | 5e77b009d0e9dc8c92fe91d0a2d3182e9fff10ae (diff) | |
| download | go-b71883e9b0eff7e89081d20204bf33f369cdf735.tar.xz | |
net: change SetTimeout to SetDeadline
Previously, a timeout (in int64 nanoseconds) applied to a granularity
even smaller than one operation: a 100 byte read with a 1 second timeout
could take 100 seconds, if the bytes all arrived on the network 1 second
apart. This was confusing.
Rather than making the timeout granularity be per-Read/Write,
this CL makes callers set an absolute deadline (in time.Time)
after which operations will fail. This makes it possible to
set deadlines at higher levels, without knowing exactly how
many read/write operations will happen in e.g. reading an HTTP
request.
Fixes #2723
R=r, rsc, dave
CC=golang-dev
https://golang.org/cl/5555048
Diffstat (limited to 'src/pkg/exp/ssh')
| -rw-r--r-- | src/pkg/exp/ssh/tcpip.go | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/pkg/exp/ssh/tcpip.go b/src/pkg/exp/ssh/tcpip.go index bee41eeb0d..e0c47bca1f 100644 --- a/src/pkg/exp/ssh/tcpip.go +++ b/src/pkg/exp/ssh/tcpip.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "net" + "time" ) // Dial initiates a connection to the addr from the remote host. @@ -107,27 +108,25 @@ func (t *tcpchanconn) RemoteAddr() net.Addr { return t.raddr } -// SetTimeout sets the read and write deadlines associated +// SetDeadline sets the read and write deadlines associated // with the connection. -func (t *tcpchanconn) SetTimeout(nsec int64) error { - if err := t.SetReadTimeout(nsec); err != nil { +func (t *tcpchanconn) SetDeadline(deadline time.Time) error { + if err := t.SetReadDeadline(deadline); err != nil { return err } - return t.SetWriteTimeout(nsec) + return t.SetWriteDeadline(deadline) } -// SetReadTimeout sets the time (in nanoseconds) that -// Read will wait for data before returning an error with Timeout() == true. -// Setting nsec == 0 (the default) disables the deadline. -func (t *tcpchanconn) SetReadTimeout(nsec int64) error { - return errors.New("ssh: tcpchan: timeout not supported") +// SetReadDeadline sets the read deadline. +// A zero value for t means Read will not time out. +// After the deadline, the error from Read will implement net.Error +// with Timeout() == true. +func (t *tcpchanconn) SetReadDeadline(deadline time.Time) error { + return errors.New("ssh: tcpchan: deadline not supported") } -// SetWriteTimeout sets the time (in nanoseconds) that -// Write will wait to send its data before returning an error with Timeout() == true. -// Setting nsec == 0 (the default) disables the deadline. -// Even if write times out, it may return n > 0, indicating that -// some of the data was successfully written. -func (t *tcpchanconn) SetWriteTimeout(nsec int64) error { - return errors.New("ssh: tcpchan: timeout not supported") +// SetWriteDeadline exists to satisfy the net.Conn interface +// but is not implemented by this type. It always returns an error. +func (t *tcpchanconn) SetWriteDeadline(deadline time.Time) error { + return errors.New("ssh: tcpchan: deadline not supported") } |
