pub trait Stream {
    // Required methods
    fn poll(&self, mode: PollMode) -> Result<()>;
    fn read(
        &self,
        buf: &mut [u8],
        fd_storage: &mut Vec<RawFdContainer>
    ) -> Result<usize>;
    fn write(&self, buf: &[u8], fds: &mut Vec<RawFdContainer>) -> Result<usize>;

    // Provided method
    fn write_vectored(
        &self,
        bufs: &[IoSlice<'_>],
        fds: &mut Vec<RawFdContainer>
    ) -> Result<usize> { ... }
}
Expand description

A trait used to implement the raw communication with the X11 server.

None of the functions of this trait shall return std::io::ErrorKind::Interrupted. If a system call fails with this error, the implementation should try again.

Required Methods§

source

fn poll(&self, mode: PollMode) -> Result<()>

Waits for level-triggered read and/or write events on the stream.

This function does not return what caused it to complete the poll. Instead, callers should try to read or write and check for std::io::ErrorKind::WouldBlock.

This function is allowed to spuriously return even if the stream is neither readable nor writable. However, it shall not do it continuously, which would cause a 100% CPU usage.

Multithreading

If Self is Send + Sync and poll is used concurrently from more than one thread, all threads should wake when the stream becomes readable (when read is true) or writable (when write is true).

source

fn read( &self, buf: &mut [u8], fd_storage: &mut Vec<RawFdContainer> ) -> Result<usize>

Read some bytes and FDs from this reader without blocking, returning how many bytes were read.

This function works like std::io::Read::read, but also supports the reception of file descriptors. Any received file descriptors are appended to the given fd_storage. Whereas implementation of std::io::Read::read are allowed to block or not to block, this method shall never block and return ErrorKind::WouldBlock if needed.

This function does not guarantee that all file descriptors were sent together with the data with which they are received. However, file descriptors may not be received later than the data that was sent at the same time. Instead, file descriptors may only be received earlier.

Multithreading

If Self is Send + Sync and read is used concurrently from more than one thread:

  • Both the data and the file descriptors shall be read in order, but possibly interleaved across threads.
  • Neither the data nor the file descriptors shall be duplicated.
  • The returned value shall always be the actual number of bytes read into buf.
source

fn write(&self, buf: &[u8], fds: &mut Vec<RawFdContainer>) -> Result<usize>

Write a buffer and some FDs into this writer without blocking, returning how many bytes were written.

This function works like std::io::Write::write, but also supports sending file descriptors. The fds argument contains the file descriptors to send. The order of file descriptors is maintained. Whereas implementation of std::io::Write::write are allowed to block or not to block, this function must never block and return ErrorKind::WouldBlock if needed.

This function does not guarantee that all file descriptors are sent together with the data. Any file descriptors that were sent are removed from the beginning of the given Vec.

There is no guarantee that the given file descriptors are received together with the given data. File descriptors might be received earlier than their corresponding data. It is not allowed for file descriptors to be received later than the bytes that were sent at the same time.

Multithreading

If Self is Send + Sync and write is used concurrently from more than one thread:

  • Both the data and the file descriptors shall be written in order, but possibly interleaved across threads.
  • Neither the data nor the file descriptors shall be duplicated.
  • The returned value shall always be the actual number of bytes written from buf.

Provided Methods§

source

fn write_vectored( &self, bufs: &[IoSlice<'_>], fds: &mut Vec<RawFdContainer> ) -> Result<usize>

Like write, except that it writes from a slice of buffers. Like write, this method must never block.

This method must behave as a call to write with the buffers concatenated would.

The default implementation calls write with the first nonempty buffer provided.

Multithreading

Same as write.

Implementors§