Trait libp2p_quic::Provider
source · pub trait Provider: Unpin + Send + Sized + 'static {
type IfWatcher: Unpin + Send;
// Required methods
fn from_socket(socket: UdpSocket) -> Result<Self>;
fn poll_recv_from(
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(Vec<u8>, SocketAddr)>>;
fn start_send(&mut self, data: Vec<u8>, addr: SocketAddr);
fn poll_send_flush(
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>;
fn spawn(future: impl Future<Output = ()> + Send + 'static);
fn new_if_watcher() -> Result<Self::IfWatcher>;
fn poll_if_event(
watcher: &mut Self::IfWatcher,
cx: &mut Context<'_>
) -> Poll<Result<IfEvent>>;
}
Expand description
Provider for non-blocking receiving and sending on a std::net::UdpSocket
and spawning tasks.
Required Associated Types§
Required Methods§
sourcefn from_socket(socket: UdpSocket) -> Result<Self>
fn from_socket(socket: UdpSocket) -> Result<Self>
Create a new providing that is wrapping the socket.
Note: The socket must be set to non-blocking.
sourcefn poll_recv_from(
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(Vec<u8>, SocketAddr)>>
fn poll_recv_from( &mut self, cx: &mut Context<'_> ) -> Poll<Result<(Vec<u8>, SocketAddr)>>
Receive a single packet.
Returns the message and the address the message came from.
sourcefn start_send(&mut self, data: Vec<u8>, addr: SocketAddr)
fn start_send(&mut self, data: Vec<u8>, addr: SocketAddr)
Set sending a packet on the socket.
Since only one packet can be sent at a time, this may only be called if a preceding
call to Provider::poll_send_flush
returned Poll::Ready
.
sourcefn poll_send_flush(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
fn poll_send_flush(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
Flush a packet send in Provider::start_send
.
If Poll::Ready
is returned the socket is ready for sending a new packet.
sourcefn spawn(future: impl Future<Output = ()> + Send + 'static)
fn spawn(future: impl Future<Output = ()> + Send + 'static)
Run the given future in the background until it ends.
This is used to spawn the task that is driving the endpoint.