diff options
Diffstat (limited to 'libgo/go/net/sock_posix.go')
-rw-r--r-- | libgo/go/net/sock_posix.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/libgo/go/net/sock_posix.go b/libgo/go/net/sock_posix.go index 9cd149e466b..be89c26db2a 100644 --- a/libgo/go/net/sock_posix.go +++ b/libgo/go/net/sock_posix.go @@ -4,8 +4,6 @@ // +build darwin freebsd linux netbsd openbsd windows -// Sockets - package net import ( @@ -15,7 +13,7 @@ import ( var listenerBacklog = maxListenerBacklog() -// Generic socket creation. +// Generic POSIX socket creation. func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr, deadline time.Time, toAddr func(syscall.Sockaddr) Addr) (fd *netFD, err error) { s, err := sysSocket(f, t, p) if err != nil { @@ -27,7 +25,8 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr, return nil, err } - if ulsa != nil { + // This socket is used by a listener. + if ulsa != nil && ursa == nil { // We provide a socket that listens to a wildcard // address with reusable UDP port when the given ulsa // is an appropriate UDP multicast address prefix. @@ -39,6 +38,9 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr, closesocket(s) return nil, err } + } + + if ulsa != nil { if err = syscall.Bind(s, ulsa); err != nil { closesocket(s) return nil, err @@ -50,19 +52,27 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr, return nil, err } + // This socket is used by a dialer. if ursa != nil { - fd.wdeadline.setTime(deadline) - if err = fd.connect(ursa); err != nil { - closesocket(s) + if !deadline.IsZero() { + setWriteDeadline(fd, deadline) + } + if err = fd.connect(ulsa, ursa); err != nil { + fd.Close() return nil, err } fd.isConnected = true - fd.wdeadline.set(0) + if !deadline.IsZero() { + setWriteDeadline(fd, time.Time{}) + } } lsa, _ := syscall.Getsockname(s) laddr := toAddr(lsa) rsa, _ := syscall.Getpeername(s) + if rsa == nil { + rsa = ursa + } raddr := toAddr(rsa) fd.setAddr(laddr, raddr) return fd, nil |