You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there any struct/trait in quiche that implement trait std::io::Read/Write? #984
I have a TCP server running in production that I'm now trying to migrate to QUIC.
The client/server example is some kind of complicated, I think it will be much helpful if quiche::Connection(or anything else) implement trait std::io::Read/Write, so anyone having some knowledge of TCPStream can easily adopt quiche in their own program.
I know I can wrap it myself, but it will be much convenient if it is right there.
use quiche::Connection;
use std::io::{self, Read, Write};
// A wrapper to adapt `quiche::Connection` to `std::io::Read`.
pub struct QuicheRead<'a> {
conn: &'a mut Connection,
}
impl<'a> QuicheRead<'a> {
pub fn new(conn: &'a mut Connection) -> Self {
QuicheRead { conn }
}
}
impl<'a> Read for QuicheRead<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
// Adapt the quiche connection to read data
// This is a simplified example, in practice, you might need to handle more cases.
match self.conn.recv(buf) {
Ok(len) => Ok(len),
Err(_) => Err(io::Error::new(io::ErrorKind::Other, "Read error")),
}
}
}
// A wrapper to adapt `quiche::Connection` to `std::io::Write`.
pub struct QuicheWrite<'a> {
conn: &'a mut Connection,
}
impl<'a> QuicheWrite<'a> {
pub fn new(conn: &'a mut Connection) -> Self {
QuicheWrite { conn }
}
}
impl<'a> Write for QuicheWrite<'a> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
// Adapt the quiche connection to write data
// This is a simplified example, in practice, you might need to handle more cases.
match self.conn.send(buf) {
Ok(_) => Ok(buf.len()),
Err(_) => Err(io::Error::new(io::ErrorKind::Other, "Write error")),
}
}
fn flush(&mut self) -> io::Result<()> {
// QUIC doesn't have a direct flush method, but you might want to handle it
Ok(())
}
}
Closing as answered. quiche is a sans-I/O library, so it exposes stream_recv() and stream_send() rather than std::io::Read and Write, which would require quiche to own the socket and timers. tokio-quiche provides an async integration that handles the I/O.
Activity
ljluestc commentedon Sep 10, 2024
ghedo commentedon Nov 25, 2026
Closing as answered. quiche is a sans-I/O library, so it exposes
stream_recv()andstream_send()rather thanstd::io::ReadandWrite, which would require quiche to own the socket and timers. tokio-quiche provides an async integration that handles the I/O.