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

A Unix domain socket server, listening for connections.

After creating a UnixListener by binding it to a socket address, it listens for incoming connections. These can be accepted by awaiting elements from the async stream of incoming connections.

The socket will be closed when the value is dropped.

This type is an async version of std::os::unix::net::UnixListener.

Examples

use async_std::os::unix::net::UnixListener;
use async_std::prelude::*;

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

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

Implementations

Creates a Unix datagram listener bound to the given path.

Examples
use async_std::os::unix::net::UnixListener;

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

Accepts a new incoming connection to this listener.

When a connection is established, the corresponding stream and address will be returned.

Examples
use async_std::os::unix::net::UnixListener;

let listener = UnixListener::bind("/tmp/socket").await?;
let (socket, 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_std::os::unix::net::UnixListener;
use async_std::prelude::*;

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

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

Returns the local socket address of this listener.

Examples
use async_std::os::unix::net::UnixListener;

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

Trait Implementations

Extracts the raw file descriptor. Read more

Formats the value using the given formatter. Read more

Converts a std::os::unix::net::UnixListener into its asynchronous equivalent.

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

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

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 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.