[−][src]Struct async_std::os::unix::net::UnixListener
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?; }
Methods
impl UnixListener
[src]
pub async fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener>
[src]
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?;
pub async fn accept<'_>(&'_ self) -> Result<(UnixStream, SocketAddr)>
[src]
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?;
pub fn incoming(&self) -> Incoming
[src]
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?; }
pub fn local_addr(&self) -> Result<SocketAddr>
[src]
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
impl AsRawFd for UnixListener
[src]
impl FromRawFd for UnixListener
[src]
unsafe fn from_raw_fd(fd: RawFd) -> UnixListener
[src]
impl IntoRawFd for UnixListener
[src]
fn into_raw_fd(self) -> RawFd
[src]
impl From<UnixListener> for UnixListener
[src]
fn from(listener: UnixListener) -> UnixListener
[src]
Converts a std::os::unix::net::UnixListener
into its asynchronous equivalent.
impl Debug for UnixListener
[src]
Auto Trait Implementations
impl Send for UnixListener
impl Sync for UnixListener
impl Unpin for UnixListener
impl UnwindSafe for UnixListener
impl RefUnwindSafe for UnixListener
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,