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 testsImplementations§
Source§impl<'a> RpcClient<'a>
impl<'a> RpcClient<'a>
Sourcepub fn new(lease: &'a MemLease) -> Self
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.
Sourcepub fn with_max_poll_iterations(self, n: u64) -> Self
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.
Sourcepub fn call<Req, Resp>(&mut self, method_id: u32, req: &Req) -> Result<Resp>where
Req: Serialize,
Resp: DeserializeOwned,
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 ofreqfailed.FabricError::CapacityExceeded– serialized payload exceeds 30 KiB.FabricError::LeaseExpired– poll limit exceeded (timeout).FabricError::IoError(-101)– deserialization of response failed.FabricError::IoError(-102)– server returnedERRORstatus.- Other
FabricErrorvariants from the underlying memory operations.