mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
Add TCP keep alive support in MacOS, FreeBSD
This commit is contained in:
parent
499a0e19cb
commit
dc709f56dd
@ -25,6 +25,15 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.TcpKeepAliveInterval > 0 {
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
|
||||||
|
return newError("failed to set TCP_KEEPINTVL", err)
|
||||||
|
}
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
|
||||||
|
return newError("failed to set SO_KEEPALIVE", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -42,6 +51,14 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if config.TcpKeepAliveInterval > 0 {
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
|
||||||
|
return newError("failed to set TCP_KEEPINTVL", err)
|
||||||
|
}
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
|
||||||
|
return newError("failed to set SO_KEEPALIVE", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -141,6 +141,14 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||||||
return newError("failed to set TCP_FASTOPEN_CONNECT=0").Base(err)
|
return newError("failed to set TCP_FASTOPEN_CONNECT=0").Base(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if config.TcpKeepAliveInterval > 0 {
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
|
||||||
|
return newError("failed to set TCP_KEEPINTVL", err)
|
||||||
|
}
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
|
||||||
|
return newError("failed to set SO_KEEPALIVE", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Tproxy.IsEnabled() {
|
if config.Tproxy.IsEnabled() {
|
||||||
@ -175,6 +183,14 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||||||
return newError("failed to set TCP_FASTOPEN=0").Base(err)
|
return newError("failed to set TCP_FASTOPEN=0").Base(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if config.TcpKeepAliveInterval > 0 {
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
|
||||||
|
return newError("failed to set TCP_KEEPINTVL", err)
|
||||||
|
}
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
|
||||||
|
return newError("failed to set SO_KEEPALIVE", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Tproxy.IsEnabled() {
|
if config.Tproxy.IsEnabled() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user