pub struct UnixSocket { /* private fields */ }Expand description
A Unix domain socket, of streams or of datagrams, to bind before it connects, listens or sends.
use nuclei::net::UnixSocket;
let dir = std::env::temp_dir().join(format!("nuclei-doc-unix-socket-{}", std::process::id()));
let _ = std::fs::remove_file(&dir);
let listener = UnixSocket::new_stream()?;
listener.bind(&dir)?;
let listener = listener.listen(16)?;
let client = UnixSocket::new_stream()?.connect(&dir).await?;
let (_server, _) = listener.accept().await?;
client.send(b"hi").await?;
std::fs::remove_file(&dir)?;Implementations§
Source§impl UnixSocket
impl UnixSocket
Sourcepub fn new_stream() -> Result<UnixSocket>
pub fn new_stream() -> Result<UnixSocket>
Sourcepub fn new_datagram() -> Result<UnixSocket>
pub fn new_datagram() -> Result<UnixSocket>
Sourcepub fn bind(&self, path: impl AsRef<Path>) -> Result<()>
pub fn bind(&self, path: impl AsRef<Path>) -> Result<()>
Binds the socket to path, which must not exist yet.
§Errors
As bind(2): the path exists, or is too long.
Sourcepub fn listen(self, backlog: u32) -> Result<UnixListener>
pub fn listen(self, backlog: u32) -> Result<UnixListener>
Makes a socket of streams a listener, with room for backlog
connections not accepted yet.
§Errors
On a socket of datagrams, and as listen(2).
Sourcepub async fn connect(self, path: impl AsRef<Path>) -> Result<UnixStream>
pub async fn connect(self, path: impl AsRef<Path>) -> Result<UnixStream>
Connects a socket of streams to the listener at path.
§Errors
On a socket of datagrams, and as connect(2).
Sourcepub fn datagram(self) -> Result<UnixDatagram>
pub fn datagram(self) -> Result<UnixDatagram>
Trait Implementations§
Source§impl AsFd for UnixSocket
impl AsFd for UnixSocket
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Borrows the file descriptor. Read more
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: RawFd) -> UnixSocket
unsafe fn from_raw_fd(fd: RawFd) -> UnixSocket
§Safety
fd is an open, non-blocking Unix domain socket the caller owns and
hands over.
Source§impl IntoRawFd for UnixSocket
impl IntoRawFd for UnixSocket
Source§fn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor. Read more
Auto Trait Implementations§
impl Freeze for UnixSocket
impl RefUnwindSafe for UnixSocket
impl Send for UnixSocket
impl Sync for UnixSocket
impl Unpin for UnixSocket
impl UnsafeUnpin for UnixSocket
impl UnwindSafe for UnixSocket
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
Mutably borrows from an owned value. Read more