pub struct RpcServer<'a> { /* private fields */ }Expand description
Server side of the shared-memory RPC protocol.
Polls the request region (offset 0) for incoming calls, dispatches them
via the provided RpcHandler, and writes responses to the response
region (offset 32768).
§Example
use grafos_rpc::{RpcHandler, RpcServer};
use grafos_std::error::{FabricError, Result};
use grafos_std::mem::MemBuilder;
struct Echo;
impl RpcHandler for Echo {
fn handle(&self, _method_id: u32, payload: &[u8]) -> Result<Vec<u8>> {
Ok(payload.to_vec())
}
}
let lease = MemBuilder::new().min_bytes(65536).acquire()?;
let server = RpcServer::new(&lease);
// In your event loop:
// let handled = server.poll_once(&Echo)?;Implementations§
Source§impl<'a> RpcServer<'a>
impl<'a> RpcServer<'a>
Sourcepub fn new(lease: &'a MemLease) -> Self
pub fn new(lease: &'a MemLease) -> Self
Create a new RPC server backed by the given memory lease.
Sourcepub fn poll_once<H: RpcHandler>(&self, handler: &H) -> Result<bool>
pub fn poll_once<H: RpcHandler>(&self, handler: &H) -> Result<bool>
Poll for and handle a single request.
Reads the request region. If a request with status REQUEST_READY
is present:
- Sets status to
PROCESSING. - Calls
handler.handle(method_id, payload). - Writes
RESPONSE_READY(orERROR) to the response region. - Clears the request region to
EMPTY. - Returns
Ok(true).
If no request is pending, returns Ok(false) without side effects.
Sourcepub fn serve_n<H: RpcHandler>(
&self,
handler: &H,
max_iterations: u64,
) -> Result<u64>
pub fn serve_n<H: RpcHandler>( &self, handler: &H, max_iterations: u64, ) -> Result<u64>
Serve requests in a loop for up to max_iterations polls.
Returns the number of requests actually handled (i.e. the number of
times poll_once returned Ok(true)).
This is a convenience for testing where you know a fixed number of
calls will arrive. In production, call poll_once
from your own event loop.
Auto Trait Implementations§
impl<'a> Freeze for RpcServer<'a>
impl<'a> !RefUnwindSafe for RpcServer<'a>
impl<'a> !Send for RpcServer<'a>
impl<'a> !Sync for RpcServer<'a>
impl<'a> Unpin for RpcServer<'a>
impl<'a> !UnwindSafe for RpcServer<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more