Restore windows compatibility.

This commit is contained in:
notsure2 2023-05-29 18:13:37 +03:00
parent 298d74b0ed
commit 0d788b728c
1 changed files with 18 additions and 12 deletions

View File

@ -105,15 +105,16 @@ func RouteTCP(listener net.Listener, streamTimeout time.Duration, singleplex boo
continue continue
} }
file, err := localConn.(*net.TCPConn).File() syscallConn, err := localConn.(*net.TCPConn).SyscallConn()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
continue continue
} }
err = syscallConn.Control(func(fd uintptr) {
if sendBufferSize > 0 { if sendBufferSize > 0 {
log.Debugf("Setting loopback connection tcp send buffer: %d", sendBufferSize) log.Debugf("Setting loopback connection tcp send buffer: %d", sendBufferSize)
err := syscall.SetsockoptInt(common.Platformfd(file.Fd()), syscall.SOL_SOCKET, syscall.SO_SNDBUF, sendBufferSize) err := syscall.SetsockoptInt(common.Platformfd(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, sendBufferSize)
if err != nil { if err != nil {
log.Errorf("setsocketopt SO_SNDBUF: %s\n", err) log.Errorf("setsocketopt SO_SNDBUF: %s\n", err)
} }
@ -121,11 +122,16 @@ func RouteTCP(listener net.Listener, streamTimeout time.Duration, singleplex boo
if receiveBufferSize > 0 { if receiveBufferSize > 0 {
log.Debugf("Setting loopback connection tcp receive buffer: %d", receiveBufferSize) log.Debugf("Setting loopback connection tcp receive buffer: %d", receiveBufferSize)
err = syscall.SetsockoptInt(common.Platformfd(file.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF, receiveBufferSize) err = syscall.SetsockoptInt(common.Platformfd(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, receiveBufferSize)
if err != nil { if err != nil {
log.Errorf("setsocketopt SO_RCVBUF: %s\n", err) log.Errorf("setsocketopt SO_RCVBUF: %s\n", err)
} }
} }
})
if err != nil {
log.Fatal(err)
continue
}
if !singleplex && (sesh == nil || sesh.IsClosed()) { if !singleplex && (sesh == nil || sesh.IsClosed()) {
sesh = newSeshFunc() sesh = newSeshFunc()