diff options
Diffstat (limited to 'src/pkg/net/sock.go')
-rw-r--r-- | src/pkg/net/sock.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/pkg/net/sock.go b/src/pkg/net/sock.go index fbdb69583..8ad3548ad 100644 --- a/src/pkg/net/sock.go +++ b/src/pkg/net/sock.go @@ -38,10 +38,16 @@ func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscal // Allow broadcast. syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1) + if f == syscall.AF_INET6 { + // using ip, tcp, udp, etc. + // allow both protocols even if the OS default is otherwise. + syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0) + } + if la != nil { e = syscall.Bind(s, la) if e != 0 { - syscall.Close(s) + closesocket(s) return nil, os.Errno(e) } } @@ -49,7 +55,7 @@ func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscal if ra != nil { e = syscall.Connect(s, ra) if e != 0 { - syscall.Close(s) + closesocket(s) return nil, os.Errno(e) } } @@ -61,7 +67,7 @@ func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscal fd, err = newFD(s, f, p, net, laddr, raddr) if err != nil { - syscall.Close(s) + closesocket(s) return nil, err } @@ -129,6 +135,12 @@ func setKeepAlive(fd *netFD, keepalive bool) os.Error { return setsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, boolint(keepalive)) } +func setNoDelay(fd *netFD, noDelay bool) os.Error { + fd.incref() + defer fd.decref() + return setsockoptInt(fd.sysfd, syscall.IPPROTO_TCP, syscall.TCP_NODELAY, boolint(noDelay)) +} + func setLinger(fd *netFD, sec int) os.Error { var l syscall.Linger if sec >= 0 { |