Struct async_net::unix::UnixListener
source · pub struct UnixListener { /* private fields */ }
Expand description
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§
source§impl UnixListener
impl UnixListener
sourcepub fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener>
pub fn bind<P: AsRef<Path>>(path: P) -> Result<UnixListener>
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?;
}
sourcepub async fn accept(&self) -> Result<(UnixStream, SocketAddr)>
pub async fn accept(&self) -> Result<(UnixStream, SocketAddr)>
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?;
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_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?;
}
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
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§
source§impl AsFd for UnixListener
impl AsFd for UnixListener
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
source§impl AsRawFd for UnixListener
impl AsRawFd for UnixListener
source§impl Clone for UnixListener
impl Clone for UnixListener
source§fn clone(&self) -> UnixListener
fn clone(&self) -> UnixListener
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for UnixListener
impl Debug for UnixListener
source§impl From<Async<UnixListener>> for UnixListener
impl From<Async<UnixListener>> for UnixListener
source§fn from(listener: Async<UnixListener>) -> UnixListener
fn from(listener: Async<UnixListener>) -> UnixListener
source§impl From<UnixListener> for Arc<Async<UnixListener>>
impl From<UnixListener> for Arc<Async<UnixListener>>
source§fn from(val: UnixListener) -> Self
fn from(val: UnixListener) -> Self
source§impl TryFrom<OwnedFd> for UnixListener
impl TryFrom<OwnedFd> for UnixListener
source§impl TryFrom<UnixListener> for UnixListener
impl TryFrom<UnixListener> for UnixListener
source§fn try_from(listener: UnixListener) -> Result<UnixListener>
fn try_from(listener: UnixListener) -> Result<UnixListener>
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> AsFilelike for Twhere
T: AsFd,
impl<T> AsFilelike for Twhere T: AsFd,
§fn as_filelike(&self) -> BorrowedFd<'_>
fn as_filelike(&self) -> BorrowedFd<'_>
§fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>where
Target: FilelikeViewType,
fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>where Target: FilelikeViewType,
&Target
. Read more§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
§impl<T> AsSocketlike for Twhere
T: AsFd,
impl<T> AsSocketlike for Twhere T: AsFd,
§fn as_socketlike(&self) -> BorrowedFd<'_>
fn as_socketlike(&self) -> BorrowedFd<'_>
§fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>where
Target: SocketlikeViewType,
fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>where Target: SocketlikeViewType,
&Target
. Read more