Trait mfio::backend::IoBackend

source ·
pub trait IoBackend<Handle: Pollable = DefaultHandle> {
    type Backend: Future<Output = ()> + Send + ?Sized;

    // Required methods
    fn polling_handle(&self) -> Option<PollingHandle<'_>>;
    fn get_backend(&self) -> BackendHandle<'_, Self::Backend>;
}
Expand description

Primary trait describing I/O backends.

This trait is implemented at the outer-most stateful object of the I/O context. A IoBackend has the opportunity to expose efficient ways of driving said backend to completion.

Users may want to call methods available on IoBackendExt, instead of the ones on this trait.

Required Associated Types§

source

type Backend: Future<Output = ()> + Send + ?Sized

Required Methods§

source

fn polling_handle(&self) -> Option<PollingHandle<'_>>

Gets handle to the backing event system.

This function returns a handle and a waker. The handle is a RawFd on Unix systems, and a RawHandle on Windows. This handle is meant to be polled/waited on by the system.

The waker is opaque, but should unblock the handle once signaled.

If the function returns None, then it can be assumed that the backend will wake any waker up with other mechanism (such as auxiliary thread), and that the polling implementation can simply park the thread.

source

fn get_backend(&self) -> BackendHandle<'_, Self::Backend>

Acquires exclusive handle to IO backend.

Panics

This function panics when multiple backend handles are attempted to be acquired. This function does not return an Option, because such case usually indicates a bug in the code.

Implementors§