Struct TcpListener

Source
pub struct TcpListener { /* private fields */ }

Implementations§

Source§

impl TcpListener

Source

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:

  1. Create a new TCP socket.
  2. Set the SO_REUSEADDR option on the socket.
  3. Bind the socket to the specified address.
  4. 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.

Source

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.

Source

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

Source

pub fn local_addr(&self) -> Result<SocketAddr>

Source

pub fn try_clone(&self) -> Result<TcpListener>

Source

pub fn take_socket_error(&self) -> Result<()>

Trait Implementations§

Source§

impl AsRawFd for TcpListener

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for TcpListener

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromRawFd for TcpListener

Source§

unsafe fn from_raw_fd(fd: RawFd) -> TcpListener

Constructs a new instance of Self from the given raw file descriptor. Read more
Source§

impl TryAccept for TcpListener

Source§

impl Evented for TcpListener

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.