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§

source

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.

source

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.

source

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.

source

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.

source

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.

source

fn new_if_watcher() -> Result<Self::IfWatcher>

Create a new if_watch watcher that reports IfEvents for network interface changes.

source

fn poll_if_event( watcher: &mut Self::IfWatcher, cx: &mut Context<'_> ) -> Poll<Result<IfEvent>>

Poll for an address change event.

Implementors§

source§

impl Provider for libp2p_quic::async_std::Provider

Available on crate feature async-std only.
§

type IfWatcher = IfWatcher<SmolSocket>

source§

impl Provider for libp2p_quic::tokio::Provider

Available on crate feature tokio only.
§

type IfWatcher = IfWatcher<TokioSocket>