pub struct TcpReader<'a> { /* private fields */ }
Expand description
The reader half of a TCP socket.
Implementations§
Source§impl<'a> TcpReader<'a>
impl<'a> TcpReader<'a>
Sourcepub async fn wait_read_ready(&self)
pub async fn wait_read_ready(&self)
Wait until the socket becomes readable.
A socket becomes readable when the receive half of the full-duplex connection is open
(see may_recv()
), and there is some pending data in the receive buffer.
This is the equivalent of read, without buffering any data.
Sourcepub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Read data from the socket.
Returns how many bytes were read, or an error. If no data is available, it waits until there is at least one byte available.
§Note
A return value of Ok(0) means that we have read all data and the remote side has closed our receive half of the socket. The remote can no longer send bytes.
The send half of the socket is still open. If you want to reconnect using
the socket you split this reader off the send half needs to be closed using
abort()
.
Sourcepub async fn read_with<F, R>(&mut self, f: F) -> Result<R, Error>
pub async fn read_with<F, R>(&mut self, f: F) -> Result<R, Error>
Call f
with the largest contiguous slice of octets in the receive buffer,
and dequeue the amount of elements returned by f
.
If no data is available, it waits until there is at least one byte available.
Sourcepub fn recv_capacity(&self) -> usize
pub fn recv_capacity(&self) -> usize
Return the maximum number of bytes inside the transmit buffer.
Sourcepub fn recv_queue(&self) -> usize
pub fn recv_queue(&self) -> usize
Return the amount of octets queued in the receive buffer. This value can be larger than
the slice read by the next recv
or peek
call because it includes all queued octets,
and not only the octets that may be returned as a contiguous slice.
Trait Implementations§
Source§impl<'d> Read for TcpReader<'d>
impl<'d> Read for TcpReader<'d>
Source§async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§async fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf
. Read more