[][src]Struct mio_st::net::TcpStream

pub struct TcpStream { /* fields omitted */ }

A non-blocking TCP stream between a local socket and a remote socket.

This works much like the TcpStream in the standard library, but the Read and Write implementation don't block and instead return a WouldBlock error.

Deregistering

TcpStream will deregister itself when dropped.

Examples

use mio_st::event::{Events, EventedId};
use mio_st::net::TcpStream;
use mio_st::poll::{Poller, PollOption};

let address = "127.0.0.1:8000".parse()?;
let mut stream = TcpStream::connect(address)?;

let mut poller = Poller::new()?;
let mut events = Events::new();

// Register the socket with `Poller`.
poller.register(&mut stream, EventedId(0), TcpStream::INTERESTS, PollOption::Edge)?;

poller.poll(&mut events, None)?;

// The socket might be ready at this point.

Methods

impl TcpStream[src]

pub const INTERESTS: Interests[src]

The interests to use when registering to receive both readable and writable events.

pub fn connect(address: SocketAddr) -> Result<TcpStream>[src]

Create a new TCP stream and issue a non-blocking connect to the specified address.

pub fn peer_addr(&mut self) -> Result<SocketAddr>[src]

Returns the socket address of the remote peer of this TCP connection.

pub fn local_addr(&mut self) -> Result<SocketAddr>[src]

Returns the socket address of the local half of this TCP connection.

pub fn set_ttl(&mut self, ttl: u32) -> Result<()>[src]

Sets the value for the IP_TTL option on this socket.

pub fn ttl(&mut self) -> Result<u32>[src]

Gets the value of the IP_TTL option for this socket.

pub fn set_nodelay(&mut self, nodelay: bool) -> Result<()>[src]

Sets the value of the TCP_NODELAY option on this socket.

pub fn nodelay(&mut self) -> Result<bool>[src]

Gets the value of the TCP_NODELAY option on this socket.

pub fn peek(&mut self, buf: &mut [u8]) -> Result<usize>[src]

Receives data on the socket from the remote address to which it is connected, without removing that data from the queue. On success, returns the number of bytes peeked.

Successive calls return the same data. This is accomplished by passing MSG_PEEK as a flag to the underlying recv system call.

pub fn shutdown(&mut self, how: Shutdown) -> Result<()>[src]

Shuts down the read, write, or both halves of this connection.

This function will cause all pending and future I/O on the specified portions to return immediately with an appropriate value (see the documentation of Shutdown).

pub fn take_error(&mut self) -> Result<Option<Error>>[src]

Get the value of the SO_ERROR option on this socket.

This will retrieve the stored error in the underlying socket, clearing the field in the process. This can be useful for checking errors between calls.

Trait Implementations

impl Evented for TcpStream[src]

impl Debug for TcpStream[src]

impl Read for TcpStream[src]

fn read_vectored(&mut self, bufs: &mut [IoVecMut]) -> Result<usize, Error>[src]

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

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

unsafe fn initializer(&self) -> Initializer[src]

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

Determines if this Reader can work with buffers of uninitialized memory. Read more

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
[src]

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

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

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

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
[src]

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

fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

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

fn bytes(self) -> Bytes<Self>
1.0.0
[src]

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

fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0
[src]

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

fn take(self, limit: u64) -> Take<Self>
1.0.0
[src]

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

impl Write for TcpStream[src]

fn write_vectored(&mut self, bufs: &[IoVec]) -> Result<usize, Error>[src]

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

Like write, except that it writes from a slice of buffers. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
[src]

Attempts to write an entire buffer into this writer. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Write. Read more

impl FromRawFd for TcpStream[src]

Important traits for TcpStream
unsafe fn from_raw_fd(fd: RawFd) -> TcpStream[src]

The caller must ensure that the stream is in non-blocking mode when using this function.

impl AsRawFd for TcpStream[src]

impl IntoRawFd for TcpStream[src]

Auto Trait Implementations

impl Send for TcpStream

impl Sync for TcpStream

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]