pub struct UnixListener { /* private fields */ }
Expand description
A Unix socket server, listening for connections.
You can accept a new connection by using the UnixListener::accept
method.
§Examples
use compio_io::{AsyncReadExt, AsyncWriteExt};
use compio_net::{UnixListener, UnixStream};
use tempfile::tempdir;
let dir = tempdir().unwrap();
let sock_file = dir.path().join("unix-server.sock");
let listener = UnixListener::bind(&sock_file).await.unwrap();
let (mut tx, (mut rx, _)) =
futures_util::try_join!(UnixStream::connect(&sock_file), listener.accept()).unwrap();
tx.write_all("test").await.0.unwrap();
let (_, buf) = rx.read_exact(Vec::with_capacity(4)).await.unwrap();
assert_eq!(buf, b"test");
Implementations§
source§impl UnixListener
impl UnixListener
sourcepub async fn bind(path: impl AsRef<Path>) -> Result<Self>
pub async fn bind(path: impl AsRef<Path>) -> Result<Self>
Creates a new UnixListener
, which will be bound to the specified
file path. The file path cannot yet exist, and will be cleaned up
upon dropping UnixListener
sourcepub async fn bind_addr(addr: &SockAddr) -> Result<Self>
pub async fn bind_addr(addr: &SockAddr) -> Result<Self>
Creates a new UnixListener
with SockAddr
, which will be bound to
the specified file path. The file path cannot yet exist, and will be
cleaned up upon dropping UnixListener
sourcepub fn close(self) -> impl Future<Output = Result<()>>
pub fn close(self) -> impl Future<Output = Result<()>>
Close the socket. If the returned future is dropped before polling, the socket won’t be closed.
sourcepub async fn accept(&self) -> Result<(UnixStream, SockAddr)>
pub async fn accept(&self) -> Result<(UnixStream, SockAddr)>
Accepts a new incoming connection from this listener.
This function will yield once a new Unix domain socket connection
is established. When established, the corresponding UnixStream
and
will be returned.
sourcepub fn local_addr(&self) -> Result<SockAddr>
pub fn local_addr(&self) -> Result<SockAddr>
Returns the local address that this listener is bound to.
Trait Implementations§
source§impl AsRawSocket for UnixListener
Available on Windows only.
impl AsRawSocket for UnixListener
source§fn as_raw_socket(&self) -> RawSocket
fn as_raw_socket(&self) -> RawSocket
source§impl Clone for UnixListener
impl Clone for UnixListener
source§fn clone(&self) -> UnixListener
fn clone(&self) -> UnixListener
1.6.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 FromRawSocket for UnixListener
Available on Windows only.
impl FromRawSocket for UnixListener
source§unsafe fn from_raw_socket(sock: RawSocket) -> Self
unsafe fn from_raw_socket(sock: RawSocket) -> Self
SharedFd
.Auto Trait Implementations§
impl Freeze for UnixListener
impl RefUnwindSafe for UnixListener
impl Send for UnixListener
impl Sync for UnixListener
impl Unpin for UnixListener
impl UnwindSafe for UnixListener
Blanket Implementations§
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more