pub struct UnixFd(/* private fields */);
Expand description
UnixFd is a wrapper around RawFd, to ensure that opened FDs are closed again, while still having the possibility of having multiple references to it.
“Ownership” as in responsibility of closing the FD works as follows:
- You can call take_raw_fd(). At this point UnixFd releases ownership. You are now responsible of closing the FD.
- You can call get_raw_fd(). This will not release ownership, UnixFd will still close it if no more references to it exist.
§UnixFds and messages
- When a UnixFd is marshalled rustbus will dup() the FD so that the message and the original UnixFd do not depend on each others lifetime. You are free to use or close the original one.
- When a UnixFd is unmarshalled rustbus will NOT dup() the FD. This means if you call take_raw_fd(), it is gone from the message too! If you do not want this, you have to call dup() and then get_raw_fd() or take_raw_fd()
Implementations§
Source§impl UnixFd
impl UnixFd
pub fn new(fd: i32) -> UnixFd
Sourcepub fn get_raw_fd(&self) -> Option<i32>
pub fn get_raw_fd(&self) -> Option<i32>
Gets a non-owning RawFd
. If None
is returned.
then this UnixFd has already been taken by somebody else
and is no longer valid.
Sourcepub fn take_raw_fd(self) -> Option<i32>
pub fn take_raw_fd(self) -> Option<i32>
Gets a owning RawFd
from the UnixFd.
Subsequent attempt to get the RawFd
from
other UnixFd
referencing the same file descriptor will
fail.
Trait Implementations§
Source§impl Marshal for UnixFd
impl Marshal for UnixFd
fn marshal(&self, ctx: &mut MarshalContext<'_, '_>) -> Result<(), Error>
fn marshal_as_variant( &self, ctx: &mut MarshalContext<'_, '_>, ) -> Result<(), Error>
Source§impl PartialEq for UnixFd
Allow for the comparison of UnixFd
even after the RawFd
has been taken, to see if they originally referred to the same thing.
impl PartialEq for UnixFd
Allow for the comparison of UnixFd
even after the RawFd
has been taken, to see if they originally referred to the same thing.
Source§impl Signature for UnixFd
impl Signature for UnixFd
fn signature() -> Type
fn alignment() -> usize
Source§fn sig_str(s_buf: &mut SignatureBuffer)
fn sig_str(s_buf: &mut SignatureBuffer)
Appends the signature of the type to the
SignatureBuffer
. Read moreimpl Eq for UnixFd
Auto Trait Implementations§
impl Freeze for UnixFd
impl RefUnwindSafe for UnixFd
impl Send for UnixFd
impl Sync for UnixFd
impl Unpin for UnixFd
impl UnwindSafe for UnixFd
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more