Skip to main content

Driver

Trait Driver 

Source
pub trait Driver: Send {
    // Required methods
    fn kind(&self) -> DriverKind;
    fn register(
        &mut self,
        socket: SharedSocket,
        token: Token,
    ) -> Result<(), NetError>;
    fn submit(&mut self, operation: Operation) -> Result<(), Rejected>;
    fn wait(
        &mut self,
        out: &mut Completions,
        timeout: Option<Duration>,
    ) -> Result<usize, NetError>;
    fn cancel(
        &mut self,
        token: Token,
        which: OperationKind,
    ) -> Result<(), NetError>;
    fn deregister(&mut self, token: Token) -> Result<(), NetError>;
    fn waker(&self) -> DriverWaker;
}
Expand description

A driver: one per worker, used from one thread. See the module docs.

Unstable until 1.0.0. The driver holds each registered socket (a SharedSocket) from Driver::register until Driver::deregister, so the descriptor it does I/O on can never close and be reused by another connection while an operation or a cached readiness refers to it.

Required Methods§

Source

fn kind(&self) -> DriverKind

Which driver this is.

Source

fn register( &mut self, socket: SharedSocket, token: Token, ) -> Result<(), NetError>

Adds a non-blocking socket under token. The driver keeps socket until Driver::deregister: dropping the caller’s own clones before then does not close it.

§Errors

Os when the OS refuses.

Source

fn submit(&mut self, operation: Operation) -> Result<(), Rejected>

Starts an operation; its completion arrives through Driver::wait.

§Errors

Rejected gives the operation and its buffers back: the token is not registered, or the same kind of operation is already pending on it.

Source

fn wait( &mut self, out: &mut Completions, timeout: Option<Duration>, ) -> Result<usize, NetError>

Fills out with finished operations, waiting up to timeout for the first (None: until one finishes or the waker fires). Returns how many.

§Errors

Os when the wait itself fails.

Source

fn cancel(&mut self, token: Token, which: OperationKind) -> Result<(), NetError>

Cancels the pending operation of kind which; it still completes exactly once (with Aborted, or with its result if it already finished).

§Errors

Os when the OS refuses.

Source

fn deregister(&mut self, token: Token) -> Result<(), NetError>

Removes the socket; no completion arrives for it afterwards. The driver drops its clone of the socket, which closes it if no other clone is left.

§Errors

Os when the OS refuses.

Source

fn waker(&self) -> DriverWaker

A waker for this driver.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§