Skip to main content

SocketOptions

Trait SocketOptions 

Source
pub trait SocketOptions<O: SocketOption>: SocketGetOption<O> + SocketSetOption<O> { }
Expand description

Convenience aggregate of SocketGetOption<O> and SocketSetOption<O>, automatically implemented for schedulers providing both operations for an option. Generic consumers require only the options they use, such as S: SocketOptions<TcpNoDelay>.

An absent implementation is a compile-time error. Socket type, protocol, state, and OS policy can still reject an operation at runtime; preserve those errors. Options retain their OS semantics, including address reuse and inheritance on accepted sockets. Read-only and write-only controls implement only their respective operation trait. Differently shaped controls can use separate extension traits.

Both futures are lazy and check cancellation before the syscall. Once executed, the syscall’s result wins concurrent cancellation; dropping an unpolled setter changes nothing. Await setters before operations that depend on them. There is no extra serialization between concurrent option operations, and get-followed-by-set is not atomic.

Option values are checked at compile time:

ⓘ
use base_scheduler::{Cancellation, SocketOptions, TcpNoDelay};
async fn configure<S: SocketOptions<TcpNoDelay>>(scheduler: &S, socket: &S::Socket) {
    scheduler.socket_set_option(socket, TcpNoDelay, 1_u32, &Cancellation::never()).await;
}

Merely supporting sockets does not imply support for every option:

ⓘ
use base_scheduler::{Cancellation, SocketOperation, SocketSetOption, TcpNoDelay};
async fn configure<S: SocketOperation>(scheduler: &S, socket: &S::Socket) {
    scheduler.socket_set_option(socket, TcpNoDelay, true, &Cancellation::never()).await;
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§