pub struct Listener(/* private fields */);Expand description
TCP listener that accepts connections through the current reactor.
Created by tcp_listener. The listener is bound to the thread that
created it. Dropping it deregisters the socket from the reactor and closes
it.
Implementations§
Source§impl Listener
impl Listener
Sourcepub async fn accept(&mut self) -> Result<(TcpStream, SocketAddr), Error>
pub async fn accept(&mut self) -> Result<(TcpStream, SocketAddr), Error>
Accepts a new incoming connection.
Returns the connected stream and the address of the peer. The stream
may be in blocking or non-blocking mode depending on the platform,
from_tcp_stream switches it to the mode the reactor needs.
Dropping the returned future before it completes does not lose a connection, the next call returns it.
Sourcepub fn poll_accept(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(TcpStream, SocketAddr), Error>>
pub fn poll_accept( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(TcpStream, SocketAddr), Error>>
Polls for a new incoming connection.
Same as accept. On Poll::Pending, the waker of
the most recent call is woken when a connection may be accepted. A
listener that is not polled again keeps an accepted connection for
the next call.
Sourcepub fn local_addr(&self) -> Result<SocketAddr, Error>
pub fn local_addr(&self) -> Result<SocketAddr, Error>
Returns the local address the listener is bound to.