Struct safina_net::TcpStream[][src]

pub struct TcpStream { /* fields omitted */ }

Implementations

impl TcpStream[src]

pub fn new(std_stream: TcpStream) -> Result<Self, Error>[src]

Wraps std_stream so we can perform async operations on it.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::set_nonblocking.

pub async fn connect<A: ToSocketAddrs + Send + 'static>(
    addr: A
) -> Result<Self, Error>
[src]

Opens a TCP connection to addr.

Uses safina_executor::schedule_blocking to perform the blocking connect call. Panics if the caller is not running on an Executor.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::connect.

#[must_use]pub fn inner(&self) -> &TcpStream[src]

pub fn inner_mut(&mut self) -> &mut TcpStream[src]

#[must_use]pub fn into_inner(self) -> TcpStream[src]

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

Reads some bytes from the socket and places them in buf. Returns the number of bytes read.

This is an async version of std::io::Read::read.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::read.

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

Reads all bytes until the socket is shutdown for reading. Appends the bytes to buf.

This is an async version of std::io::Read::read_to_end.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::read.

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

Reads all bytes until the socket is shutdown for reading. Interprets the bytes as a single UTF-8 string and appends it to buf.

This is an async version of std::io::Read::read_to_string.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::read.

Returns ErrorKind::InvalidData if the bytes are not valid UTF-8.

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

Reads the exact number of bytes required to fill buf.

This is an async version of std::io::Read::read_exact.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::read.

pub async fn read_vectored(
    &mut self,
    bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
[src]

Reads bytes into bufs, filling each buffer in order. The final buffer written to may be partially filled.

Returns the total number of bytes read.

This is an async version of std::net::TcpStream::read_vectored.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::read_vectored.

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

Waits to receive some data on the socket, then copies it into buf.

Returns the number of bytes copied.

Repeated calls return the same data. Call read to remove data from the socket.

This is an async version of std::net::TcpStream::peek.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::peek.

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

Writes the bytes in buf to the socket. Returns the number of bytes written.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::write.

pub async fn flush(&mut self) -> Result<(), Error>[src]

Sends all buffered data that was previously written on this socket and waits for receipt confirmation by the remote machine.

Errors

Returns std::io::Error if the connection failed or the remote machine did not respond within a timeout period.

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

Writes all bytes in buf to the socket.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::write.

pub async fn write_vectored(
    &mut self,
    bufs: &[IoSlice<'_>]
) -> Result<usize, Error>
[src]

Writes data from a slice of buffers.

Takes data from each buffer in order. May partially read the last buffer read.

Returns the number of bytes written.

Errors

Returns any Err(std::io::Error) returned by std::net::TcpStream::write_vectored.

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.