#quic #tokio #async #sockets

tokio-quicker

A easy-to-use quic library for tokio

1 unstable release

0.0.2 Jan 28, 2024
0.0.1 Jan 28, 2024

#74 in #quic

26 downloads per month

MIT license

49KB
1K SLoC

tokio-quicker

Async QUIC Listener/Socket for tokio using quiche.

Roadmap

  • QuicListener for server use.
  • QuicSocket for client use.
  • Boringssl key generation (Can be disabled by disabling the default features).
  • Swappable backend (quiche/quinn) for boringssl and openssl support.

Examples

Client

First create a QuicSocket.

let mut connection = QuicSocket::bind("127.0.0.1:0")
        .await?
        .connect(Some("localhost"), "127.0.0.1:4433")
        .await?;

Then you can start opening new QuicStreams or receive incoming ones from the server.

let mut stream = connection.bidi(1).await?;
let mut stream = connection.incoming().await?;

These implement the tokio AsyncRead and AsyncWrite traits.

Server

Again create a QuicListener.

let mut listener = QuicListener::bind("127.0.0.1:4433").await?;

Then you can use a while loop to accept incoming connection and either handle them directly on the thread or move them to a new one.

while let Ok(mut connection) = listener.accept().await {
    tokio::spawn(async move {
        let mut stream = connection.incoming().await?;
        ...
        stream.shutdown().await?;
    });
}

Dependencies

~71MB
~1.5M SLoC