1
0
mirror of https://github.com/golang/go synced 2024-11-12 09:50:21 -07:00

net: make spuriousENOTAVAIL to be able to parse EADDRNOTAVAIL correctly

Change-Id: I82e3aadbd18fccb98a76d1c36876510f5e1c3089
Reviewed-on: https://go-review.googlesource.com/12750
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Mikio Hara 2015-07-28 12:28:09 +09:00
parent a7e81c37f4
commit 80abe2fc59
2 changed files with 33 additions and 3 deletions

View File

@ -6,7 +6,11 @@
package net
import "syscall"
import (
"os"
"syscall"
"testing"
)
var (
errTimedout = syscall.ETIMEDOUT
@ -17,3 +21,24 @@ func isPlatformError(err error) bool {
_, ok := err.(syscall.Errno)
return ok
}
func TestSpuriousENOTAVAIL(t *testing.T) {
for _, tt := range []struct {
error
ok bool
}{
{syscall.EADDRNOTAVAIL, true},
{&os.SyscallError{Syscall: "syscall", Err: syscall.EADDRNOTAVAIL}, true},
{&OpError{Op: "op", Err: syscall.EADDRNOTAVAIL}, true},
{&OpError{Op: "op", Err: &os.SyscallError{Syscall: "syscall", Err: syscall.EADDRNOTAVAIL}}, true},
{syscall.EINVAL, false},
{&os.SyscallError{Syscall: "syscall", Err: syscall.EINVAL}, false},
{&OpError{Op: "op", Err: syscall.EINVAL}, false},
{&OpError{Op: "op", Err: &os.SyscallError{Syscall: "syscall", Err: syscall.EINVAL}}, false},
} {
if ok := spuriousENOTAVAIL(tt.error); ok != tt.ok {
t.Errorf("spuriousENOTAVAIL(%v) = %v; want %v", tt.error, ok, tt.ok)
}
}
}

View File

@ -230,8 +230,13 @@ func selfConnect(fd *netFD, err error) bool {
}
func spuriousENOTAVAIL(err error) bool {
e, ok := err.(*OpError)
return ok && e.Err == syscall.EADDRNOTAVAIL
if op, ok := err.(*OpError); ok {
err = op.Err
}
if sys, ok := err.(*os.SyscallError); ok {
err = sys.Err
}
return err == syscall.EADDRNOTAVAIL
}
// TCPListener is a TCP network listener. Clients should typically