pub struct UdStream { /* private fields */ }Expand description
A Unix domain socket byte stream, obtained either from UdStreamListener or by connecting to an existing server.
Examples
Basic example:
use interprocess::os::unix::udsocket::UdStream;
use std::io::prelude::*;
let mut conn = UdStream::connect("/tmp/example1.sock")?;
conn.write_all(b"Hello from client!")?;
let mut string_buffer = String::new();
conn.read_to_string(&mut string_buffer)?;
println!("Server answered: {}", string_buffer);Implementations
sourceimpl UdStream
impl UdStream
sourcepub fn connect<'a>(path: impl ToUdSocketPath<'a>) -> Result<Self>
pub fn connect<'a>(path: impl ToUdSocketPath<'a>) -> Result<Self>
Connects to a Unix domain socket server at the specified path.
See ToUdSocketPath for an example of using various string types to specify socket paths.
System calls
socketconnect
sourcepub fn recv_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
pub fn recv_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
Receives bytes from the socket stream, making use of scatter input for the main data.
System calls
readv
sourcepub fn recv_ancillary<'a: 'b, 'b>(
&self,
buf: &mut [u8],
abuf: &'b mut AncillaryDataBuf<'a>
) -> Result<(usize, usize)>
pub fn recv_ancillary<'a: 'b, 'b>(
&self,
buf: &mut [u8],
abuf: &'b mut AncillaryDataBuf<'a>
) -> Result<(usize, usize)>
Receives both bytes and ancillary data from the socket stream.
The ancillary data buffer is automatically converted from the supplied value, if possible. For that reason, mutable slices of bytes (u8 values) can be passed directly.
System calls
recvmsg
sourcepub fn recv_ancillary_vectored<'a: 'b, 'b>(
&self,
bufs: &mut [IoSliceMut<'_>],
abuf: &'b mut AncillaryDataBuf<'a>
) -> Result<(usize, usize)>
pub fn recv_ancillary_vectored<'a: 'b, 'b>(
&self,
bufs: &mut [IoSliceMut<'_>],
abuf: &'b mut AncillaryDataBuf<'a>
) -> Result<(usize, usize)>
Receives bytes and ancillary data from the socket stream, making use of scatter input for the main data.
The ancillary data buffer is automatically converted from the supplied value, if possible. For that reason, mutable slices of bytes (u8 values) can be passed directly.
System calls
recvmsg
sourcepub fn send_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>
pub fn send_vectored(&self, bufs: &[IoSlice<'_>]) -> Result<usize>
Sends bytes into the socket stream, making use of gather output for the main data.
System calls
senv
sourcepub fn send_ancillary<'a>(
&self,
buf: &[u8],
ancillary_data: impl IntoIterator<Item = AncillaryData<'a>>
) -> Result<(usize, usize)>
pub fn send_ancillary<'a>(
&self,
buf: &[u8],
ancillary_data: impl IntoIterator<Item = AncillaryData<'a>>
) -> Result<(usize, usize)>
Sends bytes and ancillary data into the socket stream.
The ancillary data buffer is automatically converted from the supplied value, if possible. For that reason, slices and Vecs of AncillaryData can be passed directly.
System calls
sendmsg
sourcepub fn send_ancillary_vectored<'a>(
&self,
bufs: &[IoSlice<'_>],
ancillary_data: impl IntoIterator<Item = AncillaryData<'a>>
) -> Result<(usize, usize)>
pub fn send_ancillary_vectored<'a>(
&self,
bufs: &[IoSlice<'_>],
ancillary_data: impl IntoIterator<Item = AncillaryData<'a>>
) -> Result<(usize, usize)>
Sends bytes and ancillary data into the socket stream, making use of gather output for the main data.
The ancillary data buffer is automatically converted from the supplied value, if possible. For that reason, slices and Vecs of AncillaryData can be passed directly.
System calls
sendmsg
sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn shutdown(&self, how: Shutdown) -> Result<()>
Shuts down the read, write, or both halves of the stream. See Shutdown.
Attempting to call this method with the same how argument multiple times may return Ok(()) every time or it may return an error the second time it is called, depending on the platform. You must either avoid using the same value twice or ignore the error entirely.
sourcepub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>
Enables or disables the nonblocking mode for the stream. By default, it is disabled.
In nonblocking mode, calls to the recv… methods and the Read trait methods will never wait for at least one byte of data to become available; calls to send… methods and the Write trait methods will never wait for the other side to remove enough bytes from the buffer for the write operation to be performed. Those operations will instead return a WouldBlock error immediately, allowing the thread to perform other useful operations in the meantime.
sourcepub fn is_nonblocking(&self) -> Result<bool>
pub fn is_nonblocking(&self) -> Result<bool>
Checks whether the stream is currently in nonblocking mode or not.
sourcepub fn get_peer_credentials(&self) -> Result<ucred>
Available on Linux and (GNU or musl or target_env="musleabi" or target_env="musleabihf"), or Emscripten, or Redox, or Haiku only.
pub fn get_peer_credentials(&self) -> Result<ucred>
target_env="musleabi" or target_env="musleabihf"), or Emscripten, or Redox, or Haiku only.Fetches the credentials of the other end of the connection without using ancillary data. The returned structure contains the process identifier, user identifier and group identifier of the peer.
Trait Implementations
sourceimpl Read for UdStream
impl Read for UdStream
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
read, except that it reads into a slice of buffers. Read moresourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf. Read more1.0.0 · sourcefn 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 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moresourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)sourcefn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read moresourceimpl TryFrom<UdStream> for SyncUdStream
Available on crate feature tokio_support only.
impl TryFrom<UdStream> for SyncUdStream
tokio_support only.sourceimpl Write for UdStream
impl Write for UdStream
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
sourcefn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)