Enum rotor_stream::Expectation
[−]
[src]
pub enum Expectation { Bytes(usize), Delimiter(usize, &'static [u8], usize), Flush(usize), Sleep, }
Variants
Bytes(usize)
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
Delimiter(usize, &'static [u8], usize)
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.
Flush(usize)
Wait until no more than N bytes is in output buffer
This is going to be used for several cases:
Flush(0)
before closing the connectionFlush(0)
to before receiving new request (if needed)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 thanFlush(0)
Sleep
Wait until deadline
This useful for two cases:
- Just wait before doing anything if required by business logic
- Wait until
wakeup
happens or atimeout whatever comes first