-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add TCP FastOpen support for macOS #1632
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
Comments
Clientuse std::mem;
use std::ptr;
use libc;
extern "C" {
fn inet_pton(af: libc::c_int, src: *const libc::c_char, dst: *mut libc::c_void) -> libc::c_int;
fn htons(hostshort: u16) -> u16;
}
fn main() {
unsafe {
let socket = libc::socket(libc::PF_INET, libc::SOCK_STREAM, libc::IPPROTO_TCP);
assert!(socket > 0);
println!("Socket {}", socket);
let mut saddr: libc::sockaddr_in = mem::zeroed();
saddr.sin_family = libc::AF_INET as libc::sa_family_t;
saddr.sin_port = htons(8000);
inet_pton(
libc::AF_INET,
"127.0.0.1".as_ptr() as *const _,
&mut saddr.sin_addr as *mut _ as *mut libc::c_void,
);
let mut endpoints: libc::sa_endpoints_t = mem::zeroed();
endpoints.sae_dstaddr = &mut saddr as *mut _ as *mut libc::sockaddr;
endpoints.sae_dstaddrlen = mem::size_of_val(&saddr) as libc::socklen_t;
let ret = libc::connectx(
socket,
&mut endpoints as *mut _,
libc::SAE_ASSOCID_ANY,
libc::CONNECT_DATA_IDEMPOTENT,
ptr::null(),
0,
ptr::null_mut(),
ptr::null_mut(),
);
assert!(ret == 0);
let ret = libc::disconnectx(socket, libc::SAE_ASSOCID_ANY, libc::SAE_CONNID_ANY);
assert!(ret == 0);
}
} Serveruse std::mem;
use libc;
extern "C" {
fn inet_pton(af: libc::c_int, src: *const libc::c_char, dst: *mut libc::c_void) -> libc::c_int;
fn htons(hostshort: u16) -> u16;
}
fn main() {
unsafe {
let socket = libc::socket(libc::PF_INET, libc::SOCK_STREAM, 0);
assert!(socket > 0);
println!("Socket {}", socket);
let mut saddr: libc::sockaddr_in = mem::zeroed();
saddr.sin_family = libc::AF_INET as libc::sa_family_t;
saddr.sin_port = htons(8000);
inet_pton(
libc::AF_INET,
"127.0.0.1".as_ptr() as *const _,
&mut saddr.sin_addr as *mut _ as *mut libc::c_void,
);
let ret = libc::bind(
socket,
&saddr as *const _ as *const libc::sockaddr,
mem::size_of_val(&saddr) as libc::socklen_t,
);
assert!(ret == 0);
let queue_len: libc::c_int = 5;
let ret = libc::listen(socket, queue_len);
assert!(ret == 0);
let enable: libc::c_int = 1;
let ret = libc::setsockopt(
socket,
libc::IPPROTO_TCP,
libc::TCP_FASTOPEN,
&enable as *const _ as *const libc::c_void,
mem::size_of_val(&enable) as libc::socklen_t,
);
assert!(ret == 0);
loop {
let mut saddr: libc::sockaddr = mem::zeroed();
let mut slen: libc::socklen_t = 0;
let csocket = libc::accept(socket, &mut saddr, &mut slen);
assert!(csocket > 0);
println!("Accepted csocket {}", csocket);
libc::close(csocket);
}
}
} |
This was referenced Dec 31, 2019
database64128
added a commit
to database64128/libc
that referenced
this issue
Mar 3, 2023
This is used to disable the backoff mechanism, otherwise TFO is basically unusable. Updates rust-lang#1632 and rust-lang#1635 Definition: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/tcp.h#L310 Related commits/PRs: zonyitoo/tokio-tfo#5, database64128/tfo-go@c980f6b
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
connectx
system callThis function is commonly used for inititiating a TCP Fast Open connection.
Available since iOS 9 and OS X 10.11
Definition:
Example usage:
Variable definitions
SAE_ASSOCID_ANY
CONNECT_DATA_IDEMPOTENT
andCONNECT_RESUME_ON_READ_WRITE
sa_endpoints_t
sae_associd_t
The text was updated successfully, but these errors were encountered: