VLink  2.0.0
A high-performance communication middleware
server.h File Reference

Handler-side primitive of the VLink method (RPC) communication model. More...

#include <memory>
#include <string>
#include <type_traits>
#include "./base/functional.h"
#include "./impl/server_impl.h"
#include "./node.h"
#include "./internal/server-inl.h"
Include dependency graph for server.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  vlink::Server< ReqT, RespT, SecT >
 Type-safe RPC handler for the VLink method communication model. More...
 
class  vlink::SecurityServer< ReqT, RespT >
 Convenience alias of Server with per-message encryption enabled. More...
 

Namespaces

 

Detailed Description

Handler-side primitive of the VLink method (RPC) communication model.

Server<ReqT, RespT, SecT> registers a handler for inbound RPC requests issued by matching Client instances. Three handler styles are supported: fire-and-forget (no response), synchronous request/response, and deferred asynchronous reply. Codec selection for both the request and the response payload is resolved at compile time.

The class is a thin, header-only template wrapper around ServerImpl.

Request / Response Sequence
*   Client<Req,Resp>           Transport Back-end           Server<Req,Resp>
*   -----------------          ------------------           -----------------
*      | invoke(req)                  |                            |
*      |----------------------------->|  serialised request        |
*      |                              |--------------------------->|
*      |                              |                            |  handler
*      |                              |                            |  fills resp
*      |                              |                            |   (sync mode)
*      |                              |                            |     -- or --
*      |                              |                            |  store req_id
*      |                              |                            |  reply(req_id, resp)
*      |                              |                            |   (async mode)
*      |                              |  serialised response       |
*      |                              |<---------------------------|
*      | deserialised response        |                            |
*      |<-----------------------------|                            |
* 
Three Listen-Handler Variants
Method Handler signature Semantics
listen(ReqCallback) void(const ReqT&) Fire-and-forget; no response.
listen(ReqRespCallback) void(const ReqT&, RespT&) Synchronous fill of resp.
listen_for_reply(ReqAsyncRespCallback) void(uint64_t, const Req&) Deferred reply via reply.
Synchronous Reply Example
vlink::Server<Req, Resp> svr("dds://compute/sum");
svr.listen([](const Req& q, Resp& r) {
r.value = q.a + q.b;
});
Deferred Asynchronous Reply Example
vlink::Server<Req, Resp> svr("dds://compute/sum");
uint64_t pending = 0;
svr.listen_for_reply([&](uint64_t id, const Req& q) {
pending = id;
schedule_async_work(q);
});
// ...some time later, from any thread:
svr.reply(pending, Resp{result});
Fire-and-Forget Example
vlink::Server<Req> svr("dds://logger/push"); // RespT defaults to EmptyType
svr.listen([](const Req& q) { write_log(q); });
Note
Calling listen() or listen_for_reply() more than once is a fatal error. reply() must only be used following listen_for_reply(); calling it after a synchronous listen() triggers a fatal log.
See also
client.h, node.h, serializer.h, base/functional.h