compio

repository·master·Indexed 23 days ago

https://github.com/compio-rs/compio

A thread-per-core Rust async runtime focused on completion-based IO, utilizing IOCP on Windows, io_uring on Linux, and polling on other Unix platforms. Version 0.19.1 provides high-level, cross-platform APIs for asynchronous filesystem operations, networking (TCP, QUIC), and process management, utilizing owned buffers via IoBuf and IoBufMut to avoid lifetime complexities common in poll-based runtimes.

Tokens
56.8K
Snippets
101
Records
365
Agent score
83%

What's inside compio

  1. Overview of compio-process features

    master

    The compio-process crate provides the following capabilities:

    • Async process spawning and management: Control the lifecycle of child processes.
    • Async stdio access: Asynchronously interact with stdin, stdout, and stderr streams.
    • Cross-platform support: Works on both Unix and Windows.
    • Compio integration: Built to work with compio's completion-based IO model.
    • Linux pidfd support: Optional support for efficient process monitoring on Linux via pidfd.
  2. What is Compio?

    master
    Compio is a thread-per-core Rust runtime designed around completion-based IO (IOCP/io_uring/polling). Unlike poll-based runtimes like Tokio, Compio is built to provide high-level APIs that directly leverage completion-based interfaces across multiple platforms, including Windows and Linux.
  3. Features of compio-ws

    master

    The compio-ws crate provides:

    • WebSocket client and server support.
    • A foundation built on the tungstenite WebSocket library.
    • TLS/SSL support via multiple backends:
      • native-tls: Platform-specific TLS.
      • rustls: Pure Rust TLS implementation.
    • Various certificate verification options: platform-verifier, native-certs, and webpki-roots.
  4. What is compio-driver and when to use it

    master

    The compio-driver crate provides the low-level Proactor implementation for the compio ecosystem. It acts as the platform-specific abstraction layer that manages the submission and completion of I/O operations.

    While most users will interact with compio indirectly through its high-level runtime, compio-driver can be used directly if you require low-level control over the I/O driver itself.

    Supported OS backends:

    • Windows: Uses IOCP (IO Completion Ports).
    • Linux: Uses io_uring (with an optional polling fallback).
    • Other Unix platforms: Uses polling.
  5. How completion-based async IO works in compio-io

    master
    Unlike traditional poll-based async IO traits (like those in tokio or futures), compio-io is designed for completion-based operations. The core mental model is that async operations work with owned buffers. Instead of passing a reference to a buffer, the traits work with buffers that implement IoBuf or IoBufMut. Upon completion of an operation, the trait returns both the buffer and the operation result. This allows the runtime to own the buffer during the asynchronous operation, avoiding lifetime complexities common in poll-based models.
  6. Install Compio

    master

    To use Compio in your Rust project, add it as a dependency using cargo add. It is recommended to enable the macros and fs features for high-level API support and filesystem operations.

    cargo add compio --features macros,fs
  7. Run compio in other async runtimes using compio-compat

    master

    The compio-compat layer allows you to run compio-specific code within other asynchronous runtimes, such as Tokio. To use this, you should use the compio::compat module re-exported from the main compio crate.

    To integrate compio with Tokio:

    1. Create a standard compio::runtime::Runtime.
    2. Wrap that runtime in a RuntimeCompat using a specific adapter (e.g., TokioAdapter).
    3. Use the resulting compat layer to execute your futures.
    use compio::compat::{RuntimeCompat, TokioAdapter};
    
    #[tokio::main]
    async fn main() {
        // Create a compio runtime:
        let runtime = compio::runtime::Runtime::new().unwrap();
        // Create the compat layer:
        let runtime = RuntimeCompat::<TokioAdapter>::new(runtime).unwrap();
        // Execute your future:
        runtime.execute(async {
            // Run compio-specific code
        }).await;
    }