pub struct Connection<Bindings: ConnectionBindings> { /* private fields */ }Expand description
A bidirectional, message-oriented AsyncRead/AsyncWrite stream wrapper.
Connections are Futures that you spawn.
To send messages, you push them into the outbound message stream.
To receive messages, you implement a MessageReactor.
Inbound messages are not wrapped in a Stream, in order to avoid an
extra layer of async buffering. If you need to buffer messages or
forward them to a Stream, you can do so in the reactor. If you can
process them very quickly, you can handle them inline in the reactor
callback on_messages, which will let you reply as soon as possible.
Implementations§
Source§impl<Bindings: ConnectionBindings> Connection<Bindings>
impl<Bindings: ConnectionBindings> Connection<Bindings>
Sourcepub fn new(
stream: Bindings::Stream,
address: SocketAddr,
deserializer: Bindings::Deserializer,
serializer: Bindings::Serializer,
max_buffer_length: usize,
buffer_allocation_increment: usize,
max_queued_send_messages: usize,
outbound_messages: Receiver<<Bindings::Serializer as Serializer>::Message>,
reactor: Bindings::Reactor,
) -> Connection<Bindings> ⓘ
pub fn new( stream: Bindings::Stream, address: SocketAddr, deserializer: Bindings::Deserializer, serializer: Bindings::Serializer, max_buffer_length: usize, buffer_allocation_increment: usize, max_queued_send_messages: usize, outbound_messages: Receiver<<Bindings::Serializer as Serializer>::Message>, reactor: Bindings::Reactor, ) -> Connection<Bindings> ⓘ
Create a new protosocket Connection with the given stream and reactor.
Probably you are interested in the protosocket-server or protosocket-prost crates.
Trait Implementations§
Source§impl<Bindings: ConnectionBindings> Display for Connection<Bindings>
impl<Bindings: ConnectionBindings> Display for Connection<Bindings>
Source§impl<Lifecycle: ConnectionBindings> Drop for Connection<Lifecycle>
impl<Lifecycle: ConnectionBindings> Drop for Connection<Lifecycle>
Source§impl<Bindings: ConnectionBindings> Future for Connection<Bindings>
impl<Bindings: ConnectionBindings> Future for Connection<Bindings>
Source§fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output>
fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) -> Poll<Self::Output>
Take a look at ConnectionBindings for the type definitions used by the Connection
This method performs the following steps:
- Check for read readiness and read into the receive_buffer (up to max_buffer_length).
- Deserialize the read bytes into Messages and store them in the inbound_messages queue.
- Dispatch messages as they are deserialized using the user-provided MessageReactor.
- Serialize messages from outbound_messages queue, up to max_queued_send_messages.
- Send serialized messages.