[−][src]Struct stakker_mio::TcpStreamBuf
Type to aid with managing a mio::net::TcpStream
along with MioPoll
First create the stream and add it to MioPoll
, then pass the
resulting MioSource
to TcpStreamBuf::init
, which allows
this struct to manage the buffering.
Fields
out: Vec<u8>
Output buffer. Append data here, and then call
TcpStreamBuf::flush
when ready to send. If the stream is
receiving backpressure from the remote end then you'll see
data here building up.
out_eof: bool
Output EOF flag. When this is set to true
and the out
buffer fully empties in a TcpStreamBuf::flush
call, the
outgoing half of the stream will be shut down, which signals
end-of-file. If any data is added to out
after this point
it will give an error from flush
.
inp: Vec<u8>
Input buffer. To receive data, read data from offset rd
up
to offset wr
, updating rd
offset as you go. Call
TcpStreamBuf::read
to pull more data into the buffer,
which will update both rd
and wr
offsets (dropping data
before rd
). To apply backpressure to the remote end, use
stakker::idle!
for the read()
call.
rd: usize
Offset for reading in input buffer
wr: usize
Offset for writing in input buffer
Implementations
impl TcpStreamBuf
[src]
pub fn new() -> Self
[src]
Create a new empty TcpStreamBuf, without any stream currently associated
pub fn init(&mut self, stream: MioSource<TcpStream>)
[src]
After adding a stream to the MioPoll instance with
MioPoll::add
, store the MioSource
here to handle the
buffering. TcpStreamBuf
takes care of deregistering the
stream on drop. The caller should probably call
TcpStreamBuf::flush
and TcpStreamBuf::read
soon after
this call.
pub fn deinit(&mut self)
[src]
Discard the current stream if there is one, deregistering it
from the MioPoll
instance.
pub fn flush(&mut self) -> Result<()>
[src]
Flush as much data as possible out to the stream
pub fn read(&mut self, max: usize) -> ReadStatus
[src]
Read more data and append it to the data currently in the
inp
buffer. This is non-blocking. Bytes before the rd
offset might be dropped from the buffer, and rd
might be
moved. No more than max
bytes are read, which allows
regulating the data input rate if that is required. If you
need to apply backpressure when under load, call this method
from a stakker::idle!
handler. This must be called
repeatedly until it returns ReadStatus::WouldBlock
in order
to get another read notification from mio
.
Trait Implementations
impl Default for TcpStreamBuf
[src]
fn default() -> TcpStreamBuf
[src]
Auto Trait Implementations
impl !RefUnwindSafe for TcpStreamBuf
impl !Send for TcpStreamBuf
impl !Sync for TcpStreamBuf
impl Unpin for TcpStreamBuf
impl !UnwindSafe for TcpStreamBuf
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Any for T where
T: Any,
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,