RpcClient

Struct RpcClient 

Source
pub struct RpcClient<'a> { /* private fields */ }
Expand description

Client side of the shared-memory RPC protocol.

Writes serialized requests into the lease’s request region (offset 0), then polls the response region (offset 32768) until the server has written back a result.

Each call assigns a monotonically increasing request_id so that stale responses from a previous call are ignored.

§Example

use grafos_rpc::RpcClient;
use grafos_std::mem::MemBuilder;

let lease = MemBuilder::new().min_bytes(65536).acquire()?;
let mut client = RpcClient::new(&lease)
    .with_max_poll_iterations(100); // short timeout for tests

Implementations§

Source§

impl<'a> RpcClient<'a>

Source

pub fn new(lease: &'a MemLease) -> Self

Create a new RPC client backed by the given memory lease.

Initializes with request_id = 1 and a default poll limit of 1,000,000 iterations. Use with_max_poll_iterations to adjust the timeout behavior.

Source

pub fn with_max_poll_iterations(self, n: u64) -> Self

Set the maximum number of poll iterations before call returns Err(FabricError::LeaseExpired).

A low value (e.g. 10) is useful in tests to fail fast when no server is running. The default is 1,000,000.

Source

pub fn call<Req, Resp>(&mut self, method_id: u32, req: &Req) -> Result<Resp>
where Req: Serialize, Resp: DeserializeOwned,

Perform an RPC call.

Serializes req with postcard, writes it to the request region with method_id, then polls the response region until the server responds.

§Errors
  • FabricError::IoError(-100) – serialization of req failed.
  • FabricError::CapacityExceeded – serialized payload exceeds 30 KiB.
  • FabricError::LeaseExpired – poll limit exceeded (timeout).
  • FabricError::IoError(-101) – deserialization of response failed.
  • FabricError::IoError(-102) – server returned ERROR status.
  • Other FabricError variants from the underlying memory operations.

Auto Trait Implementations§

§

impl<'a> Freeze for RpcClient<'a>

§

impl<'a> !RefUnwindSafe for RpcClient<'a>

§

impl<'a> !Send for RpcClient<'a>

§

impl<'a> !Sync for RpcClient<'a>

§

impl<'a> Unpin for RpcClient<'a>

§

impl<'a> !UnwindSafe for RpcClient<'a>

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.