X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/d54215aea2a7321ab0f2dc7b0042fea2b7ff5df5..4e881433f37417ccbda89c09ffdf936855d462d4:/rpc/rpc.h diff --git a/rpc/rpc.h b/rpc/rpc.h index 7b65101..3ae7737 100644 --- a/rpc/rpc.h +++ b/rpc/rpc.h @@ -37,10 +37,12 @@ class rpcc : private connection_delegate { using proc_id_t = rpc_protocol::proc_id_t; template using proc_t = rpc_protocol::proc_t; + using nonce_t = rpc_protocol::nonce_t; + using xid_t = rpc_protocol::xid_t; // manages per rpc info struct caller { - caller(int _xid, string *_rep) : xid(_xid), rep(_rep) {} + caller(xid_t _xid, string *_rep) : xid(_xid), rep(_rep) {} int xid; string *rep; @@ -51,14 +53,14 @@ class rpcc : private connection_delegate { }; void get_refconn(shared_ptr & ch); - void update_xid_rep(int xid); + void update_xid_rep(xid_t xid); sockaddr_in dst_; - unsigned int clt_nonce_; - unsigned int srv_nonce_; + nonce_t clt_nonce_; + nonce_t srv_nonce_; bool bind_done_; - int xid_; + xid_t xid_; int lossytest_; bool retrans_; bool reachable_; @@ -72,13 +74,13 @@ class rpcc : private connection_delegate { cond destroy_wait_c_; map calls_; - list xid_rep_window_; + list xid_rep_window_; struct request { void clear() { buf.clear(); xid = -1; } bool isvalid() { return xid != -1; } string buf; - int xid = -1; + xid_t xid = -1; }; request dup_req_; int xid_rep_done_; @@ -108,7 +110,7 @@ class rpcc : private connection_delegate { rpcc(const string & d, bool retrans=true); ~rpcc(); - unsigned int id() { return clt_nonce_; } + nonce_t id() { return clt_nonce_; } int bind(milliseconds to = rpc::to_max); @@ -135,6 +137,8 @@ class rpcs : private connection_delegate { using proc_id_t = rpc_protocol::proc_id_t; template using proc_t = rpc_protocol::proc_t; + using nonce_t = rpc_protocol::nonce_t; + using xid_t = rpc_protocol::xid_t; typedef enum { NEW, // new RPC, not a duplicate @@ -148,36 +152,29 @@ class rpcs : private connection_delegate { // has been sent; in that case buf points to a copy of the reply, // and sz holds the size of the reply. struct reply_t { - reply_t (int _xid) : xid(_xid), cb_present(false) {} - reply_t (int _xid, const string & _buf) : xid(_xid), cb_present(true), buf(_buf) {} - int xid; + reply_t (xid_t _xid) : xid(_xid), cb_present(false) {} + reply_t (xid_t _xid, const string & _buf) : xid(_xid), cb_present(true), buf(_buf) {} + xid_t xid; bool cb_present; // whether the reply buffer is valid string buf; // the reply buffer }; in_port_t port_; - unsigned int nonce_; + nonce_t nonce_; // provide at most once semantics by maintaining a window of replies // per client that that client hasn't acknowledged receiving yet. // indexed by client nonce. - map> reply_window_; + map> reply_window_; void free_reply_window(void); - void add_reply(unsigned int clt_nonce, int xid, const string & b); - - rpcstate_t checkduplicate_and_update(unsigned int clt_nonce, - int xid, int rep_xid, string & b); + void add_reply(nonce_t clt_nonce, xid_t xid, const string & b); - void updatestat(proc_id_t proc); + rpcstate_t checkduplicate_and_update(nonce_t clt_nonce, xid_t xid, + xid_t rep_xid, string & b); // latest connection to the client - map> conns_; - - // counting - const size_t counting_; - size_t curr_counts_; - map counts_; + map> conns_; bool reachable_; @@ -185,7 +182,6 @@ class rpcs : private connection_delegate { map procs_; mutex procs_m_; // protect insert/delete to procs[] - mutex count_m_; // protect modification of counts mutex reply_window_m_; // protect reply window et al mutex conns_m_; // protect conns_ @@ -195,21 +191,21 @@ class rpcs : private connection_delegate { void reg1(proc_id_t proc, handler *); unique_ptr dispatchpool_; - unique_ptr listener_; + unique_ptr listener_; // RPC handler for clients binding - rpc_protocol::status rpcbind(unsigned int &r, int a); + rpc_protocol::status rpcbind(nonce_t &r); bool got_pdu(const shared_ptr & c, const string & b); public: - rpcs(in_port_t port, size_t counts=0); + rpcs(in_port_t port); ~rpcs(); void set_reachable(bool r) { reachable_ = r; } - template void reg(proc_t

proc, F f, C *c=nullptr) { + template inline void reg(proc_t

proc, F f, C *c=nullptr) { static_assert(is_valid_registration::value, "RPC handler registered with incorrect argument types"); struct ReturnOnFailure { static inline int unmarshall_args_failure() {