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.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 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§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