pub struct TcpSocketOptions {
pub nodelay: Option<bool>,
pub keepalive: Option<bool>,
pub keepalive_idle_secs: Option<u32>,
pub keepalive_interval_secs: Option<u32>,
pub keepalive_count: Option<u32>,
pub recv_buf: Option<u32>,
pub send_buf: Option<u32>,
pub linger_secs: Option<u32>,
pub quickack: Option<bool>,
pub reuse_port: Option<bool>,
}Expand description
Per-connection TCP tuning applied to every accepted socket.
All fields are optional. When None, the FreeBSD default is used.
Construct with Default::default() for all defaults, or use the builder
methods to override specific values.
let opts = TcpSocketOptions::default()
.nodelay(true)
.keepalive(true)
.keepalive_idle_secs(10)
.keepalive_interval_secs(5)
.keepalive_count(3);Fields§
§nodelay: Option<bool>Disable Nagle’s algorithm — send data immediately without coalescing small writes. Essential for latency-sensitive protocols.
keepalive: Option<bool>Enable TCP keepalive probes on idle connections. When the remote peer disappears without sending a FIN (crash, network partition), keepalive detects it and tears down the connection.
keepalive_idle_secs: Option<u32>Seconds of idle time before the first keepalive probe is sent. FreeBSD default: 7200 (2 hours).
keepalive_interval_secs: Option<u32>Seconds between consecutive keepalive probes after the first. FreeBSD default: 75.
keepalive_count: Option<u32>Number of unacknowledged keepalive probes before the connection is dropped. FreeBSD default: 8.
recv_buf: Option<u32>Receive buffer size in bytes. Larger buffers allow higher throughput on high-latency links. FreeBSD default: ~64 KB.
send_buf: Option<u32>Send buffer size in bytes. FreeBSD default: ~64 KB.
linger_secs: Option<u32>Linger timeout in seconds. When set, ff_close blocks (up to this
many seconds) until buffered data is sent, then sends RST if it
couldn’t drain in time. When None, close returns immediately and
the stack drains in the background.
quickack: Option<bool>Disable delayed ACKs — acknowledge segments immediately instead of
waiting up to 40ms to piggyback the ACK on outgoing data.
Complementary to nodelay for lowest latency.
reuse_port: Option<bool>Allow multiple sockets to bind the same address:port combination. Useful for multi-process F-Stack setups.
Implementations§
Source§impl TcpSocketOptions
impl TcpSocketOptions
Sourcepub fn nodelay(self, v: bool) -> Self
pub fn nodelay(self, v: bool) -> Self
Examples found in repository?
38fn main() {
39 // Docker/TAP configuration — swap for FStackConfig::for_bare_metal() on bare metal.
40 let cfg = FStackConfig::for_docker();
41
42 println!("Initializing F-Stack...");
43 init_fstack(&cfg.config_args(), &cfg.eal_args());
44
45 let bind_ip = "0.0.0.0".to_string();
46 let bind_port = 8080u16;
47
48 let tcp_opts = TcpSocketOptions::default()
49 .nodelay(true)
50 .quickack(true);
51
52 println!("Creating TCP listener on {}:{}...", bind_ip, bind_port);
53 let listener: UniquePtr<FStackTcpListener> =
54 create_tcp_listener(&bind_ip, bind_port, &tcp_opts.to_ffi(), on_connect, on_data, on_disconnect);
55
56 unsafe {
57 GLOBAL_LISTENER = Some(&*listener as *const FStackTcpListener);
58 }
59
60 println!("Starting F-Stack TCP event loop...");
61 run_fstack_tcp(&listener);
62}pub fn keepalive(self, v: bool) -> Self
pub fn keepalive_idle_secs(self, v: u32) -> Self
pub fn keepalive_interval_secs(self, v: u32) -> Self
pub fn keepalive_count(self, v: u32) -> Self
pub fn recv_buf(self, v: u32) -> Self
pub fn send_buf(self, v: u32) -> Self
pub fn linger_secs(self, v: u32) -> Self
Sourcepub fn quickack(self, v: bool) -> Self
pub fn quickack(self, v: bool) -> Self
Examples found in repository?
38fn main() {
39 // Docker/TAP configuration — swap for FStackConfig::for_bare_metal() on bare metal.
40 let cfg = FStackConfig::for_docker();
41
42 println!("Initializing F-Stack...");
43 init_fstack(&cfg.config_args(), &cfg.eal_args());
44
45 let bind_ip = "0.0.0.0".to_string();
46 let bind_port = 8080u16;
47
48 let tcp_opts = TcpSocketOptions::default()
49 .nodelay(true)
50 .quickack(true);
51
52 println!("Creating TCP listener on {}:{}...", bind_ip, bind_port);
53 let listener: UniquePtr<FStackTcpListener> =
54 create_tcp_listener(&bind_ip, bind_port, &tcp_opts.to_ffi(), on_connect, on_data, on_disconnect);
55
56 unsafe {
57 GLOBAL_LISTENER = Some(&*listener as *const FStackTcpListener);
58 }
59
60 println!("Starting F-Stack TCP event loop...");
61 run_fstack_tcp(&listener);
62}pub fn reuse_port(self, v: bool) -> Self
Sourcepub fn to_ffi(&self) -> TcpSocketOptionsFfi
pub fn to_ffi(&self) -> TcpSocketOptionsFfi
Convert to the flat cxx-bridge struct. -1 encodes “not set / use FreeBSD default”.
Examples found in repository?
38fn main() {
39 // Docker/TAP configuration — swap for FStackConfig::for_bare_metal() on bare metal.
40 let cfg = FStackConfig::for_docker();
41
42 println!("Initializing F-Stack...");
43 init_fstack(&cfg.config_args(), &cfg.eal_args());
44
45 let bind_ip = "0.0.0.0".to_string();
46 let bind_port = 8080u16;
47
48 let tcp_opts = TcpSocketOptions::default()
49 .nodelay(true)
50 .quickack(true);
51
52 println!("Creating TCP listener on {}:{}...", bind_ip, bind_port);
53 let listener: UniquePtr<FStackTcpListener> =
54 create_tcp_listener(&bind_ip, bind_port, &tcp_opts.to_ffi(), on_connect, on_data, on_disconnect);
55
56 unsafe {
57 GLOBAL_LISTENER = Some(&*listener as *const FStackTcpListener);
58 }
59
60 println!("Starting F-Stack TCP event loop...");
61 run_fstack_tcp(&listener);
62}Trait Implementations§
Source§impl Clone for TcpSocketOptions
impl Clone for TcpSocketOptions
Source§fn clone(&self) -> TcpSocketOptions
fn clone(&self) -> TcpSocketOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more