Struct async_std::os::unix::net::UnixListener [−][src]
pub struct UnixListener { /* fields omitted */ }
Expand description
A Unix domain socket server, listening for connections.
After creating a UnixListener
by bind
ing 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
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