#include "marshall_wrap.h"
#include "connection.h"
+using std::chrono::milliseconds;
+
namespace rpc {
static constexpr milliseconds to_max{12000};
static constexpr milliseconds to_min{100};
}
-template<class P, class R, class ...Args> struct is_valid_call : false_type {};
+template<class P, class R, class ...Args>
+struct is_valid_call : false_type {};
template<class S, class R, class ...Args>
struct is_valid_call<S(R &, Args...), R, Args...> : true_type {};
-template<class P, class F> struct is_valid_registration : false_type {};
+template<class P, class F>
+struct is_valid_registration : false_type {};
template<class S, class R, class ...Args>
-struct is_valid_registration<S(R &, typename decay<Args>::type...), S(R &, Args...)> : true_type {};
+struct is_valid_registration<
+ S(R &, typename std::decay<Args>::type...),
+ S(R &, Args...)> : true_type {};
template<class P, class C, class S, class R, class ...Args>
-struct is_valid_registration<P, S(C::*)(R &, Args...)> : is_valid_registration<P, S(R &, Args...)> {};
+struct is_valid_registration<
+ P,
+ S(C::*)(R &, Args...)> : is_valid_registration<P, S(R &, Args...)> {};
// rpc client endpoint.
// manages a xid space per destination socket
string *rep;
int intret;
bool done = false;
- mutex m;
+ std::mutex m;
cond c;
};
shared_ptr<connection> chan_;
- mutex m_; // protect insert/delete to calls[]
- mutex chan_m_;
+ std::mutex m_; // protect insert/delete to calls[]
+ std::mutex chan_m_;
bool destroy_wait_ = false;
cond destroy_wait_c_;
- map<int, caller *> calls_;
+ std::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};
+ std::list<xid_t> xid_rep_window_ = {0};
struct request {
void clear() { buf.clear(); xid = -1; }
template<class P, class R, typename ...Args>
inline int call_timeout(proc_t<P> proc, milliseconds to, R & r, const Args & ... args) {
static_assert(is_valid_call<P, R, Args...>::value, "RPC called with incorrect argument types");
- return call_m(proc.id, to, r, forward<marshall>(marshall(args...)));
+ return call_m(proc.id, to, r, std::forward<marshall>(marshall(args...)));
}
};
// 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<nonce_t, list<reply_t>> reply_window_;
+ std::map<nonce_t, std::list<reply_t>> reply_window_;
void add_reply(nonce_t clt_nonce, xid_t xid, const string & b);
xid_t rep_xid, string & b);
// latest connection to the client
- map<nonce_t, shared_ptr<connection>> conns_;
+ std::map<nonce_t, shared_ptr<connection>> conns_;
bool reachable_ = true;
// map proc # to function
- map<proc_id_t, handler *> procs_;
+ std::map<proc_id_t, handler *> procs_;
- mutex procs_m_; // protect insert/delete to procs[]
- mutex reply_window_m_; // protect reply window et al
- mutex conns_m_; // protect conns_
+ std::mutex procs_m_; // protect insert/delete to procs[]
+ std::mutex reply_window_m_; // protect reply window et al
+ std::mutex conns_m_; // protect conns_
void dispatch(shared_ptr<connection> c, const string & buf);