mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
Enhance TCP Fast Open (#310)
This commit is contained in:
parent
e1a5392beb
commit
ad1807dd99
9 changed files with 147 additions and 198 deletions
|
@ -130,14 +130,13 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||
}
|
||||
|
||||
if isTCPSocket(network) {
|
||||
switch config.Tfo {
|
||||
case SocketConfig_Enable:
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, 1); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN_CONNECT=1").Base(err)
|
||||
}
|
||||
case SocketConfig_Disable:
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, 0); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN_CONNECT=0").Base(err)
|
||||
tfo := int(config.Tfo)
|
||||
if tfo > 0 {
|
||||
tfo = 1
|
||||
}
|
||||
if tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, tfo); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN_CONNECT=", tfo).Base(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,14 +163,9 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||
}
|
||||
}
|
||||
if isTCPSocket(network) {
|
||||
switch config.Tfo {
|
||||
case SocketConfig_Enable:
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, 1); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN=1").Base(err)
|
||||
}
|
||||
case SocketConfig_Disable:
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, 0); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN=0").Base(err)
|
||||
if config.Tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, int(config.Tfo)); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN=", config.Tfo).Base(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue