pub struct SendAncillaryBuffer<'buf, 'slice, 'fd> {
buffer: &'buf mut [MaybeUninit<u8>],
length: usize,
_phantom: PhantomData<&'slice [BorrowedFd<'fd>]>,
}
Expand description
Buffer for sending ancillary messages with sendmsg
and
sendmsg_addr
.
Use the push
function to add messages to send.
Fields§
§buffer: &'buf mut [MaybeUninit<u8>]
Raw byte buffer for messages.
length: usize
The amount of the buffer that is used.
_phantom: PhantomData<&'slice [BorrowedFd<'fd>]>
Phantom data for lifetime of &'slice [BorrowedFd<'fd>]
.
Implementations§
Source§impl<'buf, 'slice, 'fd> SendAncillaryBuffer<'buf, 'slice, 'fd>
impl<'buf, 'slice, 'fd> SendAncillaryBuffer<'buf, 'slice, 'fd>
Sourcepub fn new(buffer: &'buf mut [MaybeUninit<u8>]) -> Self
pub fn new(buffer: &'buf mut [MaybeUninit<u8>]) -> Self
Create a new, empty SendAncillaryBuffer
from a raw byte buffer.
The buffer size may be computed with cmsg_space
, or it may be
zero for an empty buffer, however in that case, consider default()
instead, or even using send
instead of sendmsg
.
§Examples
Allocate a buffer for a single file descriptor:
let mut space = [MaybeUninit::uninit(); rustix::cmsg_space!(ScmRights(1))];
let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space);
Allocate a buffer for credentials:
let mut space = [MaybeUninit::uninit(); rustix::cmsg_space!(ScmCredentials(1))];
let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space);
Allocate a buffer for two file descriptors and credentials:
let mut space = [MaybeUninit::uninit(); rustix::cmsg_space!(ScmRights(2), ScmCredentials(1))];
let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space);
Sourcepub(crate) fn as_control_ptr(&mut self) -> *mut u8
pub(crate) fn as_control_ptr(&mut self) -> *mut u8
Returns a pointer to the message data.
Sourcepub(crate) fn control_len(&self) -> usize
pub(crate) fn control_len(&self) -> usize
Returns the length of the message data.
Sourcepub fn push(&mut self, msg: SendAncillaryMessage<'slice, 'fd>) -> bool
pub fn push(&mut self, msg: SendAncillaryMessage<'slice, 'fd>) -> bool
Add an ancillary message to the buffer.
Returns true
if the message was added successfully.
Trait Implementations§
Source§impl Default for SendAncillaryBuffer<'_, '_, '_>
impl Default for SendAncillaryBuffer<'_, '_, '_>
Source§impl<'slice, 'fd> Extend<SendAncillaryMessage<'slice, 'fd>> for SendAncillaryBuffer<'_, 'slice, 'fd>
impl<'slice, 'fd> Extend<SendAncillaryMessage<'slice, 'fd>> for SendAncillaryBuffer<'_, 'slice, 'fd>
Source§fn extend<T: IntoIterator<Item = SendAncillaryMessage<'slice, 'fd>>>(
&mut self,
iter: T,
)
fn extend<T: IntoIterator<Item = SendAncillaryMessage<'slice, 'fd>>>( &mut self, iter: T, )
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)