template<typename Request, typename Response, typename InBuffer = buffer, typename OutBuffer = buffer>
class cbdc::rpc::async_server< Request, Response, InBuffer, OutBuffer >
Generic asynchronous RPC server.
Handles serialization of requests and responses. Dispatches incoming requests to a handler callback for processing and returns the response using a response callback. Subclass to define specific remote communication logic.
- Template Parameters
-
Request | type for requests. |
Response | type for responses. |
InBuffer | type of buffer for serialized requests, defaults to cbdc::buffer |
OutBuffer | type of buffer for serialized responses, defaults to cbdc::buffer |
Definition at line 27 of file async_server.hpp.
template<typename Request , typename Response , typename InBuffer = buffer, typename OutBuffer = buffer>
Request handler callback function.
Defines a function that processes an inbound request, attempts to generate a response, and passes that response to a callback for transmission. Should return false if processing the request failed and the server should return a general error.
Definition at line 50 of file async_server.hpp.
template<typename Request , typename Response , typename InBuffer = buffer, typename OutBuffer = buffer>
using cbdc::rpc::async_server< Request, Response, InBuffer, OutBuffer >::response_callback_type = std::function<void(std::optional<Response>)> |
Response callback function type.
Used to return responses generated by the request handler function before serialization.
Definition at line 43 of file async_server.hpp.
template<typename Request , typename Response , typename InBuffer = buffer, typename OutBuffer = buffer>
auto cbdc::rpc::async_server< Request, Response, InBuffer, OutBuffer >::async_call |
( |
InBuffer | request_buf, |
|
|
std::function< void(cbdc::buffer)> | response_callback ) -> std::optional<OutBuffer> |
|
inlineprotected |
Deserializes an RPC request, then calls the registered request handler function.
Provides the request handler function with a callback which serializes the response. That callback passes the serialized data buffer to the callback provided here for transmission.
- Parameters
-
request_buf | buffer holding an RPC request. |
response_callback | callback which transmits the serialized response buffer. |
- Returns
- std::nullopt if the request handler reported that the request started successfully. Also returns std::nullopt if deserializing the request failed. Returns a serialized error response if the request handler returns a failure.
Definition at line 74 of file async_server.hpp.
template<typename Request , typename Response , typename InBuffer = buffer, typename OutBuffer = buffer>
Register a request handler callback function for processing requests, generating responses, and passing those responses to a response callback.
- Parameters
-
callback | function to register to process client requests and call the response callback with the response. |
Definition at line 57 of file async_server.hpp.
Referenced by cbdc::raft::rpc::server::register_raft_node().