Expand description
ringline — io_uring-native async I/O runtime for Linux.
ringline is a thread-per-core I/O framework built directly on io_uring.
It provides an async/await API (AsyncEventHandler) on a single-threaded
executor with no work-stealing.
§Quick Start
use ringline::{AsyncEventHandler, Config, ConnCtx, ParseResult, RinglineBuilder};
struct Echo;
impl AsyncEventHandler for Echo {
fn on_accept(&self, conn: ConnCtx) -> impl std::future::Future<Output = ()> + 'static {
async move {
loop {
let n = conn.with_data(|data| {
conn.send_nowait(data).ok();
ParseResult::Consumed(data.len())
}).await;
if n == 0 { break; }
}
}
}
fn create_for_worker(_id: usize) -> Self { Echo }
}
fn main() -> Result<(), ringline::Error> {
let config = Config::default();
let (_shutdown, handles) = RinglineBuilder::new(config)
.bind("127.0.0.1:7878".parse().unwrap())
.launch::<Echo>()?;
for h in handles { h.join().unwrap()?; }
Ok(())
}§Platform
Linux 6.0+ only. Requires io_uring with multishot recv, ring-provided buffers, SendMsgZc, and fixed file table support.
Re-exports§
pub use handler::ConnToken;pub use handler::DriverCtx;pub use handler::SendPart;pub use handler::UdpToken;pub use error::TimerExhausted;pub use error::UdpSendError;pub use config::Config;pub use config::ConfigBuilder;pub use config::RecvBufferConfig;pub use config::WorkerConfig;pub use direct_io::DirectIoCompletion;pub use direct_io::DirectIoConfig;pub use direct_io::DirectIoFile;pub use direct_io::DirectIoOp;pub use error::Error;pub use guard::GuardBox;pub use guard::SendGuard;pub use nvme::NvmeCompletion;pub use nvme::NvmeConfig;pub use nvme::NvmeDevice;
Modules§
- config
- direct_
io - Direct I/O via io_uring (
O_DIRECT+IORING_OP_READ/IORING_OP_WRITE). - error
- guard
- handler
- nvme
- NVMe io_uring passthrough types and helpers.
Structs§
- Async
Send Builder - Async scatter-gather send builder. Builder for scatter-gather sends in the async API.
- ConnCtx
- Async connection context with send/recv futures.
The async equivalent of
ConnToken+DriverCtx. Passed to the connection’s async fn, provides I/O methods. - Connect
Future - Future that completes when a connect finishes.
Future that awaits an outbound TCP connection. The connect SQE was submitted
eagerly by
ConnCtx::connect— this future waits for the CQE result. - Deadline
- A monotonic clock deadline for absolute timers. A monotonic clock deadline for use with absolute timers.
- Disk
IoFuture - Future that awaits a disk I/O completion (NVMe or Direct I/O). Future that awaits a disk I/O completion (NVMe or Direct I/O).
- Elapsed
- Error returned when a
timeout()expires. Error returned when atimeout()deadline expires. - Join
- Future returned by
join(). Future that polls two sub-futures and returns both outputs when complete. - Join3
- Future returned by
join3(). Future that polls three sub-futures and returns all outputs when complete. - Memory
Region - Memory region for io_uring fixed buffer registration. A user-registered memory region (e.g., mmap’d storage arena).
- Recv
Ready Future - Future that resolves when recv data is available (sink, accumulator, or close).
Future returned by
ConnCtx::recv_ready. Resolves when: - Region
Id - Region identifier for
SendGuardimplementations. Identifies a registered memory region (index into the iovec array). - Ringline
Builder - Builder for launching ringline workers. Builder for launching ringline workers with optional listener/acceptor.
- Select
- Future returned by
select(). Future that polls two sub-futures and returns whichever completes first. Biased: always pollsabeforeb. - Select3
- Future returned by
select3(). Future that polls three sub-futures and returns whichever completes first. Biased: pollsa, thenb, thenc. - Send
Future - Future that completes when a send finishes.
Future that awaits send completion. The SQE was already submitted eagerly
by
ConnCtx::send— this future only waits for the CQE result. No data stored in the future. No allocation. - Shutdown
Handle - Handle for triggering graceful shutdown.
Handle returned by
launch()to trigger graceful shutdown of all workers. - Sleep
Future - Future returned by
sleep(). Future returned bysleep()orsleep_until(). Completes after the configured duration or at the given deadline. - TaskId
- Opaque handle for a standalone spawned task.
Opaque handle for a standalone task spawned via
spawn(). - Timeout
Future - Future returned by
timeout(). Future returned bytimeout()ortimeout_at(). - UdpCtx
- Async context for a UDP socket. Async context for a UDP socket.
- UdpRecv
Future - Future returned by
UdpCtx::recv_from(). Future returned byUdpCtx::recv_from(). - With
Bytes Future - Future that provides received data as zero-copy
Bytes. Future returned byConnCtx::with_bytes. - With
Data Future - Future that provides received data.
Future returned by
ConnCtx::with_data.
Enums§
- Either
- Result of
select()— which branch completed. Result ofselect()— indicates which branch completed first. - Either3
- Result of
select3()— which branch completed. Result ofselect3()— indicates which of three branches completed first. - Parse
Result - Result of a parse closure: consumed bytes or need more data.
Result of a parse closure passed to
ConnCtx::with_dataorConnCtx::with_bytes.
Constants§
- MAX_
GUARDS - Maximum zero-copy guards per scatter-gather send.
- MAX_
IOVECS - Maximum iovecs per scatter-gather send.
Traits§
- Async
Event Handler - Trait for async event handlers (one task per connection). Trait for async connection handlers.
Functions§
- connect
- Initiate an outbound TCP connection from any async task. Initiate an outbound TCP connection from any async task (connection or standalone).
- connect_
with_ timeout - Initiate an outbound TCP connection with a timeout from any async task. Initiate an outbound TCP connection with a timeout from any async task.
- direct_
io_ ⚠read - Submit a Direct I/O read and return a future for the result. Submit a Direct I/O read and return a future for the result.
- direct_
io_ ⚠write - Submit a Direct I/O write and return a future for the result. Submit a Direct I/O write and return a future for the result.
- join
- Poll two futures concurrently, returning both outputs when complete. Poll two futures concurrently, returning both outputs when they complete.
- join3
- Poll three futures concurrently, returning all outputs when complete. Poll three futures concurrently, returning all outputs when they complete.
- nvme_
read - Submit an NVMe read and return a future for the result. Submit an NVMe read and return a future for the result.
- nvme_
write - Submit an NVMe write and return a future for the result. Submit an NVMe write and return a future for the result.
- open_
direct_ io_ file - Open a Direct I/O file from any async task. Open a Direct I/O file from any async task.
- open_
nvme_ device - Open an NVMe device from any async task. Open an NVMe device from any async task.
- request_
shutdown - Request graceful shutdown from any async task. Request graceful shutdown of the worker event loop from any async task.
- select
- Poll two futures concurrently, returning whichever completes first. Poll two futures concurrently, returning whichever completes first.
- select3
- Poll three futures concurrently, returning whichever completes first. Poll three futures concurrently, returning whichever completes first.
- sleep
- Create a future that completes after a duration. Create a future that completes after the given duration.
- sleep_
until - Create a future that completes at an absolute deadline. Create a future that completes at the given absolute deadline.
- spawn
- Spawn a standalone async task on the current worker. Spawn a standalone async task on the current worker thread.
- timeout
- Wrap a future with a deadline.
Wrap a future with a deadline. If the future does not complete within
duration, returnsErr(Elapsed). - timeout_
at - Wrap a future with an absolute deadline.
Wrap a future with an absolute deadline. If the future does not complete
before
deadline, returnsErr(Elapsed). - try_
sleep - Fallible sleep that returns an error if the timer pool is exhausted. Create a sleep future, returning an error if the timer pool is exhausted.
- try_
sleep_ until - Fallible sleep_until that returns an error if the timer pool is exhausted. Create an absolute-deadline sleep, returning an error if the timer pool is exhausted.
- try_
timeout - Fallible timeout that returns an error if the timer pool is exhausted. Wrap a future with a deadline, returning an error if the timer pool is full.
- try_
timeout_ at - Fallible timeout_at that returns an error if the timer pool is exhausted. Wrap a future with an absolute deadline, returning an error if the timer pool is full.