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
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.
Thanks!
The text was updated successfully, but these errors were encountered:
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(())
}
}
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.
Thanks!
The text was updated successfully, but these errors were encountered: