Skip to main content

SocketService

Trait SocketService 

Source
pub trait SocketService: 'static {
    type Codec: Codec + Decoder<Message: Message> + Encoder<Message: Message>;
    type ConnectionService: ConnectionService<Request = <Self::Codec as Decoder>::Message, Response = <Self::Codec as Encoder>::Message>;
    type SocketListener: SocketListener;

    // Required methods
    fn codec(&self) -> Self::Codec;
    fn new_stream_service(
        &self,
        _stream: &<Self::SocketListener as SocketListener>::Stream,
    ) -> Self::ConnectionService;
}
Expand description

SocketService receives connections and produces ConnectionServices.

The SocketService is notified when a new connection is established. It is given the address of the remote peer and it returns a ConnectionService for that connection. You can think of this as the “connection factory” for your server. It is the “top” of your service stack.

Required Associated Types§

Source

type Codec: Codec + Decoder<Message: Message> + Encoder<Message: Message>

Message encoding scheme

Consider pooling your allocations, like with protosocket::PooledEncoder. The write out to the network uses the raw Encoder::Serialized type, so you can make outbound messages low-allocation via simple pooling.

Source

type ConnectionService: ConnectionService<Request = <Self::Codec as Decoder>::Message, Response = <Self::Codec as Encoder>::Message>

The type of connection service that will be created for each connection.

Source

type SocketListener: SocketListener

The listener type for this service. E.g., TcpSocketListener

Required Methods§

Source

fn codec(&self) -> Self::Codec

Create a new message codec for a connection.

Source

fn new_stream_service( &self, _stream: &<Self::SocketListener as SocketListener>::Stream, ) -> Self::ConnectionService

Create a new ConnectionService for your new connection. The Stream will be wired into a protosocket::Connection. You can look at it in here if it has data you want (like a SocketAddr).

Implementors§