using std::list;
using namespace std::chrono;
-inline void set_rand_seed() {
- auto now = time_point_cast<nanoseconds>(steady_clock::now());
- srandom((uint32_t)now.time_since_epoch().count()^(uint32_t)getpid());
-}
-
static sockaddr_in make_sockaddr(const string & hostandport);
rpcc::rpcc(const string & d) : dst_(make_sockaddr(d))
{
- set_rand_seed();
- clt_nonce_ = (nonce_t)random();
+ clt_nonce_ = (nonce_t)global->random_generator();
char *loss_env = getenv("RPC_LOSSY");
if (loss_env)
rpcc::~rpcc() {
lock ml(m_);
cancel(ml);
+
+ lock cl(chan_m_);
IF_LEVEL(2) LOG << "delete nonce " << clt_nonce_ << " chan " << (chan_?(int)chan_->fd:-1);
chan_.reset();
VERIFY(calls_.size() == 0);
<< ntoh(dst_.sin_port) << " done? " << ca.done << " ret " << ca.intret;
// destruction of req automatically frees its buffer
- return (ca.done? ca.intret : rpc_protocol::timeout_failure);
+ return ca.done ? ca.intret : rpc_protocol::timeout_failure;
}
void rpcc::get_latest_connection(shared_ptr<connection> & ch) {
ch = chan_;
}
-// PollMgr's thread is being used to
-// make this upcall from connection object to rpcc.
-// this funtion must not block.
-//
-// this function keeps no reference for connection *c
-bool
-rpcc::got_pdu(const shared_ptr<connection> &, const string & b)
-{
+// Runs in poll_mgr's thread as an upcall from the connection object to the
+// rpcc. Does not call blocking RPC handlers.
+bool rpcc::got_pdu(const shared_ptr<connection> &, const string & b) {
unmarshall rep(b, true);
rpc_protocol::reply_header h;
rep.read_header(h);
rpcs::rpcs(in_port_t p1) : port_(p1)
{
- set_rand_seed();
- nonce_ = (nonce_t)random();
+ nonce_ = (nonce_t)global->random_generator();
IF_LEVEL(2) LOG << "created with nonce " << nonce_;
reg(rpc_protocol::bind, &rpcs::rpcbind, this);