pub trait ScmSocket {
    fn socket_fd(&self) -> RawFd;

    fn send_with_fd<D: IntoIobuf>(&self, buf: &[D], fd: RawFd) -> Result<usize> { ... }
    fn send_with_fds<D: IntoIobuf>(
        &self,
        buf: &[D],
        fd: &[RawFd]
    ) -> Result<usize> { ... } fn recv_with_fd(&self, buf: &mut [u8]) -> Result<(usize, Option<File>)> { ... } fn recv_with_fds(
        &self,
        buf: &mut [u8],
        fds: &mut [RawFd]
    ) -> Result<(usize, usize)> { ... } }
Expand description

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

Required Methods§

Gets the file descriptor of this socket.

Provided Methods§

Sends the given data and file descriptor over the socket.

On success, returns the number of bytes sent.

Arguments
  • buf - A buffer of data to send on the socket.
  • fd - A file descriptors to be sent.

Sends the given data and file descriptors over the socket.

On success, returns the number of bytes sent.

Arguments
  • buf - A buffer of data to send on the socket.
  • fds - A list of file descriptors to be sent.
Examples found in repository?
src/util/sock_ctrl_msg.rs (line 237)
236
237
238
    fn send_with_fd<D: IntoIobuf>(&self, buf: &[D], fd: RawFd) -> Result<usize> {
        self.send_with_fds(buf, &[fd])
    }

Receives data and potentially a file descriptor from the socket.

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

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

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).

Arguments
  • buf - A buffer to receive data from the socket.
  • fds - A slice of RawFds to put the received file descriptors into. On success, the number of valid file descriptors is indicated by the second element of the returned tuple. The caller owns these file descriptors, but they will not be closed on drop like a File-like type would be. It is recommended that each valid file descriptor gets wrapped in a drop type that closes it after this returns.
Examples found in repository?
src/util/sock_ctrl_msg.rs (line 261)
259
260
261
262
263
264
265
266
267
268
269
270
    fn recv_with_fd(&self, buf: &mut [u8]) -> Result<(usize, Option<File>)> {
        let mut fd = [0];
        let (read_count, fd_count) = self.recv_with_fds(buf, &mut fd)?;
        let file = if fd_count == 0 {
            None
        } else {
            // Safe because the first fd from recv_with_fds is owned by us and valid because this
            // branch was taken.
            Some(unsafe { File::from_raw_fd(fd[0]) })
        };
        Ok((read_count, file))
    }

Implementations on Foreign Types§

Implementors§