Fixed a race condition!
[invirt/third/libt4.git] / rpc / rpc.cc
index 2c1f1a5..c417f40 100644 (file)
@@ -341,20 +341,22 @@ rpcs::rpcs(in_port_t p1, size_t count)
 {
     set_rand_seed();
     nonce_ = (unsigned int)random();
-    IF_LEVEL(2) LOG("created with nonce " << nonce_);
+    IF_LEVEL(0) LOG("created with nonce " << nonce_);
 
     reg(rpc_const::bind, &rpcs::rpcbind, this);
-    dispatchpool_ = new ThrPool(6, false);
+    dispatchpool_ = unique_ptr<ThrPool>(new ThrPool(6, false));
+}
 
+void rpcs::start() {
     char *loss_env = getenv("RPC_LOSSY");
-    listener_ = new tcpsconn(this, port_, loss_env ? atoi(loss_env) : 0);
+    listener_ = unique_ptr<tcpsconn>(new tcpsconn(this, port_, loss_env ? atoi(loss_env) : 0));
 }
 
 rpcs::~rpcs()
 {
     // must delete listener before dispatchpool
-    delete listener_;
-    delete dispatchpool_;
+    listener_ = nullptr;
+    dispatchpool_ = nullptr;
     free_reply_window();
 }
 
@@ -436,7 +438,7 @@ void rpcs::dispatch(shared_ptr<connection> c, const string & buf) {
     {
         lock pl(procs_m_);
         if(procs_.count(proc) < 1){
-            cerr << "unknown proc " << hex << proc << "." << endl;
+            LOG("unknown proc 0x" << hex << proc << " with h.srv_nonce=" << h.srv_nonce << ", my srv_nonce=" << nonce_);
             VERIFY(0);
             return;
         }
@@ -610,7 +612,7 @@ void rpcs::free_reply_window(void) {
 }
 
 int rpcs::rpcbind(unsigned int &r, int) {
-    IF_LEVEL(2) LOG("called return nonce " << nonce_);
+    IF_LEVEL(0) LOG("called return nonce " << nonce_);
     r = nonce_;
     return 0;
 }