pub struct UnixListener { /* private fields */ }
Expand description

A Unix server, listening for connections.

After creating a UnixListener by binding it to an address, it listens for incoming connections. These can be accepted by calling accept() or by awaiting items from the async stream of incoming connections.

Cloning a UnixListener creates another handle to the same socket. The socket will be closed when all handles to it are dropped.

Examples

use async_net::unix::UnixListener;
use futures_lite::prelude::*;

let listener = UnixListener::bind("/tmp/socket")?;
let mut incoming = listener.incoming();

while let Some(stream) = incoming.next().await {
    let mut stream = stream?;
    stream.write_all(b"hello").await?;
}

Implementations

Creates a new UnixListener bound to the given path.

Examples
use async_net::unix::UnixListener;
use futures_lite::prelude::*;

let listener = UnixListener::bind("/tmp/socket")?;
let mut incoming = listener.incoming();

while let Some(stream) = incoming.next().await {
    let mut stream = stream?;
    stream.write_all(b"hello").await?;
}

Accepts a new incoming connection.

Returns a TCP stream and the address it is connected to.

Examples
use async_net::unix::UnixListener;

let listener = UnixListener::bind("/tmp/socket")?;
let (stream, addr) = listener.accept().await?;

Returns a stream of incoming connections.

Iterating over this stream is equivalent to calling accept() in a loop. The stream of connections is infinite, i.e awaiting the next connection will never result in None.

Examples
use async_net::unix::UnixListener;
use futures_lite::prelude::*;

let listener = UnixListener::bind("/tmp/socket")?;
let mut incoming = listener.incoming();

while let Some(stream) = incoming.next().await {
    let mut stream = stream?;
    stream.write_all(b"hello").await?;
}

Returns the local address this listener is bound to.

Examples
use async_net::unix::UnixListener;

let listener = UnixListener::bind("/tmp/socket")?;
println!("Local address is {:?}", listener.local_addr()?);

Trait Implementations

Extracts the raw file descriptor. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.