pub struct UnixListener { /* private fields */ }
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§
source§impl UnixListener
impl UnixListener
sourcepub async fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener>
pub async fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener>
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?;
sourcepub async fn accept(&self) -> Result<(UnixStream, SocketAddr)>
pub async fn accept(&self) -> Result<(UnixStream, SocketAddr)>
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?;
sourcepub fn incoming(&self) -> Incoming<'_>
pub fn incoming(&self) -> Incoming<'_>
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?;
}
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
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§
source§impl AsRawFd for UnixListener
impl AsRawFd for UnixListener
source§impl Debug for UnixListener
impl Debug for UnixListener
source§impl From<UnixListener> for UnixListener
impl From<UnixListener> for UnixListener
source§fn from(listener: StdUnixListener) -> UnixListener
fn from(listener: StdUnixListener) -> UnixListener
Converts a std::os::unix::net::UnixListener
into its asynchronous equivalent.
source§impl FromRawFd for UnixListener
impl FromRawFd for UnixListener
source§unsafe fn from_raw_fd(fd: RawFd) -> UnixListener
unsafe fn from_raw_fd(fd: RawFd) -> UnixListener
Self
from the given raw file
descriptor. Read moresource§impl IntoRawFd for UnixListener
impl IntoRawFd for UnixListener
source§fn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
source§impl TryFrom<UnixListener> for UnixListener
impl TryFrom<UnixListener> for UnixListener
source§fn try_from(listener: UnixListener) -> Result<StdUnixListener>
fn try_from(listener: UnixListener) -> Result<StdUnixListener>
Converts a UnixListener
into its synchronous equivalent.
Auto Trait Implementations§
impl RefUnwindSafe for UnixListener
impl Send for UnixListener
impl Sync for UnixListener
impl Unpin for UnixListener
impl UnwindSafe for UnixListener
Blanket Implementations§
§impl<T> AsRawFilelike for Twhere
T: AsRawFd,
impl<T> AsRawFilelike for Twhere
T: AsRawFd,
§fn as_raw_filelike(&self) -> i32
fn as_raw_filelike(&self) -> i32
§impl<T> AsRawSocketlike for Twhere
T: AsRawFd,
impl<T> AsRawSocketlike for Twhere
T: AsRawFd,
§fn as_raw_socketlike(&self) -> i32
fn as_raw_socketlike(&self) -> i32
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FromRawFilelike for Twhere
T: FromRawFd,
impl<T> FromRawFilelike for Twhere
T: FromRawFd,
§unsafe fn from_raw_filelike(raw: i32) -> T
unsafe fn from_raw_filelike(raw: i32) -> T
Self
from the raw value. Read more§impl<T> FromRawSocketlike for Twhere
T: FromRawFd,
impl<T> FromRawSocketlike for Twhere
T: FromRawFd,
§unsafe fn from_raw_socketlike(raw: i32) -> T
unsafe fn from_raw_socketlike(raw: i32) -> T
Self
from the raw value. Read more