-class rpcc : public chanmgr {
-
- private:
-
- //manages per rpc info
- struct caller {
- caller(unsigned int xxid, unmarshall *un);
- ~caller();
-
- unsigned int xid;
- unmarshall *un;
- int intret;
- bool done;
- std::mutex m;
- std::condition_variable c;
- };
-
- void get_refconn(connection **ch);
- void update_xid_rep(unsigned int xid);
-
-
- sockaddr_in dst_;
- unsigned int clt_nonce_;
- unsigned int srv_nonce_;
- bool bind_done_;
- unsigned int xid_;
- int lossytest_;
- bool retrans_;
- bool reachable_;
-
- connection *chan_;
-
- std::mutex m_; // protect insert/delete to calls[]
- std::mutex chan_m_;
-
- bool destroy_wait_;
- std::condition_variable destroy_wait_c_;
-
- std::map<int, caller *> calls_;
- std::list<unsigned int> xid_rep_window_;
-
- struct request {
- request() { clear(); }
- void clear() { buf.clear(); xid = -1; }
- bool isvalid() { return xid != -1; }
- std::string buf;
- int xid;
- };
- struct request dup_req_;
- int xid_rep_done_;
- public:
-
- rpcc(sockaddr_in d, bool retrans=true);
- ~rpcc();
-
- struct TO {
- int to;
- };
- static const TO to_max;
- static const TO to_min;
- static TO to(int x) { TO t; t.to = x; return t;}
-
- unsigned int id() { return clt_nonce_; }
-
- int bind(TO to = to_max);
-
- void set_reachable(bool r) { reachable_ = r; }
-
- void cancel();
-
- int islossy() { return lossytest_ > 0; }
-
- int call1(unsigned int proc,
- marshall &req, unmarshall &rep, TO to);
-
- bool got_pdu(connection *c, char *b, int sz);
-
-
- template<class R>
- int call_m(unsigned int proc, marshall &req, R & r, TO to);
-
- template<class R>
- int call(unsigned int proc, R & r, TO to = to_max);
- template<class R, class A1>
- int call(unsigned int proc, const A1 & a1, R & r, TO to = to_max);
- template<class R, class A1, class A2>
- int call(unsigned int proc, const A1 & a1, const A2 & a2, R & r,
- TO to = to_max);
- template<class R, class A1, class A2, class A3>
- int call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3,
- R & r, TO to = to_max);
- template<class R, class A1, class A2, class A3, class A4>
- int call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3,
- const A4 & a4, R & r, TO to = to_max);
- template<class R, class A1, class A2, class A3, class A4, class A5>
- int call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3,
- const A4 & a4, const A5 & a5, R & r, TO to = to_max);
- template<class R, class A1, class A2, class A3, class A4, class A5,
- class A6>
- int call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3,
- const A4 & a4, const A5 & a5, const A6 & a6,
- R & r, TO to = to_max);
- template<class R, class A1, class A2, class A3, class A4, class A5,
- class A6, class A7>
- int call(unsigned int proc, const A1 & a1, const A2 & a2, const A3 & a3,
- const A4 & a4, const A5 & a5, const A6 &a6, const A7 &a7,
- R & r, TO to = to_max);
-
-};
-
-template<class R> int
-rpcc::call_m(unsigned int proc, marshall &req, R & r, TO to)
-{
- unmarshall u;
- int intret = call1(proc, req, u, to);
- if (intret < 0) return intret;
- u >> r;
- if(u.okdone() != true) {
- fprintf(stderr, "rpcc::call_m: failed to unmarshall the reply."
- "You are probably calling RPC 0x%x with wrong return "
- "type.\n", proc);
+class rpcc : private connection_delegate {
+ private:
+ 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(xid_t _xid, string *_rep) : xid(_xid), rep(_rep) {}
+
+ int xid;
+ string *rep;
+ int intret;
+ bool done = false;
+ mutex m;
+ cond c;
+ };
+
+ void get_latest_connection(shared_ptr<connection> & ch);
+ void update_xid_rep(xid_t xid, lock & m_lock);
+
+
+ sockaddr_in dst_;
+ nonce_t clt_nonce_;
+ nonce_t srv_nonce_ = 0;
+ bool bind_done_ = false;
+ int lossytest_ = 0;
+ bool reachable_ = true;
+
+ shared_ptr<connection> chan_;
+
+ mutex m_; // protect insert/delete to calls[]
+ mutex chan_m_;
+
+ bool destroy_wait_ = false;
+ cond destroy_wait_c_;
+
+ map<int, caller *> calls_;
+
+ // xid starts with 1 and latest received reply starts with 0
+ xid_t xid_ = 1;
+ list<xid_t> xid_rep_window_ = {0};
+
+ struct request {
+ void clear() { buf.clear(); xid = -1; }
+ bool isvalid() { return xid != -1; }
+ string buf;
+ xid_t xid = -1;
+ };
+ request dup_req_;
+ int xid_rep_done_ = -1;
+
+ int call1(proc_id_t proc, milliseconds to, string & rep, marshall & req);
+
+ template<class R>
+ inline int call_m(proc_id_t proc, milliseconds to, R & r, marshall && req) {
+ string rep;
+ int intret = call1(proc, to, rep, req);
+ if (intret < 0) return intret;
+ unmarshall u(rep, true, r);
+ if (u.okdone() != true) {
+ LOG("rpcc::call_m: failed to unmarshall the reply. You are probably " <<
+ "calling RPC 0x" << hex << proc << " with the wrong return type.");