mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-07-27 12:24:14 +00:00
Inbounds & Outbounds: TCP KeepAlive better default value (#4931)
From https://github.com/XTLS/Xray-core/pull/4927
This commit is contained in:
parent
87d8b97d9a
commit
eb433d9462
3 changed files with 46 additions and 28 deletions
|
@ -64,26 +64,6 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||
}
|
||||
}
|
||||
|
||||
if config.TcpKeepAliveInterval > 0 || config.TcpKeepAliveIdle > 0 {
|
||||
if config.TcpKeepAliveInterval > 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, int(config.TcpKeepAliveInterval)); err != nil {
|
||||
return errors.New("failed to set TCP_KEEPINTVL", err)
|
||||
}
|
||||
}
|
||||
if config.TcpKeepAliveIdle > 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, int(config.TcpKeepAliveIdle)); err != nil {
|
||||
return errors.New("failed to set TCP_KEEPIDLE", err)
|
||||
}
|
||||
}
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 1); err != nil {
|
||||
return errors.New("failed to set SO_KEEPALIVE", err)
|
||||
}
|
||||
} else if config.TcpKeepAliveInterval < 0 || config.TcpKeepAliveIdle < 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_KEEPALIVE, 0); err != nil {
|
||||
return errors.New("failed to unset SO_KEEPALIVE", err)
|
||||
}
|
||||
}
|
||||
|
||||
if config.TcpCongestion != "" {
|
||||
if err := syscall.SetsockoptString(int(fd), syscall.SOL_TCP, syscall.TCP_CONGESTION, config.TcpCongestion); err != nil {
|
||||
return errors.New("failed to set TCP_CONGESTION", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue