[][src]Struct stakker_mio::TcpStreamBuf

pub struct TcpStreamBuf {
    pub out: Vec<u8>,
    pub out_eof: bool,
    pub inp: Vec<u8>,
    pub rd: usize,
    pub wr: usize,
    // some fields omitted
}

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]

Auto Trait Implementations

Blanket Implementations

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

impl<T> Any for T where
    T: Any

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.