Trait zbus::Socket

source ·
pub trait Socket: Debug + Send + Sync {
    // Required methods
    fn poll_recvmsg(
        &mut self,
        cx: &mut Context<'_>,
        buf: &mut [u8]
    ) -> Poll<Result<(usize, Vec<OwnedFd>)>>;
    fn poll_sendmsg(
        &mut self,
        cx: &mut Context<'_>,
        buffer: &[u8],
        fds: &[RawFd]
    ) -> Poll<Result<usize>>;
    fn close(&self) -> Result<()>;

    // Provided methods
    fn can_pass_unix_fd(&self) -> bool { ... }
    fn peer_pid(&self) -> Result<Option<u32>> { ... }
    fn uid(&self) -> Result<Option<u32>> { ... }
}
Expand description

Trait representing some transport layer over which the DBus protocol can be used

The crate provides implementations for async_io and tokio’s UnixStream wrappers if you enable the corresponding crate features (async_io is enabled by default).

You can implement it manually to integrate with other runtimes or other dbus transports. Feel free to submit pull requests to add support for more runtimes to zbus itself so rust’s orphan rules don’t force the use of a wrapper struct (and to avoid duplicating the work across many projects).

Required Methods§

source

fn poll_recvmsg( &mut self, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<(usize, Vec<OwnedFd>)>>

Attempt to receive a message from the socket.

On success, returns the number of bytes read as well as a Vec containing any associated file descriptors.

source

fn poll_sendmsg( &mut self, cx: &mut Context<'_>, buffer: &[u8], fds: &[RawFd] ) -> Poll<Result<usize>>

Attempt to send a message on the socket

On success, return the number of bytes written. There may be a partial write, in which case the caller is responsible of sending the remaining data by calling this method again until everything is written or it returns an error of kind WouldBlock.

If at least one byte has been written, then all the provided file descriptors will have been sent as well, and should not be provided again in subsequent calls.

If the underlying transport does not support transmitting file descriptors, this will return Err(ErrorKind::InvalidInput).

source

fn close(&self) -> Result<()>

Close the socket.

After this call, it is valid for all reading and writing operations to fail.

Provided Methods§

source

fn can_pass_unix_fd(&self) -> bool

Supports passing file descriptors.

source

fn peer_pid(&self) -> Result<Option<u32>>

Return the peer PID.

source

fn uid(&self) -> Result<Option<u32>>

Return the User ID, if any.

Trait Implementations§

source§

impl Socket for Box<dyn Socket>

source§

fn can_pass_unix_fd(&self) -> bool

Supports passing file descriptors.
source§

fn poll_recvmsg( &mut self, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<(usize, Vec<OwnedFd>)>>

Attempt to receive a message from the socket. Read more
source§

fn poll_sendmsg( &mut self, cx: &mut Context<'_>, buffer: &[u8], fds: &[RawFd] ) -> Poll<Result<usize>>

Attempt to send a message on the socket Read more
source§

fn close(&self) -> Result<()>

Close the socket. Read more
source§

fn peer_pid(&self) -> Result<Option<u32>>

Return the peer PID.
source§

fn uid(&self) -> Result<Option<u32>>

Return the User ID, if any.

Implementations on Foreign Types§

source§

impl Socket for Box<dyn Socket>

source§

fn can_pass_unix_fd(&self) -> bool

source§

fn poll_recvmsg( &mut self, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<(usize, Vec<OwnedFd>)>>

source§

fn poll_sendmsg( &mut self, cx: &mut Context<'_>, buffer: &[u8], fds: &[RawFd] ) -> Poll<Result<usize>>

source§

fn close(&self) -> Result<()>

source§

fn peer_pid(&self) -> Result<Option<u32>>

source§

fn uid(&self) -> Result<Option<u32>>

source§

impl Socket for VsockStream

source§

fn can_pass_unix_fd(&self) -> bool

source§

fn poll_recvmsg( &mut self, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<(usize, Vec<OwnedFd>)>>

source§

fn poll_sendmsg( &mut self, cx: &mut Context<'_>, buf: &[u8], fds: &[RawFd] ) -> Poll<Result<usize>>

source§

fn close(&self) -> Result<()>

source§

impl Socket for TcpStream

source§

fn can_pass_unix_fd(&self) -> bool

source§

fn poll_recvmsg( &mut self, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<(usize, Vec<OwnedFd>)>>

source§

fn poll_sendmsg( &mut self, cx: &mut Context<'_>, buf: &[u8], fds: &[RawFd] ) -> Poll<Result<usize>>

source§

fn close(&self) -> Result<()>

source§

impl Socket for UnixStream

source§

fn poll_recvmsg( &mut self, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<(usize, Vec<OwnedFd>)>>

source§

fn poll_sendmsg( &mut self, cx: &mut Context<'_>, buffer: &[u8], fds: &[RawFd] ) -> Poll<Result<usize>>

source§

fn close(&self) -> Result<()>

source§

fn peer_pid(&self) -> Result<Option<u32>>

source§

fn uid(&self) -> Result<Option<u32>>

Implementors§