Enum rotor_stream::Expectation [] [src]

pub enum Expectation {
    Bytes(usize),
    Delimiter(usize&'static [u8]usize),
    Flush(usize),
    Sleep,
}

This is an enumeration used to declare what next protocol is expecting

The value is used in Intent::expect().

Most users should use IntentBuilder's (a type which is returned from Intent::of(..)) methods. But for some kinds of control flow being able to specify expectation as a separate enum is very useful.

Variants

Read number of bytes

The buffer that is passed to bytes_read might contain more bytes, but num parameter of the bytes_read() method will contain a number of bytes passed into Bytes constructor.

Note that bytes passed here is neither limit on bytes actually read from the network (we resize buffer as convenient for memory allocator and read as much as possible), nor is the preallocated buffer size (we don't preallocate the buffer to be less vulnerable to DoS attacks).

Note that real number of bytes that netbuf::Buf might contain is less than 4Gb. So this value can't be as big as usize::MAX

Read until delimiter

Parameters: offset, delimiter, max_bytes

Only static strings are supported for delimiter now.

bytes_read action gets passed num bytes before the delimeter, or in other words, the position of the delimiter in the buffer. The delimiter is guaranteed to be in the buffer too. The max_bytes do include the offset itself.

Wait until no more than N bytes is in output buffer

This is going to be used for several cases:

  1. Flush(0) before closing the connection
  2. Flush(0) to before receiving new request (if needed)
  3. Flush(N) to wait when you can continue producing some data, this allows TCP pushback. To be able not to put everything in output buffer at once. Still probably more efficient than Flush(0)

Wait until deadline

This useful for two cases:

  1. Just wait before doing anything if required by business logic
  2. Wait until wakeup happens or atimeout whatever comes first

Trait Implementations

impl Debug for Expectation
[src]

Formats the value using the given formatter.