diff options
Diffstat (limited to 'server/sockopt_linux.go')
-rw-r--r-- | server/sockopt_linux.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/server/sockopt_linux.go b/server/sockopt_linux.go index 436591e9..4a68a18d 100644 --- a/server/sockopt_linux.go +++ b/server/sockopt_linux.go @@ -75,6 +75,9 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec if err != nil { return nil, err } + fi := os.NewFile(uintptr(fd), "") + defer fi.Close() + t, err := buildTcpMD5Sig(host, key) if err != nil { return nil, err @@ -94,9 +97,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec return nil, os.NewSyscallError("bind", err) } - tcpconn := func(fd uintptr) (*net.TCPConn, error) { - fi := os.NewFile(uintptr(fd), "") - defer fi.Close() + tcpconn := func(fi *os.File) (*net.TCPConn, error) { conn, err := net.FileConn(fi) return conn.(*net.TCPConn), err } @@ -106,7 +107,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR: // do timeout handling case nil, syscall.EISCONN: - return tcpconn(uintptr(fd)) + return tcpconn(fi) default: return nil, os.NewSyscallError("connect", err) } @@ -141,7 +142,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec switch err := syscall.Errno(nerr); err { case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR: case syscall.Errno(0), syscall.EISCONN: - return tcpconn(uintptr(fd)) + return tcpconn(fi) default: return nil, os.NewSyscallError("getsockopt", err) } |