using proc_id_t = rpc_protocol::proc_id_t;
template <class S>
using proc_t = rpc_protocol::proc_t<S>;
+ 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;
};
void get_refconn(shared_ptr<connection> & 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_;
cond destroy_wait_c_;
map<int, caller *> calls_;
- list<int> xid_rep_window_;
+ list<xid_t> 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_;
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);
using proc_id_t = rpc_protocol::proc_id_t;
template <class S>
using proc_t = rpc_protocol::proc_t<S>;
+ using nonce_t = rpc_protocol::nonce_t;
+ using xid_t = rpc_protocol::xid_t;
typedef enum {
NEW, // new RPC, not a duplicate
// 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<unsigned int, list<reply_t>> reply_window_;
+ map<nonce_t, list<reply_t>> 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<unsigned int, shared_ptr<connection>> conns_;
-
- // counting
- const size_t counting_;
- size_t curr_counts_;
- map<proc_id_t, size_t> counts_;
+ map<nonce_t, shared_ptr<connection>> conns_;
bool reachable_;
map<proc_id_t, handler *> 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_
void reg1(proc_id_t proc, handler *);
unique_ptr<thread_pool> dispatchpool_;
- unique_ptr<tcpsconn> listener_;
+ unique_ptr<connection_listener> 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<connection> & 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<class P, class F, class C=void> void reg(proc_t<P> proc, F f, C *c=nullptr) {
+ template<class P, class F, class C=void> inline void reg(proc_t<P> proc, F f, C *c=nullptr) {
static_assert(is_valid_registration<P, F>::value, "RPC handler registered with incorrect argument types");
struct ReturnOnFailure {
static inline int unmarshall_args_failure() {