Lio - Platform-Independent Async I/O Library
Lio is a high-performance, platform-independent async I/O library that provides native support for the most efficient I/O mechanisms on each platform:
- Linux: Uses io_uring for maximum performance
- Windows: Uses IOCP (I/O Completion Ports)
- macOS: Uses kqueue for event notification
Features
- Zero-copy operations where possible
- Async/await support with standard Rust futures
- Platform-specific optimizations automatically selected
- File I/O operations: read, write, open, close, truncate
- Network operations: socket, bind, listen, accept, connect, send, recv
- Automatic fallback to blocking operations when async isn't supported
NOTE
Currently this library is a bit finicky ([libc::accept] especially) on linux machines that doesn't support
io-uring operations, like wsl2. If anyone has a good idea of api design and detecting io-uring support on linux,
please file an issue.
This problem arises when the library checks for the specific operation support, if yes everything works. If no, it will call the blocking normal syscall. With accept, that means blocking in a future which is really bad.
Quick Start
use ;
use RawFd;
async
Architecture
The library automatically selects the most efficient I/O mechanism:
- On Linux with io_uring support, operations are submitted to the kernel's submission queue
- On other platforms, operations use polling-based async I/O with automatic fallback to blocking
- All operations return
OperationProgress<T>which implementsFuture<Output = io::Result<[different based on operation]>>
Platform Support
| Platform | I/O Mechanism | Status |
|---|---|---|
| Linux | io_uring | ✅ Async IO support |
| Windows | IOCP | ✅ Full support |
| macOS | kqueue | ✅ event notification (kqueue) |
| Other Unix | poll/epoll | ✅ event notification (epoll/poll/event ports) |
Examples
File I/O
use CString;
async
Network I/O
use ;
async
Safety and Threading
- All operations are safe and follow Rust's memory safety guarantees
- The library automatically handles thread management for background I/O processing
- Operations can be safely used across different threads
- Proper cleanup is guaranteed through Rust's drop semantics
Error Handling
All operations return std::io::Result<T> or BufResult<T, B> for operations
that return buffers. Errors are automatically converted from platform-specific
error codes to Rust's standard I/O error types.
License
This project is licensed under the MIT License - see the LICENSE file for details.