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