X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5a5c578e2e358a121cdb9234a6cb11c4ecfbf323..c9be386a30dc7145ac757fae66c255b21da26d5d:/rpc/rpc.h diff --git a/rpc/rpc.h b/rpc/rpc.h index f01af09..065cabc 100644 --- a/rpc/rpc.h +++ b/rpc/rpc.h @@ -7,6 +7,7 @@ #include "thr_pool.h" #include "marshall.h" +#include "marshall_wrap.h" #include "connection.h" class rpc_const { @@ -30,10 +31,10 @@ class rpcc : public chanmgr { //manages per rpc info struct caller { - caller(int _xid, unmarshall *_un) : xid(_xid), un(_un) {} + caller(int _xid, string *_rep) : xid(_xid), rep(_rep) {} int xid; - unmarshall *un; + string *rep; int intret; bool done = false; mutex m; @@ -95,10 +96,9 @@ class rpcc : public chanmgr { int islossy() { return lossytest_ > 0; } - int call1(proc_t proc, - marshall &req, unmarshall &rep, TO to); + int call1(proc_t proc, marshall &req, string &rep, TO to); - bool got_pdu(connection *c, char *b, size_t sz); + bool got_pdu(connection *c, const string & b); template int call_m(proc_t proc, marshall &req, R & r, TO to); @@ -113,8 +113,9 @@ class rpcc : public chanmgr { template int rpcc::call_m(proc_t proc, marshall &req, R & r, TO to) { - unmarshall u; - int intret = call1(proc, req, u, to); + string rep; + int intret = call1(proc, req, rep, to); + unmarshall u(rep, true); if (intret < 0) return intret; u >> r; if (u.okdone() != true) { @@ -139,8 +140,6 @@ rpcc::call_timeout(proc_t proc, const rpcc::TO to, R & r, const Args&... args) return call_m(proc, m, r, to); } -bool operator<(const sockaddr_in &a, const sockaddr_in &b); - // rpc server endpoint. class rpcs : public chanmgr { @@ -158,25 +157,14 @@ class rpcs : public chanmgr { // 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; - buf = NULL; - sz = 0; - } - reply_t (int _xid, char *_buf, size_t _sz) { - xid = _xid; - cb_present = true; - buf = _buf; - sz = _sz; - } + 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; bool cb_present; // whether the reply buffer is valid - char *buf; // the reply buffer - size_t sz; // the size of reply buffer + string buf; // the reply buffer }; - unsigned int port_; + in_port_t port_; unsigned int nonce_; // provide at most once semantics by maintaining a window of replies @@ -185,11 +173,10 @@ class rpcs : public chanmgr { map > reply_window_; void free_reply_window(void); - void add_reply(unsigned int clt_nonce, int xid, char *b, size_t sz); + 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, - char **b, size_t *sz); + int xid, int rep_xid, string & b); void updatestat(proc_t proc); @@ -201,7 +188,6 @@ class rpcs : public chanmgr { size_t curr_counts_; map counts_; - int lossytest_; bool reachable_; // map proc # to function @@ -216,10 +202,8 @@ class rpcs : public chanmgr { protected: struct djob_t { - djob_t (connection *c, char *b, size_t bsz):buf(b),sz(bsz),conn(c) {} - char *buf; - size_t sz; connection *conn; + string buf; }; void dispatch(djob_t *); @@ -227,18 +211,18 @@ class rpcs : public chanmgr { void reg1(proc_t proc, handler *); ThrPool* dispatchpool_; - tcpsconn* listener_; + tcpsconn *listener_; public: - rpcs(unsigned int port, size_t counts=0); + rpcs(in_port_t port, size_t counts=0); ~rpcs(); - inline unsigned int port() { return listener_->port(); } + inline in_port_t port() { return listener_->port(); } //RPC handler for clients binding int rpcbind(unsigned int &r, int a); void set_reachable(bool r) { reachable_ = r; } - bool got_pdu(connection *c, char *b, size_t sz); + bool got_pdu(connection *c, const string & b); template void reg(proc_t proc, F f, C *c=nullptr); }; @@ -253,7 +237,4 @@ template void rpcs::reg(proc_t proc, F f, C *c) { reg1(proc, marshalled_func::wrap(f, c)); } -sockaddr_in make_sockaddr(const string &hostandport); -sockaddr_in make_sockaddr(const string &host, const string &port); - #endif