881de9b7d69054f0489473090cbd8c76eaab74dd
[invirt/third/libt4.git] / rpc / rpc_protocol.h
1 #ifndef rpc_protocol_h
2 #define rpc_protocol_h
3
4 #include "types.h"
5
6 namespace rpc_protocol {
7     using proc_id_t = uint32_t;
8
9     using status = int32_t;
10     using rpc_sz_t = uint32_t;
11
12     enum : status {
13         timeout_failure = -1,
14         unmarshal_args_failure = -2,
15         unmarshal_reply_failure = -3,
16         atmostonce_failure = -4,
17         oldsrv_failure = -5,
18         bind_failure = -6,
19         cancel_failure = -7
20     };
21
22     struct request_header {
23         int xid;
24         proc_id_t proc;
25         unsigned int clt_nonce;
26         unsigned int srv_nonce;
27         int xid_rep;
28
29         MEMBERS(xid, proc, clt_nonce, srv_nonce, xid_rep)
30     };
31
32     struct reply_header {
33         int xid;
34         int ret;
35
36         MEMBERS(xid, ret)
37     };
38
39     template <typename Signature>
40     struct proc_t {
41         using signature = Signature;
42         proc_id_t id;
43     };
44
45     const size_t RPC_HEADER_SZ = max(sizeof(request_header), sizeof(reply_header)) + sizeof(rpc_sz_t);
46     const size_t DEFAULT_RPC_SZ = 1024; // size of initial buffer allocation
47     const size_t MAX_PDU = 10<<20; //maximum PDF is 10M
48
49 #define REMOTE_PROCEDURE_BASE(_base_) enum proc_no : ::rpc_protocol::proc_id_t { base = _base_ };
50 #define REMOTE_PROCEDURE(_offset_, _name_, _args_) static constexpr ::rpc_protocol::proc_t<status _args_> _name_{base + _offset_};
51
52     REMOTE_PROCEDURE_BASE(0);
53     REMOTE_PROCEDURE(1, bind, (unsigned int &, int)); // handler number reserved for bind
54 };
55
56 ENDIAN_SWAPPABLE(rpc_protocol::request_header)
57 ENDIAN_SWAPPABLE(rpc_protocol::reply_header)
58
59 #endif