pub struct TcpStream { /* private fields */ }
Implementations
sourceimpl TcpStream
impl TcpStream
sourcepub fn new(std_stream: TcpStream) -> Result<TcpStream, Error>
pub fn new(std_stream: TcpStream) -> Result<TcpStream, Error>
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
.
sourcepub async fn connect<A>(addr: A) -> Result<TcpStream, Error> where
A: 'static + ToSocketAddrs + Send,
pub async fn connect<A>(addr: A) -> Result<TcpStream, Error> where
A: 'static + ToSocketAddrs + Send,
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
.
pub fn inner(&self) -> &TcpStream
pub fn inner_mut(&mut self) -> &mut TcpStream
pub fn into_inner(self) -> TcpStream
sourcepub async fn read(&'_ mut self, buf: &'_ mut [u8]) -> Result<usize, Error>
pub async fn read(&'_ mut self, buf: &'_ mut [u8]) -> Result<usize, Error>
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
.
sourcepub async fn read_to_end(
&'_ mut self,
buf: &'_ mut Vec<u8, Global>
) -> Result<usize, Error>
pub async fn read_to_end(
&'_ mut self,
buf: &'_ mut Vec<u8, Global>
) -> Result<usize, Error>
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
.
sourcepub async fn read_to_string(
&'_ mut self,
buf: &'_ mut String
) -> Result<usize, Error>
pub async fn read_to_string(
&'_ mut self,
buf: &'_ mut String
) -> Result<usize, Error>
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.
sourcepub async fn read_exact(&'_ mut self, buf: &'_ mut [u8]) -> Result<(), Error>
pub async fn read_exact(&'_ mut self, buf: &'_ mut [u8]) -> Result<(), Error>
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
.
sourcepub async fn read_vectored(
&'_ mut self,
bufs: &'_ mut [IoSliceMut<'_>]
) -> Result<usize, Error>
pub async fn read_vectored(
&'_ mut self,
bufs: &'_ mut [IoSliceMut<'_>]
) -> Result<usize, Error>
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
.
sourcepub async fn peek(&'_ mut self, buf: &'_ mut [u8]) -> Result<usize, Error>
pub async fn peek(&'_ mut self, buf: &'_ mut [u8]) -> Result<usize, Error>
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
.
sourcepub async fn write(&'_ mut self, buf: &'_ [u8]) -> Result<usize, Error>
pub async fn write(&'_ mut self, buf: &'_ [u8]) -> Result<usize, Error>
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
.
sourcepub async fn flush(&'_ mut self) -> Result<(), Error>
pub async fn flush(&'_ mut self) -> Result<(), Error>
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.
sourcepub async fn write_all(&'_ mut self, buf: &'_ [u8]) -> Result<(), Error>
pub async fn write_all(&'_ mut self, buf: &'_ [u8]) -> Result<(), Error>
Writes all bytes in buf
to the socket.
Errors
Returns any
Err(std::io::Error)
returned by
std::net::TcpStream::write
.
sourcepub async fn write_vectored(
&'_ mut self,
bufs: &'_ [IoSlice<'_>]
) -> Result<usize, Error>
pub async fn write_vectored(
&'_ mut self,
bufs: &'_ [IoSlice<'_>]
) -> Result<usize, Error>
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
impl RefUnwindSafe for TcpStream
impl Send for TcpStream
impl Sync for TcpStream
impl Unpin for TcpStream
impl UnwindSafe for TcpStream
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more