lio 0.1.1

A platform-independent async I/O library with native support for io_uring (Linux), IOCP (Windows), and kqueue (macOS)
Documentation

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 lio::{read, write, close};
use std::os::fd::RawFd;

async fn example() -> std::io::Result<()> {
    let fd: RawFd = 1; // stdout
    let data = b"Hello, World!\n".to_vec();
    
    // Async write operation
    let (result, _buf) = write(fd, data, 0).await?;
    println!("Wrote {} bytes", result);
    
    Ok(())
}

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 implements Future<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 std::ffi::CString;

async fn file_operations() -> std::io::Result<()> {
    let path = CString::new("/tmp/test.txt").unwrap();
    let fd = lio::openat(libc::AT_FDCWD, path, libc::O_CREAT | libc::O_WRONLY).await?;
    
    let data = b"Hello, async I/O!".to_vec();
    let (bytes_written, _buf) = lio::write(fd, data, 0).await?;
    
    close(fd).await?;
    Ok(())
}

Network I/O

use socket2::{Domain, Type, Protocol};

async fn network_operations() -> std::io::Result<()> {
    let sock = libc::socket(Domain::INET, Type::STREAM, Some(Protocol::TCP)).await?;
    let addr = socket2::SockAddr::from("127.0.0.1:8080".parse::<std::net::SocketAddr>().unwrap());
    
    libc::bind(sock, addr).await?;
    libc::listen(sock).await?;
    
    // Accept connections...
    Ok(())
}

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.