X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/be7cf844f59fa483423724e8e4b5e663e5b88ddd..6b5e09540e9392a7015fae1ad3b01b0973600ff2:/rpc/rpc_protocol.h?ds=sidebyside diff --git a/rpc/rpc_protocol.h b/rpc/rpc_protocol.h index 8107f04..881de9b 100644 --- a/rpc/rpc_protocol.h +++ b/rpc/rpc_protocol.h @@ -3,33 +3,57 @@ #include "types.h" -using proc_t = uint32_t; -using status_t = int32_t; -using rpc_sz_t = uint32_t; - -struct request_header { - int xid; - proc_t proc; - unsigned int clt_nonce; - unsigned int srv_nonce; - int xid_rep; - - MEMBERS(xid, proc, clt_nonce, srv_nonce, xid_rep) +namespace rpc_protocol { + using proc_id_t = uint32_t; + + using status = int32_t; + using rpc_sz_t = uint32_t; + + enum : status { + timeout_failure = -1, + unmarshal_args_failure = -2, + unmarshal_reply_failure = -3, + atmostonce_failure = -4, + oldsrv_failure = -5, + bind_failure = -6, + cancel_failure = -7 + }; + + struct request_header { + int xid; + proc_id_t proc; + unsigned int clt_nonce; + unsigned int srv_nonce; + int xid_rep; + + MEMBERS(xid, proc, clt_nonce, srv_nonce, xid_rep) + }; + + struct reply_header { + int xid; + int ret; + + MEMBERS(xid, ret) + }; + + template + struct proc_t { + using signature = Signature; + proc_id_t id; + }; + + const size_t RPC_HEADER_SZ = max(sizeof(request_header), sizeof(reply_header)) + sizeof(rpc_sz_t); + const size_t DEFAULT_RPC_SZ = 1024; // size of initial buffer allocation + const size_t MAX_PDU = 10<<20; //maximum PDF is 10M + +#define REMOTE_PROCEDURE_BASE(_base_) enum proc_no : ::rpc_protocol::proc_id_t { base = _base_ }; +#define REMOTE_PROCEDURE(_offset_, _name_, _args_) static constexpr ::rpc_protocol::proc_t _name_{base + _offset_}; + + REMOTE_PROCEDURE_BASE(0); + REMOTE_PROCEDURE(1, bind, (unsigned int &, int)); // handler number reserved for bind }; -ENDIAN_SWAPPABLE(request_header) - -struct reply_header { - int xid; - int ret; - - MEMBERS(xid, ret) -}; - -ENDIAN_SWAPPABLE(reply_header) - -const size_t RPC_HEADER_SZ = max(sizeof(request_header), sizeof(reply_header)) + sizeof(rpc_sz_t); -const size_t DEFAULT_RPC_SZ = 1024; // size of initial buffer allocation -const size_t MAX_PDU = 10<<20; //maximum PDF is 10M +ENDIAN_SWAPPABLE(rpc_protocol::request_header) +ENDIAN_SWAPPABLE(rpc_protocol::reply_header) #endif