# [−] [src] Struct mio::net::TcpListener

    pub struct TcpListener { /* fields omitted */ }

A structure representing a socket server

# Examples

    use mio::{Events, Interest, Poll, Token};
    use mio::net::TcpListener;
    use std::time::Duration;

    let mut listener = TcpListener::bind("127.0.0.1:34255".parse()?)?;

    let mut poll = Poll::new()?;
    let mut events = Events::with_capacity(128);

    // Register the socket with `Poll`
    poll.registry().register(&mut listener, Token(0), Interest::READABLE)?;

    poll.poll(&mut events, Some(Duration::from_millis(100)))?;

    // There may be a socket ready to be accepted

## Implementations

### `impl TcpListener` [src]

#### `pub fn bind(addr: SocketAddr) -> Result<TcpListener>` [src]

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 on Unix.
3. Bind the socket to the specified address.
4. Calls `listen` on the socket to prepare it to receive new connections.

#### `pub fn from_std(listener: TcpListener) -> TcpListener` [src]

Creates a new `TcpListener` from a standard `net::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.

#### `pub fn accept(&self) -> Result<(TcpStream, SocketAddr)>` [src]

Accepts a new `TcpStream`.

This may return an `Err(e)` where `e.kind()` is `io::ErrorKind::WouldBlock`. This means a stream may be ready at a later point and one should wait for an event before calling `accept` again.

If an accepted stream is returned, the remote address of the peer is returned along with it.

#### `pub fn local_addr(&self) -> Result<SocketAddr>` [src]

Returns the local socket address of this listener.

#### `pub fn set_ttl(&self, ttl: u32) -> Result<()>` [src]

Sets the value for the `IP_TTL` option on this socket.

This value sets the time-to-live field that is used in every packet sent from this socket.

#### `pub fn ttl(&self) -> Result<u32>` [src]

Gets the value of the `IP_TTL` option for this socket.

For more information about this option, see `set_ttl`.

#### `pub fn take_error(&self) -> Result<Option<Error>>` [src]

Get the value of the `SO_ERROR` option 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.

## Trait Implementations

### `impl AsRawFd for TcpListener` [src]

#### `fn as_raw_fd(&self) -> RawFd` [src]

Extracts the raw file descriptor. Read more

### `impl Debug for TcpListener` [src]

#### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` [src]

Formats the value using the given formatter. Read more

### `impl FromRawFd for TcpListener` [src]

#### `unsafe fn from_raw_fd(fd: RawFd) -> TcpListener` [src]

Converts a `RawFd` to a `TcpListener`.

# Notes

The caller is responsible for ensuring that the socket is in non-blocking mode.

### `impl IntoRawFd for TcpListener` [src]

#### `fn into_raw_fd(self) -> RawFd` [src]

Consumes this object, returning the raw underlying file descriptor. Read more

### `impl Source for TcpListener` [src]

#### `fn register(
&mut self,
registry: &Registry,
token: Token,
interests: Interest
) -> Result<()>` [src]

Register `self` with the given `Registry` instance. Read more

#### `fn reregister(
&mut self,
registry: &Registry,
token: Token,
interests: Interest
) -> Result<()>` [src]

Re-register `self` with the given `Registry` instance. Read more

#### `fn deregister(&mut self, registry: &Registry) -> Result<()>` [src]

Deregister `self` from the given `Registry` instance. Read more

## Auto Trait Implementations

### `impl RefUnwindSafe for TcpListener`

### `impl Send for TcpListener`

### `impl Sync for TcpListener`

### `impl Unpin for TcpListener`

### `impl UnwindSafe for TcpListener`

## Blanket Implementations

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `pub fn type_id(&self) -> TypeId` [src]

Gets the `TypeId` of `self`. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow(&self) -> &T` [src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow_mut(&mut self) -> &mut T` [src]

Mutably borrows from an owned value. Read more

### `impl<T> From<T> for T` [src]

#### `pub fn from(t: T) -> T` [src]

Performs the conversion.

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `pub fn into(self) -> U` [src]

Performs the conversion.

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>` [src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

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

The type returned in the event of a conversion error.

#### `pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>` [src]

Performs the conversion.