Struct bolic_network::hub::endpoint::Endpoint
source · pub struct Endpoint(/* private fields */);Expand description
An endpoint to the network that facilitates high-performance data transmission.
Endpoint encapsulates the necessary asynchronous/non-blocking handling of data transmission
in the network. Each endpoint may contain at most one underlying Transport object at a time.
It masks away the connection establishment, reconnection and other chores that need to be done by
different means of network transmission. Its internal state EndpointState is kept (owned)
by a Worker from the Driver and the worker will trigger the logic of the endpoint
to help user move data to and from the contained transport object at its best effort. It offers
to the user a nice and clear interface that one could asynchronously send to or receive from
the network. It carries data across different contained transports (i.e., the transport object
could be set and switched on-the-fly by Endpoint::set_transport), creates back pressure (aka.
flow control) in its logic, although the underlying transport may not do so. The user does not
have to care about whether the underlying transport is even active or not. If the transport
provides a reliable channel, it guarantees reliable delivery. Otherwise, some data may still be
lost due to the limitation of the specific transport implementation.
Implementations§
source§impl Endpoint
impl Endpoint
sourcepub async fn set_transport(
&self,
transport: Box<dyn Transport>
) -> Result<&Self>
pub async fn set_transport( &self, transport: Box<dyn Transport> ) -> Result<&Self>
Load the endpoint with the given transport (replacing if exists). Initially, an endpoint starts without a transport.
sourcepub async fn take_transport(&self) -> Result<Box<dyn Transport>>
pub async fn take_transport(&self) -> Result<Box<dyn Transport>>
Deregister the stream from the poll and take the transport out from the endpoint. The endpoint will be left without a transport.
sourcepub async fn flush(&self) -> Result<&Self>
pub async fn flush(&self) -> Result<&Self>
Try to flush the internal buffers in the endpoint. It is best-effort since the contained transport may not be available or able to transfer data.
sourcepub async fn set_worker(&self, worker: Worker) -> Result<&Self>
pub async fn set_worker(&self, worker: Worker) -> Result<&Self>
Switch to be driven by a different worker. Each worker runs a sequential polling event loop. This could be used to load-balance the workers.
sourcepub async fn reset(&self) -> Result<&Self>
pub async fn reset(&self) -> Result<&Self>
Reset the underlying transport. This will invoke shutdown() of the transport, causing the transport to eventually renew.
sourcepub async fn is_disconnected(&self) -> Result<bool>
pub async fn is_disconnected(&self) -> Result<bool>
Return if the underlying transport of the endpoint is disconnected.