-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support TCP Fast Open #49
Comments
I don't know much about this myself, but PRs are most welcome to explore the design space here! |
@zonyitoo still interested in contributing this? |
I made a few steps but couldn't find a good design for it. |
We could just expose the system calls/flags if we can't get a nice cross-platform API. |
https://github.com/zonyitoo/tokio-tfo Made a simple repo for this. |
@zonyitoo do you still think this should go into Socket2? Or is your library a better place to keep it? |
Well, setting the I am ok to make a PR for setting |
Sounds good. |
There is a problem about how to design an unified API. Linux's |
We could document the behaviour, i.e. |
- Supported platforms: Linux-like, FreeBSD, macOS, Windows - ref rust-lang#49
TcpListener
All of Linux, OS X and Windows are the same, call
setsockopt
withTCP_FASTOPEN
optionTcpStream
This is a bit more complicated than
TcpListener
, because we have to sendSYN
with the first data packet to make TFO works. APIs are completely different on different platforms:Linux
Before 4.11, Linux uses
MSG_FASTOPEN
flag forsendto()
, doesn't need to callconnect()
After 4.11, Linux provides a
TCP_FASTOPEN_CONNECT
optionBSDs (except Darwin)
Uses
sendto()
as Linux withoutMSG_FASTOPEN
flagDarwin (OS X)
Darwin supports TFO after OS X 10.11, iOS 9.0, tvOS 9.0 and watchOS 2.0.
It supports with a new syscall
connectx
.SYN will be sent with the first
write
orsend
.Windows
Windows supports with
ConnectEx
, since Windows 10. https://docs.microsoft.com/en-us/windows/win32/api/mswsock/nc-mswsock-lpfn_connectexChallenge
As we can see for those OSes' APIs, (except OS X and Linux > 4.10) connections are made with the first
write()
, which means that if we want to support TFO, we have to put those code in the first call ofstd::io::Write::write
ortokio::AsyncWrite::poll_write
.There is no other way except customizing a
TcpStream
fromsocket()
and call different APIs on different OSes while sending the first data packet.I want to open a discussion here for how in Rust's world to support TFO gracefully.
Related API PRs
connectx
for OS X: Add TCP FastOpen support for macOS libc#1635TCP_FASTOPEN_CONNECT
for Linux: Add TCP_FASTOPEN_CONNECT for Linux after 4.11 libc#1634TCP_FASTOPEN
for Windows: Missing TCP_FASTOPEN retep998/winapi-rs#856The text was updated successfully, but these errors were encountered: