Skip to content

Commit

Permalink
net: make spuriousENOTAVAIL to be able to parse EADDRNOTAVAIL correctly
Browse files Browse the repository at this point in the history
Change-Id: I82e3aadbd18fccb98a76d1c36876510f5e1c3089
Reviewed-on: https://go-review.googlesource.com/12750
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
cixtor committed Jul 28, 2015
1 parent a7e81c3 commit 80abe2f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/net/error_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

package net

import "syscall"
import (
"os"
"syscall"
"testing"
)

var (
errTimedout = syscall.ETIMEDOUT
Expand All @@ -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)
}
}
}
9 changes: 7 additions & 2 deletions src/net/tcpsock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 80abe2f

Please sign in to comment.