Skip to content

Commit

Permalink
Implement {Recv,Send}WithFd for tokio::net::unix::{Read,Write}Half
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy authored and nagisa committed Jun 30, 2022
1 parent 0e13d3d commit d7e1bd2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ impl SendWithFd for tokio::net::UnixStream {
}
}

#[cfg(feature = "tokio")]
impl SendWithFd for tokio::net::unix::WriteHalf<'_> {
/// Send the bytes and the file descriptors as a stream.
///
/// Neither is guaranteed to be received by the other end in a single chunk and
/// may arrive entirely independently.
fn send_with_fd(&self, bytes: &[u8], fds: &[RawFd]) -> io::Result<usize> {
let unix_stream: &tokio::net::UnixStream = self.as_ref();
unix_stream.send_with_fd(bytes, fds)
}
}

impl SendWithFd for net::UnixDatagram {
/// Send the bytes and the file descriptors as a single packet.
///
Expand Down Expand Up @@ -238,6 +250,19 @@ impl RecvWithFd for tokio::net::UnixStream {
}
}

#[cfg(feature = "tokio")]
impl RecvWithFd for tokio::net::unix::ReadHalf<'_> {
/// Receive the bytes and the file descriptors from the stream.
///
/// It is not guaranteed that the received information will form a single coherent packet of
/// data. In other words, it is not required that this receives the bytes and file descriptors
/// that were sent with a single `send_with_fd` call by somebody else.
fn recv_with_fd(&self, bytes: &mut [u8], fds: &mut [RawFd]) -> io::Result<(usize, usize)> {
let unix_stream: &tokio::net::UnixStream = self.as_ref();
unix_stream.recv_with_fd(bytes, fds)
}
}

impl RecvWithFd for net::UnixDatagram {
/// Receive the bytes and the file descriptors as a single packet.
///
Expand Down

0 comments on commit d7e1bd2

Please sign in to comment.