Trait tokio_proto::streaming::multiplex::ServerProto [−][src]
pub trait ServerProto<T: 'static>: 'static { type Request: 'static; type RequestBody: 'static; type Response: 'static; type ResponseBody: 'static; type Error: From<Error> + 'static; type Transport: Transport<Self::RequestBody, Item = Frame<Self::Request, Self::RequestBody, Self::Error>, SinkItem = Frame<Self::Response, Self::ResponseBody, Self::Error>>; type BindTransport: IntoFuture<Item = Self::Transport, Error = Error>; fn bind_transport(&self, io: T) -> Self::BindTransport; }
A streaming, multiplexed server protocol.
The T
parameter is used for the I/O object used to communicate, which is
supplied in bind_transport
.
For simple protocols, the Self
type is often a unit struct. In more
advanced cases, Self
may contain configuration information that is used
for setting up the transport in bind_transport
.
Considerations
There are some difficulties with implementing back pressure in the case that the wire protocol does not support a means by which backpressure can be signaled to the peer.
The problem is the potential for deadlock:
-
The server is busy processing requests on this connection, and stops reading frames from its transport.
-
Meanwhile, the processing logic is blocked waiting for another frame that is currently pending on the socket.
To deal with this, once the connection's frame buffer is filled, a timeout is set. If no further frames are able to be read before the timeout expires, the connection is killed.
Associated Types
type Request: 'static
Request headers.
type RequestBody: 'static
Request body chunks.
type Response: 'static
Response headers.
type ResponseBody: 'static
Response body chunks.
type Error: From<Error> + 'static
Errors, which are used both for error frames and for the service itself.
type Transport: Transport<Self::RequestBody, Item = Frame<Self::Request, Self::RequestBody, Self::Error>, SinkItem = Frame<Self::Response, Self::ResponseBody, Self::Error>>
The frame transport, which usually take T
as a parameter.
type BindTransport: IntoFuture<Item = Self::Transport, Error = Error>
A future for initializing a transport from an I/O object.
In simple cases, Result<Self::Transport, Self::Error>
often suffices.
Required Methods
fn bind_transport(&self, io: T) -> Self::BindTransport
Build a transport from the given I/O object, using self
for any
configuration.