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§
Source§impl UnixListener
impl UnixListener
Sourcepub 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. See UnixListener::bind_addr for more details.
Sourcepub 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.
To configure the socket before binding, you can use the UnixSocket
type.
Sourcepub 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.
See TcpStream::close for more details.
Sourcepub 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
the remote peer’s address will be returned.
Sourcepub async fn accept_with(
&self,
sock: UnixSocket,
) -> Result<(UnixStream, SockAddr), Error>
Available on Windows only.
pub async fn accept_with( &self, sock: UnixSocket, ) -> Result<(UnixStream, SockAddr), Error>
Accepts a new incoming connection from this listener using the provided socket.
Sourcepub fn incoming(&self) -> UnixIncoming<'_>
pub fn incoming(&self) -> UnixIncoming<'_>
Returns a stream of incoming connections to this listener.
Sourcepub 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§
Source§impl AsRawSocket for UnixListener
Available on Windows only.
impl AsRawSocket for UnixListener
Source§fn as_raw_socket(&self) -> u64
fn as_raw_socket(&self) -> u64
Source§impl AsSocket for UnixListener
Available on Windows only.
impl AsSocket for UnixListener
Source§fn as_socket(&self) -> BorrowedSocket<'_>
fn as_socket(&self) -> BorrowedSocket<'_>
Source§impl Clone for UnixListener
impl Clone for UnixListener
Source§fn clone(&self) -> UnixListener
fn clone(&self) -> UnixListener
1.0.0 (const: unstable) · 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: u64) -> UnixListener
unsafe fn from_raw_socket(sock: u64) -> UnixListener
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 UnsafeUnpin for UnixListener
impl UnwindSafe for UnixListener
Blanket Implementations§
§impl<T> AsFd for Twhere
T: AsSocket,
impl<T> AsFd for Twhere
T: AsSocket,
§fn as_fd(&self) -> BorrowedSocket<'_>
fn as_fd(&self) -> BorrowedSocket<'_>
as_fd function for Winsock, where an Fd is a Socket.§impl<T> AsRawFd for Twhere
T: AsRawSocket,
impl<T> AsRawFd for Twhere
T: AsRawSocket,
§impl<T> AsRawSocketlike for Twhere
T: AsRawSocket,
impl<T> AsRawSocketlike for Twhere
T: AsRawSocket,
§fn as_raw_socketlike(&self) -> u64
fn as_raw_socketlike(&self) -> u64
§impl<T> AsRawSocketlike for Twhere
T: AsRawSocket,
impl<T> AsRawSocketlike for Twhere
T: AsRawSocket,
§fn as_raw_socketlike(&self) -> u64
fn as_raw_socketlike(&self) -> u64
§impl<T> AsSocketlike for Twhere
T: AsSocket,
impl<T> AsSocketlike for Twhere
T: AsSocket,
§fn as_socketlike(&self) -> BorrowedSocket<'_>
fn as_socketlike(&self) -> BorrowedSocket<'_>
§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§impl<T> AsSocketlike for Twhere
T: AsSocket,
impl<T> AsSocketlike for Twhere
T: AsSocket,
§fn as_socketlike(&self) -> BorrowedSocket<'_>
fn as_socketlike(&self) -> BorrowedSocket<'_>
§fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>where
Target: SocketlikeViewType,
fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>where
Target: SocketlikeViewType,
&Target. Read moreSource§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> FromRawFd for Twhere
T: FromRawSocket,
impl<T> FromRawFd for Twhere
T: FromRawSocket,
§unsafe fn from_raw_fd(raw_fd: u64) -> T
unsafe fn from_raw_fd(raw_fd: u64) -> T
from_raw_fd for use with Winsock API. Read more§impl<T> FromRawSocketlike for Twhere
T: FromRawSocket,
impl<T> FromRawSocketlike for Twhere
T: FromRawSocket,
§unsafe fn from_raw_socketlike(raw: u64) -> T
unsafe fn from_raw_socketlike(raw: u64) -> T
Self from the raw value.§impl<T> FromRawSocketlike for Twhere
T: FromRawSocket,
impl<T> FromRawSocketlike for Twhere
T: FromRawSocket,
§unsafe fn from_raw_socketlike(raw: u64) -> T
unsafe fn from_raw_socketlike(raw: u64) -> T
Self from the raw value.§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