X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5a5c578e2e358a121cdb9234a6cb11c4ecfbf323..a5f10a497bebfc680bf418193f1fd9f1ad7cc417:/rsm_client.h diff --git a/rsm_client.h b/rsm_client.h index bb21f24..2a9c8c4 100644 --- a/rsm_client.h +++ b/rsm_client.h @@ -14,14 +14,14 @@ class rsm_client { protected: - std::string primary; - std::vector known_mems; - std::mutex rsm_client_mutex; + string primary; + vector known_mems; + mutex rsm_client_mutex; void primary_failure(lock & rsm_client_mutex_lock); bool init_members(lock & rsm_client_mutex_lock); public: - rsm_client(std::string dst); - rsm_protocol::status invoke(unsigned int proc, std::string &rep, const std::string &req); + rsm_client(string dst); + rsm_protocol::status invoke(unsigned int proc, string &rep, const string &req); template int call(unsigned int proc, R & r, const Args & ...a1); @@ -29,30 +29,41 @@ class rsm_client { template int call_m(unsigned int proc, R & r, const marshall & req); }; +inline string hexify(const string & s) { + string bytes; + for (char ch : s) { + bytes.push_back("0123456789abcdef"[(uint8_t)ch >> 4]); + bytes.push_back("0123456789abcdef"[(uint8_t)ch & 15]); + } + return bytes; +} + template int rsm_client::call_m(unsigned int proc, R & r, const marshall & req) { - std::string rep; - std::string res; - int intret = invoke(proc, rep, req.cstr()); + string rep; + string res; + int intret = invoke(proc, rep, req.content()); VERIFY( intret == rsm_client_protocol::OK ); - unmarshall u(rep); + unmarshall u(rep, false); u >> intret; if (intret < 0) return intret; u >> res; if (!u.okdone()) { - fprintf(stderr, "rsm_client::call_m: failed to unmarshall the reply.\n" - "You probably forgot to set the reply string in " - "rsm::client_invoke, or you may call RPC 0x%x with wrong return " - "type\n", proc); + LOG("failed to unmarshall the reply."); + LOG("You probably forgot to set the reply string in " << + "rsm::client_invoke, or you may have called RPC " << + "0x" << hex << proc << " with the wrong return type"); + LOG("here's what I got: \"" << hexify(rep) << "\""); VERIFY(0); return rpc_const::unmarshal_reply_failure; } - unmarshall u1(res); + unmarshall u1(res, false); u1 >> r; if(!u1.okdone()) { - fprintf(stderr, "rsm_client::call_m: failed to unmarshall the reply.\n" - "You are probably calling RPC 0x%x with wrong return " - "type.\n", proc); + LOG("failed to unmarshall the reply."); + LOG("You are probably calling RPC 0x" << hex << proc << + " with the wrong return type."); + LOG("here's what I got: \"" << hexify(res) << "\""); VERIFY(0); return rpc_const::unmarshal_reply_failure; }