mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
cd5191fd30
commit
47a0533411
12 changed files with 347 additions and 315 deletions
|
|
@ -69,14 +69,14 @@ func connect(t *testing.T, network, addr string, isEmpty bool) {
|
|||
}
|
||||
var b1 [100]byte
|
||||
|
||||
n, err := fd.Write(b)
|
||||
n, err1 := fd.Write(b)
|
||||
if n != len(b) {
|
||||
t.Fatalf("fd.Write(%q) = %d, %v", b, n, err)
|
||||
t.Fatalf("fd.Write(%q) = %d, %v", b, n, err1)
|
||||
}
|
||||
|
||||
n, err = fd.Read(&b1)
|
||||
if n != len(b) || err != nil {
|
||||
t.Fatalf("fd.Read() = %d, %v (want %d, nil)", n, err, len(b))
|
||||
n, err1 = fd.Read(&b1)
|
||||
if n != len(b) || err1 != nil {
|
||||
t.Fatalf("fd.Read() = %d, %v (want %d, nil)", n, err1, len(b))
|
||||
}
|
||||
fd.Close()
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ func runPacket(t *testing.T, network, addr string, listening chan<- string, done
|
|||
var buf [1000]byte
|
||||
for {
|
||||
n, addr, err := c.ReadFrom(&buf)
|
||||
if isEAGAIN(err) {
|
||||
if e, ok := err.(Error); ok && e.Timeout() {
|
||||
if done <- 1 {
|
||||
break
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue