[−][src]Struct async_net::unix::UnixListener
A Unix server, listening for connections.
After creating a UnixListener
by bind
ing 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
impl UnixListener
[src]
pub fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener>
[src]
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?; }
pub async fn accept<'_>(&'_ self) -> Result<(UnixStream, SocketAddr)>
[src]
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?;
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_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?; }
pub fn local_addr(&self) -> Result<SocketAddr>
[src]
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
impl AsRawFd for UnixListener
[src]
impl Clone for UnixListener
[src]
fn clone(&self) -> UnixListener
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for UnixListener
[src]
impl From<Async<UnixListener>> for UnixListener
[src]
fn from(listener: Async<UnixListener>) -> UnixListener
[src]
impl Into<Arc<Async<UnixListener>>> for UnixListener
[src]
fn into(self) -> Arc<Async<UnixListener>>
[src]
impl TryFrom<UnixListener> for UnixListener
[src]
type Error = Error
The type returned in the event of a conversion error.
fn try_from(listener: UnixListener) -> Result<UnixListener>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut 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>,