pub struct ClientStream<F: ClientFacts, P: ClientTransport> { /* private fields */ }Expand description
ClientStream represents a client-side connection.
On Drop, the connection will be closed on the write-side. The response reader coroutine will not exit
until all the ClientTasks have a response or after task_timeout is reached.
The user sends packets in sequence, with a throttler controlling the IO depth of in-flight packets. An internal timer then registers the request through a channel, and when the response is received, it can optionally notify the user through a user-defined channel or another mechanism.
Implementations§
Source§impl<F: ClientFacts, P: ClientTransport> ClientStream<F, P>
impl<F: ClientFacts, P: ClientTransport> ClientStream<F, P>
Sourcepub fn connect(
facts: Arc<F>,
addr: &str,
conn_id: &str,
last_resp_ts: Option<Arc<AtomicU64>>,
) -> impl Future<Output = Result<Self, RpcIntErr>> + Send
pub fn connect( facts: Arc<F>, addr: &str, conn_id: &str, last_resp_ts: Option<Arc<AtomicU64>>, ) -> impl Future<Output = Result<Self, RpcIntErr>> + Send
Make a streaming connection to the server, returns ClientStream on success
pub fn get_codec(&self) -> &F::Codec
Sourcepub async fn ping(&mut self) -> Result<(), RpcIntErr>
pub async fn ping(&mut self) -> Result<(), RpcIntErr>
Should be call in sender threads
NOTE: will skip if throttler is full
pub fn get_last_resp_ts(&self) -> u64
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Since sender and receiver are two threads, might be close on either side
Sourcepub async fn set_error_and_exit(&mut self)
pub async fn set_error_and_exit(&mut self)
Force the receiver to exit.
You can call it when connectivity probes detect that a server is unreachable. And then just let the Client drop
Sourcepub async fn send_task(
&mut self,
task: F::Task,
need_flush: bool,
) -> Result<(), RpcIntErr>
pub async fn send_task( &mut self, task: F::Task, need_flush: bool, ) -> Result<(), RpcIntErr>
send_task() should only be called without parallelism.
NOTE: After send, will wait for response if too many inflight task in throttler.
Since the transport layer might have buffer, user should always call flush explicitly.
You can set need_flush = true for some urgent messages, or call flush_req() explicitly.
Sourcepub async fn flush_req(&mut self) -> Result<(), RpcIntErr>
pub async fn flush_req(&mut self) -> Result<(), RpcIntErr>
Since the transport layer might have buffer, user should always call flush explicitly.
you can set need_flush = true for some urgent message, or call flush_req() explicitly.
Sourcepub fn will_block(&self) -> bool
pub fn will_block(&self) -> bool
Check the throttler and see if future send_task() might be blocked
Sourcepub fn get_inflight_count(&self) -> usize
pub fn get_inflight_count(&self) -> usize
Get the task sent but not yet received response