Expand description
A completion-style I/O driver, one per event-loop thread.
The model is the one io_uring and IOCP provide natively, and that epoll and kqueue emulate
inside Driver::turn with readiness events plus non-blocking calls:
- Receive into buffers the driver owns. The caller hands buffers to the driver with
Driver::provide; the driver takes one only when data has actually arrived (io_uring’s provided-buffer ring, a read after readiness on epoll and kqueue, a read after a zero-byteWSARecvon IOCP). So an idle connection holds no buffer. Data comes back asEvent::Datacarrying the filledVec<u8>; the caller owns it from then on. - Send owned buffers with
Driver::send. Sends on one connection go out in order and are batched: everything queued during a turn is written at the start of the nextDriver::turn, with one vectored call (or one submission) per connection. Each buffer comes back asEvent::Sentonce written, so it can be reused. - Accept on listeners registered with
Driver::listen:Event::Acceptedcarries the new non-blocking socket, which the caller registers withDriver::stream(possibly on another loop’s driver). - Close with
Driver::close: the driver cancels what is in flight, returns every buffer, closes the socket and reportsEvent::Closed; only then may the caller reuse the key. - Wake a driver blocked in
Driver::turnfrom any thread with aWaker.
The driver never calls back into user code: Driver::turn appends Events to a vector.
Structs§
- Driver
- A completion-style I/O driver for one thread. See the module docs.
- Driver
Config - Driver settings. The defaults suit a server loop.
- Driver
Stats - System calls and events counted by a driver (plain counters; read them on the loop thread).
- Id
- A handle to a socket registered with a
Driver. Stale handles (after the socket was closed) are detected by a generation count and ignored. - Waker
- Wakes a driver blocked in
Driver::turnfrom any thread. Cheap to clone; repeated wakes before the driver runs collapse into one OS signal.
Enums§
- Backend
- Which I/O back end a driver uses.
- Event
- Something that happened, reported by
Driver::turn. - OutBuf
- A buffer to send: owned (returned by
Event::Sentfor reuse) or static.