Struct Sender

struct Sender { ... }

Sending end of an Unix pipe.

See new for documentation, including examples.

Implementations

impl Sender

fn set_nonblocking(self: &Self, nonblocking: bool) -> Result<()>

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

fn try_io<F, T>(self: &Self, f: F) -> Result<T>
where
    F: FnOnce() -> Result<T>

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::error::Error;
#
# fn main() -> Result<(), Box<dyn Error>> {
use std::io;
use std::os::fd::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);
# Ok(())
# }

impl AsFd for Sender

fn as_fd(self: &Self) -> BorrowedFd<'_>

impl AsRawFd for Sender

fn as_raw_fd(self: &Self) -> RawFd

impl Debug for Sender

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Freeze for Sender

impl From for Sender

fn from(stdin: ChildStdin) -> Sender

impl From for Sender

fn from(fd: OwnedFd) -> Self

impl FromRawFd for Sender

unsafe fn from_raw_fd(fd: RawFd) -> Sender

impl IntoRawFd for Sender

fn into_raw_fd(self: Self) -> RawFd

impl RefUnwindSafe for Sender

impl Send for Sender

impl Source for Sender

fn register(self: &mut Self, registry: &Registry, token: Token, interests: Interest) -> Result<()>
fn reregister(self: &mut Self, registry: &Registry, token: Token, interests: Interest) -> Result<()>
fn deregister(self: &mut Self, registry: &Registry) -> Result<()>

impl Sync for Sender

impl Unpin for Sender

impl UnsafeUnpin for Sender

impl UnwindSafe for Sender

impl Write for Sender

fn write(self: &mut Self, buf: &[u8]) -> Result<usize>
fn write_vectored(self: &mut Self, bufs: &[IoSlice<'_>]) -> Result<usize>
fn flush(self: &mut Self) -> Result<()>

impl<T> Any for Sender

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Sender

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Sender

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for Sender

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for Sender

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for Sender

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Sender

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>