Struct TcpListener
struct TcpListener { ... }
A structure representing a socket server
Examples
# use Error;
#
Implementations
impl TcpListener
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_REUSEADDRoption on the socket on Unix. - Bind the socket to the specified address.
- Calls
listenon the socket to prepare it to receive new connections.
fn from_std(listener: TcpListener) -> TcpListenerCreates a new
TcpListenerfrom a standardnet::TcpListener.This function is intended to be used to wrap a TCP listener from the standard library in the Mio equivalent. The conversion assumes nothing about the underlying listener; ; it is left up to the user to set it in non-blocking mode.
fn accept(self: &Self) -> Result<(TcpStream, SocketAddr)>Accepts a new
TcpStream.This may return an
Err(e)wheree.kind()isio::ErrorKind::WouldBlock. This means a stream may be ready at a later point and one should wait for an event before callingacceptagain.If an accepted stream is returned, the remote address of the peer is returned along with it.
fn local_addr(self: &Self) -> Result<SocketAddr>Returns the local socket address of this listener.
fn set_ttl(self: &Self, ttl: u32) -> Result<()>Sets the value for the
IP_TTLoption on this socket.This value sets the time-to-live field that is used in every packet sent from this socket.
fn ttl(self: &Self) -> Result<u32>Gets the value of the
IP_TTLoption for this socket.For more information about this option, see
set_ttl.fn take_error(self: &Self) -> Result<Option<Error>>Get the value of the
SO_ERRORoption on this socket.This will retrieve the stored error in the underlying socket, clearing the field in the process. This can be useful for checking errors between calls.
impl AsFd for TcpListener
fn as_fd(self: &Self) -> BorrowedFd<'_>
impl AsRawFd for TcpListener
fn as_raw_fd(self: &Self) -> RawFd
impl Debug for TcpListener
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Freeze for TcpListener
impl From for TcpListener
fn from(fd: OwnedFd) -> SelfConverts a
RawFdto aTcpListener.Notes
The caller is responsible for ensuring that the socket is in non-blocking mode.
impl FromRawFd for TcpListener
unsafe fn from_raw_fd(fd: RawFd) -> TcpListenerConverts a
RawFdto aTcpListener.Notes
The caller is responsible for ensuring that the socket is in non-blocking mode.
impl IntoRawFd for TcpListener
fn into_raw_fd(self: Self) -> RawFd
impl RefUnwindSafe for TcpListener
impl Send for TcpListener
impl Source for TcpListener
fn register(self: &mut Self, registry: &Registry, token: Token, interests: Interest) -> Result<()>fn reregister(self: &mut Self, registry: &Registry, token: Token, interests: Interest) -> Result<()>fn deregister(self: &mut Self, registry: &Registry) -> Result<()>
impl Sync for TcpListener
impl Unpin for TcpListener
impl UnsafeUnpin for TcpListener
impl UnwindSafe for TcpListener
impl<T> Any for TcpListener
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for TcpListener
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for TcpListener
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for TcpListener
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for TcpListener
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for TcpListener
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for TcpListener
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>