pub struct Sender { /* private fields */ }
Expand description

Sending end of an Unix pipe.

See new for documentation, including examples.

Implementations

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

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.

Converts to this type from the input type.
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
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
Write a buffer into this writer, returning how many bytes were written. Read more
Like write, except that it writes from a slice of buffers. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Attempts to write an entire buffer into this writer. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Like write, except that it writes from a slice of buffers. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Attempts to write an entire buffer into this writer. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. 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.