1
0
Fork 0
mirror of https://github.com/XTLS/Xray-core.git synced 2025-06-15 07:48:40 +00:00

Enhance TCP Fast Open ()

This commit is contained in:
risetechlab 2021-03-06 22:45:12 +08:00 committed by GitHub
parent e1a5392beb
commit ad1807dd99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 147 additions and 198 deletions
transport/internet

View file

@ -48,14 +48,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.SOL_TCP, TCP_FASTOPEN_CONNECT, 1); err != nil {
return newError("failed to set TCP_FASTOPEN_CONNECT=1").Base(err)
}
case SocketConfig_Disable:
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN_CONNECT, 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.SOL_TCP, TCP_FASTOPEN_CONNECT, tfo); err != nil {
return newError("failed to set TCP_FASTOPEN_CONNECT=", tfo).Base(err)
}
}
}
@ -76,14 +75,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.SOL_TCP, 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.SOL_TCP, 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.SOL_TCP, TCP_FASTOPEN, int(config.Tfo)); err != nil {
return newError("failed to set TCP_FASTOPEN=", config.Tfo).Base(err)
}
}
}