pub struct Receiver { /* private fields */ }
This is supported on Unix and crate feature os-ext only.
Expand description

Receiving end of an Unix pipe.

See new for documentation, including examples.

Implementations

This is supported on crate feature os-poll only.

Set the Receiver into or out of non-blocking mode.

This is supported on crate feature os-poll only.

Execute an I/O operation ensuring that the socket receives more events if it hits a WouldBlock error.

Notes

This method is required to be called for all I/O operations to ensure the user will receive events once the socket is ready again after returning a WouldBlock error.

Examples
use std::io;
use std::os::unix::io::AsRawFd;
use mio::unix::pipe;

let (sender, receiver) = pipe::new()?;

// Wait until the sender is writable...

// Write to the sender using a direct libc call, of course the
// `io::Write` implementation would be easier to use.
let buf = b"hello";
let n = sender.try_io(|| {
    let buf_ptr = &buf as *const _ as *const _;
    let res = unsafe { libc::write(sender.as_raw_fd(), buf_ptr, buf.len()) };
    if res != -1 {
        Ok(res as usize)
    } else {
        // If EAGAIN or EWOULDBLOCK is set by libc::write, the closure
        // should return `WouldBlock` error.
        Err(io::Error::last_os_error())
    }
})?;
eprintln!("write {} bytes", n);

// Wait until the receiver is readable...

// Read from the receiver using a direct libc call, of course the
// `io::Read` implementation would be easier to use.
let mut buf = [0; 512];
let n = receiver.try_io(|| {
    let buf_ptr = &mut buf as *mut _ as *mut _;
    let res = unsafe { libc::read(receiver.as_raw_fd(), buf_ptr, buf.len()) };
    if res != -1 {
        Ok(res as usize)
    } else {
        // If EAGAIN or EWOULDBLOCK is set by libc::read, the closure
        // should return `WouldBlock` error.
        Err(io::Error::last_os_error())
    }
})?;
eprintln!("read {} bytes", n);

Trait Implementations

Extracts the raw file descriptor. Read more

Formats the value using the given formatter. Read more

Notes

The underlying pipe is not set to non-blocking.

Performs the conversion.

Notes

The underlying pipe is not set to non-blocking.

Performs the conversion.

Constructs a new instance of Self from the given raw file descriptor. Read more

Consumes this object, returning the raw underlying file descriptor. Read more

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Like read, except that it reads into a slice of buffers. Read more

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Read the exact number of bytes required to fill buf. Read more

🔬 This is a nightly-only experimental API. (read_buf)

Pull some bytes from this source into the specified buffer. Read more

🔬 This is a nightly-only experimental API. (read_buf)

Read the exact number of bytes required to fill buf. Read more

Creates a “by reference” adaptor for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Like read, except that it reads into a slice of buffers. Read more

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Read the exact number of bytes required to fill buf. Read more

🔬 This is a nightly-only experimental API. (read_buf)

Pull some bytes from this source into the specified buffer. Read more

🔬 This is a nightly-only experimental API. (read_buf)

Read the exact number of bytes required to fill buf. Read more

Creates a “by reference” adaptor for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Register self with the given Registry instance. Read more

Re-register self with the given Registry instance. Read more

Deregister self from the given Registry instance. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.