net: introduce net.Error interface

Adds two more methods, Timeout and Temporary.
Implemented by os.Errno too.  The intent is to make
the checks for os.EAGAIN a little less clunky.
It should also let us clean up a bug that Mike Solomon
pointed out: if a network server gets an "out of file descriptors"
error from Accept, the listener should not stop.
It will be able to check this because that error would
have Temporary() == true.

Also clean up some underscore names.

Fixes #442.

R=r
CC=golang-dev, msolo
https://golang.org/cl/957045
This commit is contained in:
Russ Cox 2010-04-26 22:15:25 -07:00
parent cd5191fd30
commit 47a0533411
12 changed files with 347 additions and 315 deletions

View file

@ -32,8 +32,8 @@ func testTimeout(t *testing.T, network, addr string, readFrom bool) {
if readFrom {
what = "ReadFrom"
}
if n != 0 || !isEAGAIN(err1) {
t.Errorf("fd.%s on %s %s did not return 0, EAGAIN: %v, %v", what, network, addr, n, err1)
if n != 0 || err1 == nil || !err1.(Error).Timeout() {
t.Errorf("fd.%s on %s %s did not return 0, timeout: %v, %v", what, network, addr, n, err1)
}
if t1-t0 < 0.5e8 || t1-t0 > 1.5e8 {
t.Errorf("fd.%s on %s %s took %f seconds, expected 0.1", what, network, addr, float64(t1-t0)/1e9)