pub struct Listener<Socket>where
Socket: ListeningSocket,{ /* private fields */ }
Expand description
Listener that spawns peers for all accepted connections.
Implementations§
source§impl<Socket: ListeningSocket> Listener<Socket>
impl<Socket: ListeningSocket> Listener<Socket>
sourcepub fn new(listener: Socket, config: Socket::Config) -> Self
pub fn new(listener: Socket, config: Socket::Config) -> Self
Create a server on a listening socket.
The passed in config is used to create transports and peers for all accepted connections.
sourcepub async fn bind<'a, Address: 'a>(
address: Address,
config: Socket::Config
) -> Result<Self>where
Socket: Bind<'a, Address>,
pub async fn bind<'a, Address: 'a>(
address: Address,
config: Socket::Config
) -> Result<Self>where
Socket: Bind<'a, Address>,
Create a server with a new listening socket bound to the given address.
The type of address accepted depends on the listener.
For internet transports such as TCP, the address must implement tokio::net::ToSocketAddrs
.
For unix transports, the address must implement AsRef<std::path::Path>
.
This function is asynchronous because it may perform a DNS lookup for some address types.
sourcepub async fn run<F, R>(&mut self, task: F) -> Result<()>where
F: FnMut(PeerHandle<Socket::Body>, Socket::TransportInfo) -> R,
R: Future<Output = ()> + Send + 'static,
pub async fn run<F, R>(&mut self, task: F) -> Result<()>where
F: FnMut(PeerHandle<Socket::Body>, Socket::TransportInfo) -> R,
R: Future<Output = ()> + Send + 'static,
Run the server.
The server will accept connections in a loop and spawn a user task for each new peer.
sourcepub async fn accept(
&mut self
) -> Result<(PeerHandle<Socket::Body>, Socket::TransportInfo)>
pub async fn accept( &mut self ) -> Result<(PeerHandle<Socket::Body>, Socket::TransportInfo)>
Accept a connection and spawn a peer for it.
A Peer
is spawned for the new connection,
and a PeerHandle
is returned to allow interaction with the peer.