Skip to main content

Driver

Trait Driver 

Source
pub trait Driver:
    Send
    + Sync
    + AsRawFd {
    // Required methods
    fn submit(&self) -> Result<usize>;
    fn wait(&self) -> Result<usize>;
    fn wait_timeout(&self, duration: Duration) -> Result<(usize, bool)>;
    fn get_submission(&self) -> Option<&mut SubmitEntry>;
    fn get_completion(&self) -> Option<&CompletionEntry>;
    fn advance_completion(&self);
    fn register(&self, fd: RawFd, interest: Interest) -> Result<()>;
    fn deregister(&self, fd: RawFd) -> Result<()>;
    fn modify(&self, fd: RawFd, interest: Interest) -> Result<()>;
    fn submission_capacity(&self) -> usize;
    fn completion_capacity(&self) -> usize;
    fn supports_operation(&self, opcode: u8) -> bool;
}
Expand description

Core driver trait for async I/O operations 异步I/O操作的核心driver trait

This trait abstracts different I/O polling mechanisms (io-uring, epoll, kqueue) providing a unified interface for the runtime.

此trait抽象了不同的I/O轮询机制(io-uring、epoll、kqueue), 为运行时提供统一接口。

Required Methods§

Source

fn submit(&self) -> Result<usize>

Submit queued operations to the kernel 将队列中的操作提交给内核

Returns the number of operations submitted. 返回已提交的操作数量。

Source

fn wait(&self) -> Result<usize>

Wait for completion events indefinitely 无限等待完成事件

Returns the number of completion events available. 返回可用的完成事件数量。

Source

fn wait_timeout(&self, duration: Duration) -> Result<(usize, bool)>

Wait for completion events with a timeout 带超时等待完成事件

Returns (events_count, timed_out) where:

  • events_count: number of completion events / 完成事件数量
  • timed_out: true if timeout occurred, false if events arrived / 是否超时
Source

fn get_submission(&self) -> Option<&mut SubmitEntry>

Get a mutable reference to the next available submission entry 获取下一个可用提交条目的可变引用

Returns None if the submission queue is full. 如果提交队列已满则返回 None

Source

fn get_completion(&self) -> Option<&CompletionEntry>

Get a reference to the next available completion entry 获取下一个可用完成条目的引用

Returns None if the completion queue is empty. 如果完成队列为空则返回 None

Source

fn advance_completion(&self)

Advance the completion queue cursor, consuming the current entry 前进完成队列游标,消费当前条目

Source

fn register(&self, fd: RawFd, interest: Interest) -> Result<()>

Register interest in a file descriptor 注册对文件描述符的兴趣

This tells the driver to monitor the FD for specific events. 这告诉driver监控文件描述符的特定事件。

Source

fn deregister(&self, fd: RawFd) -> Result<()>

Deregister interest in a file descriptor 取消对文件描述符的兴趣注册

Source

fn modify(&self, fd: RawFd, interest: Interest) -> Result<()>

Modify the interest for a registered file descriptor 修改已注册文件描述符的兴趣

Source

fn submission_capacity(&self) -> usize

Get the capacity of the submission queue 获取提交队列的容量

Source

fn completion_capacity(&self) -> usize

Get the capacity of the completion queue 获取完成队列的容量

Source

fn supports_operation(&self, opcode: u8) -> bool

Check if the driver supports the specified operation 检查driver是否支持指定操作

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Driver for EpollDriver

Available on Linux only.
Source§

impl Driver for IoUringDriver

Available on Linux only.