Trait aldrin_core::transport::AsyncTransport
source · pub trait AsyncTransport {
type Error;
// Required methods
fn receive_poll(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<Message, Self::Error>>;
fn send_poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>;
fn send_start(self: Pin<&mut Self>, msg: Message) -> Result<(), Self::Error>;
fn send_poll_flush(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>;
}
Expand description
Bidirectional asynchronous message transport.
This trait represents the core abstraction used throughout Aldrin for communication between
clients and the broker. It is essentially a combination of Futures
’ Stream
trait for
receiving Message
s and the Sink
trait for sending.
Implementations must be reliable and ordered. Reliable means that Message
s must not get
corrupted. Ordered means that Message
s must be delivered in the same order they were
sent.
Typical implementations include:
- TCP/IP across a network.
- Unix domain sockets (
SOCK_STREAM
) between processes on a single machine. - Channels inside a single process.
§Shutdown
Transports shut down only implicitly when dropped or in the case of errors. There is no
explicit shutdown method, because the Aldrin protocol defines the Shutdown
message, after
which users of this trait are expected to drop the transport. Any unexpected shutdown must be
signaled with an Error
by the implementation.
§Errors
All methods may return an Error
at any time. Afterwards, the transport should be considered
unusable. Implementations may panic in any further method calls.
Required Associated Types§
Required Methods§
sourcefn receive_poll(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<Message, Self::Error>>
fn receive_poll( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Message, Self::Error>>
Attempts to receive the next message.
sourcefn send_poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn send_poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
Prepares the transport for sending a message.
This method must be called before sending a Message
with
send_start
. Only when it returns Poll::Ready(Ok(()))
is
the transport ready to start sending a single Message
.
The transport may be implicitly flushed, fully or partially, when this method is called.
sourcefn send_start(self: Pin<&mut Self>, msg: Message) -> Result<(), Self::Error>
fn send_start(self: Pin<&mut Self>, msg: Message) -> Result<(), Self::Error>
Begins sending a message.
Every call to this method must be preceded by a successful call to
send_poll_ready
.
Sending a Message
may flush the transport, but does not necessarily do so. Thus, even
when Ok(())
is returned, the Message
may not yet be delivered to the remote end of
the transport. Use send_poll_flush
to explicitly flush
the transport.