pub struct TcpStream { /* private fields */ }
Expand description
A TCP stream between a local and a remote socket, akin to
std::net::TcpStream
All I/O operations provided by mtcp::TcpStream
are “blocking” by default,
but – unlike the std::net
implementation – proper timeout and
cancellation support is available. Each mtcp::TcpStream
is tied to
an mtcp::TcpManager
instance.
A new TCP stream is created by connect()
ing to a
remote host, or initialized from()
an existing
mtcp::TcpConnection
.
If the timeout
parameter was set to Some(Duration)
and if the I/O
operation does not complete before the specified timeout period
expires, then the pending I/O operation will fail as soon as possible with
an TcpError::TimedOut
error.
Function like Read::read()
and
Write::write()
, which do not have an
explicit timeout
parameter, implicitly use the timeouts that have been
set up via the
set_default_timeouts()
function.
Initially, these timeouts are disabled.
Implementations§
source§impl TcpStream
impl TcpStream
pub fn from(manager: &Rc<TcpManager>, connection: TcpConnection) -> Result<Self>
pub fn set_default_timeouts(
&mut self,
timeout_rd: Option<Duration>,
timeout_wr: Option<Duration>
)
pub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn connect(
manager: &Rc<TcpManager>,
addr: SocketAddr,
timeout: Option<Duration>
) -> Result<Self>
pub fn read_timeout(
&mut self,
buffer: &mut [u8],
timeout: Option<Duration>
) -> Result<usize>
pub fn read_all_timeout<F>(
&mut self,
buffer: &mut Vec<u8>,
timeout: Option<Duration>,
chunk_size: Option<NonZeroUsize>,
fn_complete: F
) -> Result<()>where
F: Fn(&[u8]) -> bool,
pub fn write_timeout(
&mut self,
buffer: &[u8],
timeout: Option<Duration>
) -> Result<usize>
pub fn write_all_timeout(
&mut self,
buffer: &[u8],
timeout: Option<Duration>
) -> Result<()>
Trait Implementations§
source§impl Read for TcpStream
impl Read for TcpStream
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl Write for TcpStream
impl Write for TcpStream
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)