pub struct TcpListener { /* private fields */ }
Expand description
A simulated TCP socket server, listening for connections.
All methods must be called from a host within a Turmoil simulation.
Implementations§
Source§impl TcpListener
impl TcpListener
Sourcepub async fn bind<A: ToSocketAddrs>(addr: A) -> Result<TcpListener>
pub async fn bind<A: ToSocketAddrs>(addr: A) -> Result<TcpListener>
Creates a new TcpListener, which will be bound to the specified address.
The returned listener is ready for accepting connections.
Binding with a port number of 0 will request that the OS assigns a port
to this listener. The port allocated can be queried via the local_addr
method.
Only 0.0.0.0
, ::
, or localhost are currently supported.
Sourcepub async fn accept(&self) -> Result<(TcpStream, SocketAddr)>
pub async fn accept(&self) -> Result<(TcpStream, SocketAddr)>
Accepts a new incoming connection from this listener.
This function will yield once a new TCP connection is established. When
established, the corresponding TcpStream
and the remote peer’s
address will be returned.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address that this listener is bound to.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TcpListener
impl RefUnwindSafe for TcpListener
impl Send for TcpListener
impl Sync for TcpListener
impl Unpin for TcpListener
impl UnwindSafe for TcpListener
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more