pub struct TcpListener { /* private fields */ }
Implementations§
Source§impl TcpListener
impl TcpListener
Sourcepub fn bind(addr: &SocketAddr) -> Result<TcpListener>
pub fn bind(addr: &SocketAddr) -> Result<TcpListener>
Convenience method to bind a new TCP listener to the specified address to receive new connections.
This function will take the following steps:
- Create a new TCP socket.
- Set the
SO_REUSEADDR
option on the socket. - Bind the socket to the specified address.
- Call
listen
on the socket to prepare it to receive new connections.
If fine-grained control over the binding and listening process for a
socket is desired then the net2::TcpBuilder
methods can be used in
combination with the TcpListener::from_listener
method to transfer
ownership into mio.
Sourcepub fn from_listener(
listener: TcpListener,
addr: &SocketAddr,
) -> Result<TcpListener>
pub fn from_listener( listener: TcpListener, addr: &SocketAddr, ) -> Result<TcpListener>
Creates a new TcpListener
from an instance of a
std::net::TcpListener
type.
This function will set the listener
provided into nonblocking mode on
Unix, and otherwise the stream will just be wrapped up in an mio stream
ready to accept new connections and become associated with an event
loop.
The address provided must be the address that the listener is bound to.
Sourcepub fn accept(&self) -> Result<Option<(TcpStream, SocketAddr)>>
pub fn accept(&self) -> Result<Option<(TcpStream, SocketAddr)>>
Accepts a new TcpStream
.
Returns a Ok(None)
when the socket WOULDBLOCK
, this means the stream
will be ready at a later point. If an accepted stream is returned, the
address of the peer is returned along with it
pub fn local_addr(&self) -> Result<SocketAddr>
pub fn try_clone(&self) -> Result<TcpListener>
pub fn take_socket_error(&self) -> Result<()>
Trait Implementations§
Source§impl AsRawFd for TcpListener
impl AsRawFd for TcpListener
Source§impl Debug for TcpListener
impl Debug for TcpListener
Source§impl FromRawFd for TcpListener
impl FromRawFd for TcpListener
Source§unsafe fn from_raw_fd(fd: RawFd) -> TcpListener
unsafe fn from_raw_fd(fd: RawFd) -> TcpListener
Self
from the given raw file
descriptor. Read more