Struct mio::net::UnixStream [−][src]
pub struct UnixStream { /* fields omitted */ }
Expand description
A non-blocking Unix stream socket.
Implementations
Connects to the socket named by path
.
pub fn from_std(stream: UnixStream) -> UnixStreamⓘNotable traits for UnixStreamimpl Write for UnixStreamimpl<'a> Write for &'a UnixStreamimpl Read for UnixStreamimpl<'a> Read for &'a UnixStream
pub fn from_std(stream: UnixStream) -> UnixStreamⓘNotable traits for UnixStreamimpl Write for UnixStreamimpl<'a> Write for &'a UnixStreamimpl Read for UnixStreamimpl<'a> Read for &'a UnixStream
impl Write for UnixStreamimpl<'a> Write for &'a UnixStreamimpl Read for UnixStreamimpl<'a> Read for &'a UnixStream
Creates a new UnixStream
from a standard net::UnixStream
.
This function is intended to be used to wrap a Unix stream from the standard library in the Mio equivalent. The conversion assumes nothing about the underlying stream; it is left up to the user to set it in non-blocking mode.
Note
The Unix stream here will not have connect
called on it, so it
should already be connected via some other means (be it manually, or
the standard library).
Creates an unnamed pair of connected sockets.
Returns two UnixStream
s which are connected to each other.
Returns the socket address of the local half of this connection.
Returns the socket address of the remote half of this connection.
Returns the value of the SO_ERROR
option.
Shuts down the read, write, or both halves of this connection.
This function will cause all pending and future I/O calls on the
specified portions to immediately return with an appropriate value
(see the documentation of Shutdown
).
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::net::UnixStream;
let (stream1, stream2) = UnixStream::pair()?;
// Wait until the stream is writable...
// Write to the stream using a direct libc call, of course the
// `io::Write` implementation would be easier to use.
let buf = b"hello";
let n = stream1.try_io(|| {
let buf_ptr = &buf as *const _ as *const _;
let res = unsafe { libc::send(stream1.as_raw_fd(), buf_ptr, buf.len(), 0) };
if res != -1 {
Ok(res as usize)
} else {
// If EAGAIN or EWOULDBLOCK is set by libc::send, the closure
// should return `WouldBlock` error.
Err(io::Error::last_os_error())
}
})?;
eprintln!("write {} bytes", n);
// Wait until the stream is readable...
// Read from the stream using a direct libc call, of course the
// `io::Read` implementation would be easier to use.
let mut buf = [0; 512];
let n = stream2.try_io(|| {
let buf_ptr = &mut buf as *mut _ as *mut _;
let res = unsafe { libc::recv(stream2.as_raw_fd(), buf_ptr, buf.len(), 0) };
if res != -1 {
Ok(res as usize)
} else {
// If EAGAIN or EWOULDBLOCK is set by libc::recv, the closure
// should return `WouldBlock` error.
Err(io::Error::last_os_error())
}
})?;
eprintln!("read {} bytes", n);
Trait Implementations
unsafe fn from_raw_fd(fd: RawFd) -> UnixStreamⓘNotable traits for UnixStreamimpl Write for UnixStreamimpl<'a> Write for &'a UnixStreamimpl Read for UnixStreamimpl<'a> Read for &'a UnixStream
unsafe fn from_raw_fd(fd: RawFd) -> UnixStreamⓘNotable traits for UnixStreamimpl Write for UnixStreamimpl<'a> Write for &'a UnixStreamimpl Read for UnixStreamimpl<'a> Read for &'a UnixStream
impl Write for UnixStreamimpl<'a> Write for &'a UnixStreamimpl Read for UnixStreamimpl<'a> Read for &'a UnixStream
Converts a RawFd
to a UnixStream
.
Notes
The caller is responsible for ensuring that the socket is in non-blocking mode.
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
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
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
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
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