Struct mio::unix::pipe::Receiver [−][src]
pub struct Receiver { /* fields omitted */ }
Expand description
Receiving end of an Unix pipe.
See new
for documentation, including examples.
Implementations
Set the Receiver
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
Notes
The underlying pipe is not set to non-blocking.
Notes
The underlying pipe is not set to non-blocking.
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
can_vector
)Determines if this Read
er 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
read_buf
)Pull some bytes from this source into the specified buffer. Read more
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
Creates an adapter which will chain this stream with another. 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
can_vector
)Determines if this Read
er 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
read_buf
)Pull some bytes from this source into the specified buffer. Read more
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
Creates an adapter which will chain this stream with another. Read more