Trait rotor_stream::Protocol [] [src]

pub trait Protocol: Sized {
    type Context;
    type Socket: StreamSocket;
    type Seed;
    fn create(
        seed: Self::Seed,
        sock: &mut Self::Socket,
        scope: &mut Scope<Self::Context>
    ) -> Intent<Self>; fn bytes_read(
        self,
        transport: &mut Transport<Self::Socket>,
        end: usize,
        scope: &mut Scope<Self::Context>
    ) -> Intent<Self>; fn bytes_flushed(
        self,
        transport: &mut Transport<Self::Socket>,
        scope: &mut Scope<Self::Context>
    ) -> Intent<Self>; fn timeout(
        self,
        transport: &mut Transport<Self::Socket>,
        scope: &mut Scope<Self::Context>
    ) -> Intent<Self>; fn exception(
        self,
        _transport: &mut Transport<Self::Socket>,
        reason: Exception,
        _scope: &mut Scope<Self::Context>
    ) -> Intent<Self>; fn fatal(
        self,
        reason: Exception,
        scope: &mut Scope<Self::Context>
    ) -> Option<Box<Error>>; fn wakeup(
        self,
        transport: &mut Transport<Self::Socket>,
        scope: &mut Scope<Self::Context>
    ) -> Intent<Self>; }

Associated Types

Required Methods

Starting the protocol (e.g. accepted a socket)

The action WaitBytes or WaitDelimiter is complete

Note you don't have to consume input buffer. The data is in the transport, but you are free to ignore it. This may be useful for example to yield Bytes(4) to read the header size and then yield bigger value to read the whole header at once. But be careful, if you don't consume bytes you will repeatedly receive them again.

The action Flush is complete

Timeout happened, which means either deadline reached in Bytes, Delimiter, Flush. Or Sleep has passed.

The method is called when too much bytes are read but no delimiter is found within the number of bytes specified. Or end of stream reached

The usual case is to just close the connection (because it's probably DoS attack is going on or the protocol mismatch), but sometimes you want to send error code, like 413 Entity Too Large for HTTP.

Note it's your responsibility to wait for the buffer to be flushed. If you write to the buffer and then return Intent::done() immediately, your data will be silently discarded.

The WriteError and ConnectError are never passed here but passed into fatal handler instead.

This method is called on fatal errors of the connection

Connection can't proceed after this method is called

Note: we use shared Exception type for both exception and fatal exceptions. This method receives WriteError and ConnectError options only.

Message received (from the main loop)

Implementors