Skip to main content

ClientStream

Struct ClientStream 

Source
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>

Source

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

Source

pub fn get_codec(&self) -> &F::Codec

Source

pub async fn ping(&mut self) -> Result<(), RpcIntErr>

Should be call in sender threads

NOTE: will skip if throttler is full

Source

pub fn get_last_resp_ts(&self) -> u64

Source

pub fn is_closed(&self) -> bool

Since sender and receiver are two threads, might be close on either side

Source

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

Source

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.

Source

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.

Source

pub fn will_block(&self) -> bool

Check the throttler and see if future send_task() might be blocked

Source

pub fn get_inflight_count(&self) -> usize

Get the task sent but not yet received response

Trait Implementations§

Source§

impl<F: ClientFacts, P: ClientTransport> Debug for ClientStream<F, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: ClientFacts, P: ClientTransport> Drop for ClientStream<F, P>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<F, P> Freeze for ClientStream<F, P>

§

impl<F, P> !RefUnwindSafe for ClientStream<F, P>

§

impl<F, P> Send for ClientStream<F, P>

§

impl<F, P> Sync for ClientStream<F, P>

§

impl<F, P> Unpin for ClientStream<F, P>

§

impl<F, P> !UnwindSafe for ClientStream<F, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V