Skip to main content

TcpSocketOptions

Struct TcpSocketOptions 

Source
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

Source

pub fn nodelay(self, v: bool) -> Self

Examples found in repository?
examples/tcp_echo.rs (line 49)
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}
Source

pub fn keepalive(self, v: bool) -> Self

Source

pub fn keepalive_idle_secs(self, v: u32) -> Self

Source

pub fn keepalive_interval_secs(self, v: u32) -> Self

Source

pub fn keepalive_count(self, v: u32) -> Self

Source

pub fn recv_buf(self, v: u32) -> Self

Source

pub fn send_buf(self, v: u32) -> Self

Source

pub fn linger_secs(self, v: u32) -> Self

Source

pub fn quickack(self, v: bool) -> Self

Examples found in repository?
examples/tcp_echo.rs (line 50)
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}
Source

pub fn reuse_port(self, v: bool) -> Self

Source

pub fn to_ffi(&self) -> TcpSocketOptionsFfi

Convert to the flat cxx-bridge struct. -1 encodes “not set / use FreeBSD default”.

Examples found in repository?
examples/tcp_echo.rs (line 54)
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

Source§

fn clone(&self) -> TcpSocketOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TcpSocketOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TcpSocketOptions

Source§

fn default() -> TcpSocketOptions

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.