pub struct ScmSocket<T: AsRawDescriptor> {
    pub(in sys) socket: T,
}
Expand description

Trait for file descriptors can send and receive socket control messages via sendmsg and recvmsg.

On Linux, this uses MSG_NOSIGNAL to avoid triggering signals. On MacOS, this sets the SO_NOSIGPIPE option on the file descriptor to avoid triggering signals.

Fields§

§socket: T

Implementations§

source§

impl<T: AsRawDescriptor> ScmSocket<T>

source

pub fn send_with_fds(&self, buf: &[u8], fds: &[RawFd]) -> Result<usize>

Sends the given data and file descriptors over the socket.

On success, returns the number of bytes sent.

The error is constructed via std::io::Error::last_os_error().

§Arguments
  • buf - A buffer of data to send on the socket.
  • fds - A list of file descriptors to be sent.
source

pub fn send_vectored_with_fds( &self, bufs: &[impl AsIobuf], fds: &[RawFd] ) -> Result<usize>

Sends the given data and file descriptors over the socket.

On success, returns the number of bytes sent.

The error is constructed via std::io::Error::last_os_error().

§Arguments
  • bufs - A slice of buffers of data to send on the socket.
  • fds - A list of file descriptors to be sent.
source

pub fn recv_with_fds( &self, buf: &mut [u8], max_descriptors: usize ) -> Result<(usize, Vec<SafeDescriptor>)>

Receives data and file descriptors from the socket.

On success, returns the number of bytes and file descriptors received as a tuple (bytes count, descriptors).

The error is constructed via std::io::Error::last_os_error().

§Arguments
  • buf - A buffer to store received data.
  • max_descriptors - Maximum number of file descriptors to receive.
source

pub fn recv_vectored_with_fds( &self, bufs: &mut [IoSliceMut<'_>], max_descriptors: usize ) -> Result<(usize, Vec<SafeDescriptor>)>

Receives data and file descriptors from the socket.

On success, returns the number of bytes and file descriptors received as a tuple (bytes count, files count).

The error is constructed via std::io::Error::last_os_error().

§Arguments
  • bufs - A slice of buffers to store received data.
  • max_descriptors - Maximum number of file descriptors to receive.
source

pub fn recv_with_file(&self, buf: &mut [u8]) -> Result<(usize, Option<File>)>

Receives data and potentially a file descriptor from the socket.

On success, returns the number of bytes and an optional file descriptor.

The error is constructed via std::io::Error::last_os_error().

§Arguments
  • buf - A buffer to receive data from the socket.vm
source

pub fn inner(&self) -> &T

Returns a reference to the wrapped instance.

source

pub fn inner_mut(&mut self) -> &mut T

Returns a mutable reference to the wrapped instance.

source

pub fn into_inner(self) -> T

Returns the inner object, destroying the ScmSocket.

Trait Implementations§

source§

impl<T: AsRawDescriptor> AsRawDescriptor for ScmSocket<T>

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more
source§

impl<'de, T> Deserialize<'de> for ScmSocket<T>
where T: Deserialize<'de> + AsRawDescriptor,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> Serialize for ScmSocket<T>

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<StreamChannel> for ScmSocket<StreamChannel>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(socket: StreamChannel) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<UnixDatagram> for ScmSocket<UnixDatagram>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(socket: UnixDatagram) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<UnixListener> for ScmSocket<UnixListener>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(socket: UnixListener) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<UnixSeqpacket> for ScmSocket<UnixSeqpacket>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(socket: UnixSeqpacket) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<UnixStream> for ScmSocket<UnixStream>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(socket: UnixStream) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for ScmSocket<T>
where T: RefUnwindSafe,

§

impl<T> Send for ScmSocket<T>
where T: Send,

§

impl<T> Sync for ScmSocket<T>
where T: Sync,

§

impl<T> Unpin for ScmSocket<T>
where T: Unpin,

§

impl<T> UnwindSafe for ScmSocket<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsRawDescriptors for T
where T: AsRawDescriptor,

source§

fn as_raw_descriptors(&self) -> Vec<i32>

Returns the underlying raw descriptors. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,