Skip to main content

Engine

Trait Engine 

Source
pub trait Engine {
    // Required methods
    fn kind(&self) -> &'static str;
    fn add_listener(&mut self, fd: RawFd, token: Token) -> Result<()>;
    fn add_stream(&mut self, fd: RawFd, token: Token) -> Result<()>;
    fn read(&mut self, token: Token, fd: RawFd, slot: u32) -> Result<Poll>;
    fn write(
        &mut self,
        token: Token,
        fd: RawFd,
        slot: u32,
        len: usize,
        offset: usize,
    ) -> Result<Poll>;
    fn connect(
        &mut self,
        token: Token,
        addr: SocketAddr,
    ) -> Result<(RawFd, Poll)>;
    fn connect_unix(
        &mut self,
        token: Token,
        path: &Path,
    ) -> Result<(RawFd, Poll)>;
    fn accept(
        &mut self,
        lfd: RawFd,
        ltoken: Token,
    ) -> Result<Option<(RawFd, SocketAddr)>>;
    fn splice_pump(
        &mut self,
        a: Token,
        afd: i32,
        b: Token,
        bfd: i32,
    ) -> Result<()>;
    fn remove(&mut self, fd: RawFd);
    fn poll(
        &mut self,
        timeout: Option<Duration>,
        out: &mut Vec<Cqe>,
    ) -> Result<()>;
    fn take_accepted(&mut self, fd: RawFd) -> Option<SocketAddr>;
}
Expand description

Transport engine — owned and driven by a single worker thread.

Required Methods§

Source

fn kind(&self) -> &'static str

Backend name for diagnostics (io_uring / mio).

Source

fn add_listener(&mut self, fd: RawFd, token: Token) -> Result<()>

Registers a nonblocking listening socket for accept readiness.

§Errors

Backend registration failure.

Source

fn add_stream(&mut self, fd: RawFd, token: Token) -> Result<()>

Registers a connected socket for read/write readiness.

§Errors

Backend registration failure.

Source

fn read(&mut self, token: Token, fd: RawFd, slot: u32) -> Result<Poll>

Queues one read into pool slot. The completion yields bytes read; 0 means EOF.

§Errors

Submission failure (not EAGAIN — that becomes Pending).

Source

fn write( &mut self, token: Token, fd: RawFd, slot: u32, len: usize, offset: usize, ) -> Result<Poll>

Queues a write of slot[0..len], resuming from a prior partial write when the backend tracks one for this token.

§Errors

Submission failure (not EAGAIN).

Source

fn connect(&mut self, token: Token, addr: SocketAddr) -> Result<(RawFd, Poll)>

Starts a nonblocking connect(2); completion is a CQE where result == Ok(0) means established.

§Errors

Socket creation or connect submission failure.

Source

fn connect_unix(&mut self, token: Token, path: &Path) -> Result<(RawFd, Poll)>

Starts a nonblocking UDS connect(2) to path.

§Errors

Socket creation or connect submission failure.

Source

fn accept( &mut self, lfd: RawFd, ltoken: Token, ) -> Result<Option<(RawFd, SocketAddr)>>

Attempts an accept on a registered listener; Ok(Some(..)) completes inline, Ok(None) waits for a CQE on the listener token.

§Errors

Fatal (non-EAGAIN) accept error.

Source

fn splice_pump(&mut self, a: Token, afd: i32, b: Token, bfd: i32) -> Result<()>

Starts a bidirectional zero-copy splice pump between two registered streams (IO-04). Completions on either token report bytes moved; Ok(0) signals EOF for that direction.

§Errors

Submission failure.

Source

fn remove(&mut self, fd: RawFd)

Removes a descriptor (before the worker closes it).

Source

fn poll(&mut self, timeout: Option<Duration>, out: &mut Vec<Cqe>) -> Result<()>

Drives the backend, filling out with completions. Blocks up to timeout (or indefinitely when None).

§Errors

Backend event-loop failure (unrecoverable; worker exits).

Source

fn take_accepted(&mut self, fd: RawFd) -> Option<SocketAddr>

Pops addresses of accepted connections reported by accept CQEs.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§