Struct UnixListener
pub struct UnixListener { /* private fields */ }net only.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§
§impl UnixListener
impl UnixListener
pub async fn bind(path: impl AsRef<Path>) -> Result<UnixListener, Error>
pub async fn bind(path: impl AsRef<Path>) -> Result<UnixListener, Error>
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.
pub async fn bind_addr(addr: &SockAddr) -> Result<UnixListener, Error>
pub async fn bind_addr(addr: &SockAddr) -> Result<UnixListener, Error>
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.
pub async fn bind_with_options(
addr: &SockAddr,
opts: &SocketOpts,
) -> Result<UnixListener, Error>
pub async fn bind_with_options( addr: &SockAddr, opts: &SocketOpts, ) -> Result<UnixListener, Error>
Creates a new UnixListener with [SockAddr] and SocketOpts,
which will be bound to the specified file path. The file path cannot
yet exist, and will be cleaned up upon dropping UnixListener.
pub fn from_std(stream: UnixListener) -> Result<UnixListener, Error>
Available on Unix only.
pub fn from_std(stream: UnixListener) -> Result<UnixListener, Error>
Creates new UnixListener from a std::os::unix::net::UnixListener.
pub fn close(self) -> impl Future<Output = Result<(), Error>>
pub fn close(self) -> impl Future<Output = Result<(), Error>>
Close the socket. If the returned future is dropped before polling, the socket won’t be closed.
pub async fn accept(&self) -> Result<(UnixStream, SockAddr), Error>
pub async fn accept(&self) -> Result<(UnixStream, SockAddr), Error>
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.
pub async fn accept_with_options(
&self,
options: &SocketOpts,
) -> Result<(UnixStream, SockAddr), Error>
pub async fn accept_with_options( &self, options: &SocketOpts, ) -> Result<(UnixStream, SockAddr), Error>
Accepts a new incoming connection from this listener, and sets options.
This function will yield once a new Unix domain socket connection
is established. When established, the corresponding UnixStream and
will be returned.
pub fn local_addr(&self) -> Result<SockAddr, Error>
pub fn local_addr(&self) -> Result<SockAddr, Error>
Returns the local address that this listener is bound to.
Trait Implementations§
§impl AsFd for UnixListener
Available on Unix only.
impl AsFd for UnixListener
§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
§impl AsRawFd for UnixListener
impl AsRawFd for UnixListener
§impl Clone for UnixListener
impl Clone for UnixListener
§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 more§impl Debug for UnixListener
impl Debug for UnixListener
§impl FromRawFd for UnixListener
Available on Unix only.
impl FromRawFd for UnixListener
§unsafe fn from_raw_fd(fd: i32) -> UnixListener
unsafe fn from_raw_fd(fd: i32) -> UnixListener
Self from the given raw file
descriptor. Read moreSharedFd.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§
§impl<T> AsSource for Twhere
T: AsFd,
impl<T> AsSource for Twhere
T: AsFd,
§fn source(&self) -> BorrowedFd<'_>
fn source(&self) -> BorrowedFd<'_>
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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