pub trait QuicIO: Send + Sync {
// Required methods
fn bind_uri(&self) -> BindUri;
fn real_addr(&self) -> Result<RealAddr, Error>;
fn max_segment_size(&self) -> Result<usize, Error>;
fn max_segments(&self) -> Result<usize, Error>;
fn poll_send(
&self,
cx: &mut Context<'_>,
pkts: &[IoSlice<'_>],
hdr: PacketHeader,
) -> Poll<Result<usize, Error>>;
fn poll_recv(
&self,
cx: &mut Context<'_>,
pkts: &mut [BytesMut],
hdrs: &mut [PacketHeader],
) -> Poll<Result<usize, Error>>;
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>;
}
Expand description
QUIC network I/O trait
Provides a unified interface for different network transport implementations. Note that some implementations may not support all bind address types.
gm-quic
uses ProductQuicIO
to create (bind) a new QuicIO
instance.
Read its documentation for more information.
Wrapping a new QuicIO
is easy,
you can refer to the implementations in the iface::handy
module.
Required Methods§
Sourcefn bind_uri(&self) -> BindUri
fn bind_uri(&self) -> BindUri
Get the bind address that this interface is bound to
This value cannot change after the interface is bound, as it is used as the unique identifier for the interface.
Sourcefn real_addr(&self) -> Result<RealAddr, Error>
fn real_addr(&self) -> Result<RealAddr, Error>
Get the actual address that this interface is bound to.
For example, if this interface is bound to an BindUri
,
this function should return the actual IP address and port
address of this interface.
Just like UdpSocket::local_addr
may return an error,
sometimes an interface cannot get its own actual address,
then the implementation should return an error as well.
Sourcefn max_segment_size(&self) -> Result<usize, Error>
fn max_segment_size(&self) -> Result<usize, Error>
Maximum size of a single network segment in bytes
Sourcefn max_segments(&self) -> Result<usize, Error>
fn max_segments(&self) -> Result<usize, Error>
Maximum number of segments that can be sent in a single batch
Sourcefn poll_send(
&self,
cx: &mut Context<'_>,
pkts: &[IoSlice<'_>],
hdr: PacketHeader,
) -> Poll<Result<usize, Error>>
fn poll_send( &self, cx: &mut Context<'_>, pkts: &[IoSlice<'_>], hdr: PacketHeader, ) -> Poll<Result<usize, Error>>
Poll for sending packets
Attempts to send multiple packets in a single operation. Return the number of packets sent,
Sourcefn poll_recv(
&self,
cx: &mut Context<'_>,
pkts: &mut [BytesMut],
hdrs: &mut [PacketHeader],
) -> Poll<Result<usize, Error>>
fn poll_recv( &self, cx: &mut Context<'_>, pkts: &mut [BytesMut], hdrs: &mut [PacketHeader], ) -> Poll<Result<usize, Error>>
Poll for receiving packets
Attempts to receive multiple packets in a single operation.
The number of packets received is limited by the smaller of
pkts.capacity()
and hdrs.len()
.
Sourcefn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
fn poll_close(&self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
Asynchronously destroy the QuicIO.
When it returns Poll::Ready
,
it means that the resource has been completely destroyed,
and the same BindUri
can be successfully bound again.
Even if this method is not called,
the implementation should ensure that QuicIO
does not
leak any resources when it is dropped.