1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:54:40 -07:00

net: extend the workaround to DialTCP to try to get arm building again.

Awfulness by the bucket that we hope
Fixes #3057.

R=golang-dev, mikioh.mikioh, dsymonds, r, rsc
CC=golang-dev
https://golang.org/cl/5687060
This commit is contained in:
Rob Pike 2012-02-21 16:48:05 +11:00
parent b888671f4c
commit 152d806b16
2 changed files with 12 additions and 14 deletions

View File

@ -117,10 +117,6 @@ func internetSocket(net string, laddr, raddr sockaddr, sotype, proto int, mode s
if ra, oserr = raddr.sockaddr(family); oserr != nil {
goto Error
}
if ra == nil {
// TODO(r): part of selfConnect debugging
panic("ra nil when raddr non-nil")
}
}
fd, oserr = socket(net, family, sotype, proto, la, ra, toAddr)
if oserr != nil {

View File

@ -29,8 +29,7 @@ func sockaddrToTCP(sa syscall.Sockaddr) Addr {
return &TCPAddr{sa.Addr[0:], sa.Port}
default:
if sa != nil {
// TODO(r): Diagnose when we will turn a non-nil sockaddr into a nil.
// Part of diagnosing the selfConnect bug.
// Diagnose when we will turn a non-nil sockaddr into a nil.
panic(fmt.Sprintf("unexpected type in sockaddrToTCP: %T", sa))
}
}
@ -237,13 +236,6 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
fd, err := internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOCK_STREAM, 0, "dial", sockaddrToTCP)
checkRaddr := func(s string) {
if err == nil && fd.raddr == nil {
panic("nil raddr in DialTCP: " + s)
}
}
checkRaddr("early")
// TCP has a rarely used mechanism called a 'simultaneous connection' in
// which Dial("tcp", addr1, addr2) run on the machine at addr1 can
// connect to a simultaneous Dial("tcp", addr2, addr1) run on the machine
@ -264,7 +256,6 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
for i := 0; i < 2 && err == nil && laddr == nil && selfConnect(fd); i++ {
fd.Close()
fd, err = internetSocket(net, laddr.toAddr(), raddr.toAddr(), syscall.SOCK_STREAM, 0, "dial", sockaddrToTCP)
checkRaddr("after close")
}
if err != nil {
@ -274,6 +265,17 @@ func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error) {
}
func selfConnect(fd *netFD) bool {
// The socket constructor can return an fd with raddr nil under certain
// unknown conditions. The errors in the calls there to Getpeername
// are discarded, but we can't catch the problem there because those
// calls are sometimes legally erroneous with a "socket not connected".
// Since this code (selfConnect) is already trying to work around
// a problem, we make sure if this happens we recognize trouble and
// ask the DialTCP routine to try again.
// TODO: try to understand what's really going on.
if fd.laddr == nil || fd.raddr == nil {
return true
}
l := fd.laddr.(*TCPAddr)
r := fd.raddr.(*TCPAddr)
return l.Port == r.Port && l.IP.Equal(r.IP)