-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📡 linux: use Go's listener backlog as TFO backlog
Previously we hardcoded Linux's default net.core.somaxconn (4096) as the default TFO backlog. Turns out it's quite easy to use linkname to retrieve Go's listener backlog, so we changed to do this in this commit, as well as fixing some related comments.
- Loading branch information
1 parent
7e12621
commit 12287b1
Showing
4 changed files
with
18 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
package tfo | ||
|
||
import "golang.org/x/sys/unix" | ||
import ( | ||
_ "unsafe" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// TCPFastopenQueueLength is the maximum number of total pending TFO connection requests, | ||
// see https://datatracker.ietf.org/doc/html/rfc7413#section-5.1 for why this limit exists. | ||
// The current value aligns with Go std's listen(2) backlog (4096, as of the current version). | ||
// The current value is the default net.core.somaxconn on Linux. | ||
// | ||
// Deprecated: This constant is no longer used in this module and will be removed in v3. | ||
const TCPFastopenQueueLength = 4096 | ||
|
||
func setTFOListener(fd uintptr) error { | ||
return setTFOListenerWithBacklog(fd, defaultBacklog) | ||
return setTFOListenerWithBacklog(fd, 0) | ||
} | ||
|
||
func setTFOListenerWithBacklog(fd uintptr, backlog int) error { | ||
if backlog == 0 { | ||
backlog = listenerBacklog() | ||
} | ||
return setTFO(int(fd), backlog) | ||
} | ||
|
||
// listenerBacklog is linked from src/net/net.go | ||
// | ||
//go:linkname listenerBacklog net.listenerBacklog | ||
func listenerBacklog() int | ||
|
||
func setTFODialer(fd uintptr) error { | ||
return unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_FASTOPEN_CONNECT, 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters