Struct holochain::prelude::kitsune_p2p::dependencies::kitsune_p2p_types::dependencies::lair_keystore_api::dependencies::tokio::net::UnixSocket
source · pub struct UnixSocket { /* private fields */ }
Expand description
A Unix socket that has not yet been converted to a UnixStream
, UnixDatagram
, or
UnixListener
.
UnixSocket
wraps an operating system socket and enables the caller to
configure the socket before establishing a connection or accepting
inbound connections. The caller is able to set socket option and explicitly
bind the socket with a socket address.
The underlying socket is closed when the UnixSocket
value is dropped.
UnixSocket
should only be used directly if the default configuration used
by UnixStream::connect
, UnixDatagram::bind
, and UnixListener::bind
does not meet the required use case.
Calling UnixStream::connect(path)
effectively performs the same function as:
use tokio::net::UnixSocket;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("bind_path");
let socket = UnixSocket::new_stream()?;
let stream = socket.connect(path).await?;
Ok(())
}
Calling UnixDatagram::bind(path)
effectively performs the same function as:
use tokio::net::UnixSocket;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("bind_path");
let socket = UnixSocket::new_datagram()?;
socket.bind(path)?;
let datagram = socket.datagram()?;
Ok(())
}
Calling UnixListener::bind(path)
effectively performs the same function as:
use tokio::net::UnixSocket;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("bind_path");
let socket = UnixSocket::new_stream()?;
socket.bind(path)?;
let listener = socket.listen(1024)?;
Ok(())
}
Setting socket options not explicitly provided by UnixSocket
may be done by
accessing the RawFd
/RawSocket
using AsRawFd
/AsRawSocket
and
setting the option with a crate like socket2
.
Implementations§
source§impl UnixSocket
impl UnixSocket
sourcepub fn new_datagram() -> Result<UnixSocket, Error>
pub fn new_datagram() -> Result<UnixSocket, Error>
Creates a new Unix datagram socket.
Calls socket(2)
with AF_UNIX
and SOCK_DGRAM
.
§Returns
On success, the newly created UnixSocket
is returned. If an error is
encountered, it is returned instead.
sourcepub fn new_stream() -> Result<UnixSocket, Error>
pub fn new_stream() -> Result<UnixSocket, Error>
Creates a new Unix stream socket.
Calls socket(2)
with AF_UNIX
and SOCK_STREAM
.
§Returns
On success, the newly created UnixSocket
is returned. If an error is
encountered, it is returned instead.
sourcepub fn bind(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub fn bind(&self, path: impl AsRef<Path>) -> Result<(), Error>
Binds the socket to the given address.
This calls the bind(2)
operating-system function.
sourcepub fn listen(self, backlog: u32) -> Result<UnixListener, Error>
pub fn listen(self, backlog: u32) -> Result<UnixListener, Error>
Converts the socket into a UnixListener
.
backlog
defines the maximum number of pending connections are queued
by the operating system at any given time. Connection are removed from
the queue with UnixListener::accept
. When the queue is full, the
operating-system will start rejecting connections.
Calling this function on a socket created by new_datagram
will return an error.
This calls the listen(2)
operating-system function, marking the socket
as a passive socket.
sourcepub async fn connect(self, path: impl AsRef<Path>) -> Result<UnixStream, Error>
pub async fn connect(self, path: impl AsRef<Path>) -> Result<UnixStream, Error>
Establishes a Unix connection with a peer at the specified socket address.
The UnixSocket
is consumed. Once the connection is established, a
connected UnixStream
is returned. If the connection fails, the
encountered error is returned.
Calling this function on a socket created by new_datagram
will return an error.
This calls the connect(2)
operating-system function.
sourcepub fn datagram(self) -> Result<UnixDatagram, Error>
pub fn datagram(self) -> Result<UnixDatagram, Error>
Converts the socket into a UnixDatagram
.
Calling this function on a socket created by new_stream
will return an error.
Trait Implementations§
source§impl AsFd for UnixSocket
impl AsFd for UnixSocket
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
source§impl AsRawFd for UnixSocket
impl AsRawFd for UnixSocket
source§impl Debug for UnixSocket
impl Debug for UnixSocket
source§impl FromRawFd for UnixSocket
impl FromRawFd for UnixSocket
source§unsafe fn from_raw_fd(fd: i32) -> UnixSocket
unsafe fn from_raw_fd(fd: i32) -> UnixSocket
Self
from the given raw file
descriptor. Read moresource§impl IntoRawFd for UnixSocket
impl IntoRawFd for UnixSocket
source§fn into_raw_fd(self) -> i32
fn into_raw_fd(self) -> i32
Auto Trait Implementations§
impl RefUnwindSafe for UnixSocket
impl Send for UnixSocket
impl Sync for UnixSocket
impl Unpin for UnixSocket
impl UnwindSafe for UnixSocket
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
source§impl<T> AsFilelike for Twhere
T: AsFd,
impl<T> AsFilelike for Twhere
T: AsFd,
source§fn as_filelike(&self) -> BorrowedFd<'_>
fn as_filelike(&self) -> BorrowedFd<'_>
source§fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>where
Target: FilelikeViewType,
fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>where
Target: FilelikeViewType,
&Target
. Read moresource§impl<T> AsRawFilelike for Twhere
T: AsRawFd,
impl<T> AsRawFilelike for Twhere
T: AsRawFd,
source§fn as_raw_filelike(&self) -> i32
fn as_raw_filelike(&self) -> i32
source§impl<T> AsRawSocketlike for Twhere
T: AsRawFd,
impl<T> AsRawSocketlike for Twhere
T: AsRawFd,
source§fn as_raw_socketlike(&self) -> i32
fn as_raw_socketlike(&self) -> i32
source§impl<T> AsSocketlike for Twhere
T: AsFd,
impl<T> AsSocketlike for Twhere
T: AsFd,
source§fn as_socketlike(&self) -> BorrowedFd<'_>
fn as_socketlike(&self) -> BorrowedFd<'_>
source§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> AsSource for Twhere
T: AsFd,
impl<T> AsSource for Twhere
T: AsFd,
source§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<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T> FromRawFilelike for Twhere
T: FromRawFd,
impl<T> FromRawFilelike for Twhere
T: FromRawFd,
source§unsafe fn from_raw_filelike(raw: i32) -> T
unsafe fn from_raw_filelike(raw: i32) -> T
Self
from the raw value. Read moresource§impl<T> FromRawSocketlike for Twhere
T: FromRawFd,
impl<T> FromRawSocketlike for Twhere
T: FromRawFd,
source§unsafe fn from_raw_socketlike(raw: i32) -> T
unsafe fn from_raw_socketlike(raw: i32) -> T
Self
from the raw value. Read moresource§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> 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> IntoRawFilelike for Twhere
T: IntoRawFd,
impl<T> IntoRawFilelike for Twhere
T: IntoRawFd,
source§fn into_raw_filelike(self) -> i32
fn into_raw_filelike(self) -> i32
source§impl<T> IntoRawSocketlike for Twhere
T: IntoRawFd,
impl<T> IntoRawSocketlike for Twhere
T: IntoRawFd,
source§fn into_raw_socketlike(self) -> i32
fn into_raw_socketlike(self) -> i32
source§impl<Stream> IsTerminal for Streamwhere
Stream: AsFd,
impl<Stream> IsTerminal for Streamwhere
Stream: AsFd,
source§fn is_terminal(&self) -> bool
fn is_terminal(&self) -> bool
source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.