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§
Source§impl 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
socket
connect
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 Vec
s 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 Vec
s 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§
Source§impl FromRawFd for UdStream
impl FromRawFd for UdStream
Source§unsafe fn from_raw_fd(fd: c_int) -> Self
unsafe fn from_raw_fd(fd: c_int) -> Self
Self
from the given raw file
descriptor. Read moreSource§impl IntoRawFd for UdStream
impl IntoRawFd for UdStream
Source§fn into_raw_fd(self) -> c_int
fn into_raw_fd(self) -> c_int
Source§impl Read for UdStream
impl Read for UdStream
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn 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 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<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn 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 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl Write for UdStream
impl Write for UdStream
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
)