Skip to content

Commit b030ee4

Browse files
authored
Merge pull request #1635 from zonyitoo/feature-macos-fastopen
Add TCP FastOpen support for macOS
2 parents 4a9bf92 + 53a2e7e commit b030ee4

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/unix/bsd/apple/mod.rs

+48
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub type posix_spawn_file_actions_t = *mut ::c_void;
3131
pub type key_t = ::c_int;
3232
pub type shmatt_t = ::c_ushort;
3333

34+
pub type sae_associd_t = u32;
35+
pub type sae_connid_t = u32;
36+
3437
deprecated_mach! {
3538
pub type vm_prot_t = ::c_int;
3639
pub type vm_size_t = ::uintptr_t;
@@ -493,6 +496,16 @@ s! {
493496
pub struct in_addr {
494497
pub s_addr: ::in_addr_t,
495498
}
499+
500+
// sys/socket.h
501+
502+
pub struct sa_endpoints_t {
503+
pub sae_srcif: ::c_uint, // optional source interface
504+
pub sae_srcaddr: *const ::sockaddr, // optional source address
505+
pub sae_srcaddrlen: ::socklen_t, // size of source address
506+
pub sae_dstaddr: *const ::sockaddr, // destination address
507+
pub sae_dstaddrlen: ::socklen_t, // size of destination address
508+
}
496509
}
497510

498511
s_no_extra_traits! {
@@ -2216,6 +2229,8 @@ pub const IPV6_RECVPKTINFO: ::c_int = 61;
22162229
pub const TCP_NOPUSH: ::c_int = 4;
22172230
pub const TCP_NOOPT: ::c_int = 8;
22182231
pub const TCP_KEEPALIVE: ::c_int = 0x10;
2232+
/// Enable/Disable TCP Fastopen on this socket
2233+
pub const TCP_FASTOPEN: ::c_int = 0x105;
22192234

22202235
pub const SOL_LOCAL: ::c_int = 0;
22212236

@@ -2304,6 +2319,23 @@ pub const SHUT_RD: ::c_int = 0;
23042319
pub const SHUT_WR: ::c_int = 1;
23052320
pub const SHUT_RDWR: ::c_int = 2;
23062321

2322+
pub const SAE_ASSOCID_ANY: ::sae_associd_t = 0;
2323+
/// ((sae_associd_t)(-1ULL))
2324+
pub const SAE_ASSOCID_ALL: ::sae_associd_t = 0xffffffff;
2325+
2326+
pub const SAE_CONNID_ANY: ::sae_connid_t = 0;
2327+
/// ((sae_connid_t)(-1ULL))
2328+
pub const SAE_CONNID_ALL: ::sae_connid_t = 0xffffffff;
2329+
2330+
// connectx() flag parameters
2331+
2332+
/// resume connect() on read/write
2333+
pub const CONNECT_RESUME_ON_READ_WRITE: ::c_uint = 0x1;
2334+
/// data is idempotent
2335+
pub const CONNECT_DATA_IDEMPOTENT: ::c_uint = 0x2;
2336+
/// data includes security that replaces the TFO-cookie
2337+
pub const CONNECT_DATA_AUTHENTICATED: ::c_uint = 0x4;
2338+
23072339
pub const LOCK_SH: ::c_int = 1;
23082340
pub const LOCK_EX: ::c_int = 2;
23092341
pub const LOCK_NB: ::c_int = 4;
@@ -3528,6 +3560,22 @@ extern "C" {
35283560
newfd: ::c_int,
35293561
) -> ::c_int;
35303562
pub fn uname(buf: *mut ::utsname) -> ::c_int;
3563+
3564+
pub fn connectx(
3565+
socket: ::c_int,
3566+
endpoints: *const sa_endpoints_t,
3567+
associd: sae_associd_t,
3568+
flags: ::c_uint,
3569+
iov: *const ::iovec,
3570+
iovcnt: ::c_uint,
3571+
len: *mut ::size_t,
3572+
connid: *mut sae_connid_t,
3573+
) -> ::c_int;
3574+
pub fn disconnectx(
3575+
socket: ::c_int,
3576+
associd: sae_associd_t,
3577+
connid: sae_connid_t,
3578+
) -> ::c_int;
35313579
}
35323580

35333581
cfg_if! {

0 commit comments

Comments
 (0)