pub struct UnixConnection { /* private fields */ }local only.Expand description
A connection on a Unix domain socket, with the same limits, deadlines,
and close behaviour as TcpConnection.
let mut conn = net_io::UnixConnection::connect("/run/myapp/control.sock")?;
conn.send_all(b"status\n")?;Implementations§
Source§impl UnixConnection
impl UnixConnection
Sourcepub fn connect<P: AsRef<Path>>(path: P) -> Result<UnixConnection, NetError>
pub fn connect<P: AsRef<Path>>(path: P) -> Result<UnixConnection, NetError>
Connects to the socket at path; waits up to 10 s when its backlog is full.
§Errors
NotFound (no socket, or nobody listening), PermissionDenied,
TimedOut { kind: Connect }, PathTooLong, InvalidConfig { field: "path" }, Os.
Sourcepub fn info(&self) -> &ConnectionInfo
pub fn info(&self) -> &ConnectionInfo
What net-io knows about this connection.
Sourcepub fn id(&self) -> ConnectionId
pub fn id(&self) -> ConnectionId
The connection’s id.
Sourcepub fn kill_handle(&self) -> KillHandle
pub fn kill_handle(&self) -> KillHandle
A handle other threads can use to abort this connection.
Sourcepub fn set_limits(&mut self, limits: Limits)
pub fn set_limits(&mut self, limits: Limits)
Replaces the limits from the next operation on.
Sourcepub fn set_exchange_deadline(&mut self, at: Option<Instant>)
pub fn set_exchange_deadline(&mut self, at: Option<Instant>)
The deadline for the current exchange (None clears it).
Sourcepub fn peer_credentials(&self) -> Result<PeerCredentials, NetError>
pub fn peer_credentials(&self) -> Result<PeerCredentials, NetError>
The peer’s process, user, and group, as read when the connection was made.
§Errors
Unsupported when the OS did not report them.
Sourcepub fn send_descriptors(
&mut self,
body: &[u8],
descriptors: &[BorrowedFd<'_>],
) -> Result<(), NetError>
pub fn send_descriptors( &mut self, body: &[u8], descriptors: &[BorrowedFd<'_>], ) -> Result<(), NetError>
Sends all of body (not empty) with up to 64 descriptors attached to its
first byte (SCM_RIGHTS). The descriptors stay open here; the receiver
gets its own copies.
§Errors
InvalidConfig (empty body, more than 64 descriptors), as UnixConnection::send.
Sourcepub fn recv_descriptors(
&mut self,
body: &mut [u8],
into: &mut Descriptors,
) -> Result<usize, NetError>
pub fn recv_descriptors( &mut self, body: &mut [u8], into: &mut Descriptors, ) -> Result<usize, NetError>
One receive that also takes descriptors sent with the bytes, into into
(descriptors it still holds are closed first). Ok(0) means the peer
closed its side.
§Errors
Handoff(Truncated) when the control message was cut short: every
descriptor of it was closed and the connection fails, since the bytes
can no longer be framed; as UnixConnection::recv.
Trait Implementations§
Source§impl AsFd for UnixConnection
impl AsFd for UnixConnection
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Source§impl Debug for UnixConnection
impl Debug for UnixConnection
Source§impl Read for UnixConnection
impl Read for UnixConnection
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl Write for UnixConnection
impl Write for UnixConnection
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)