More cleaning
[invirt/third/libt4.git] / rpc / rpc.cc
index c6d93c8..ad3fcd9 100644 (file)
@@ -54,6 +54,7 @@
  x exited worker threads).
  */
 
+#include "types.h"
 #include "rpc.h"
 
 #include <sys/types.h>
 #include <netinet/tcp.h>
 #include <netdb.h>
 #include <unistd.h>
-#include "lock.h"
 
 #include "jsl_log.h"
-#include "threaded_log.h"
-#include "lang/verify.h"
-
-using std::stoi;
 
 const rpcc::TO rpcc::to_max = { 120000 };
 const rpcc::TO rpcc::to_min = { 1000 };
 
-rpcc::caller::caller(int xxid, unmarshall *xun)
-: xid(xxid), un(xun), done(false)
-{
-}
-
-rpcc::caller::~caller()
-{
-}
-
-inline
-void set_rand_seed()
-{
-    auto now = std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now());
+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());
 }
 
@@ -196,10 +181,8 @@ rpcc::call1(proc_t proc, marshall &req, unmarshall &rep,
     }
 
     TO curr_to;
-    std::chrono::time_point<std::chrono::steady_clock> finaldeadline =
-        std::chrono::steady_clock::now() +
-        std::chrono::milliseconds(to.to),
-        nextdeadline;
+    auto finaldeadline = steady_clock::now() + milliseconds(to.to),
+        nextdeadline = finaldeadline;
 
     curr_to.to = to_min.to;
 
@@ -231,20 +214,20 @@ rpcc::call1(proc_t proc, marshall &req, unmarshall &rep,
             transmit = false; // only send once on a given channel
         }
 
-        if(finaldeadline == std::chrono::time_point<std::chrono::steady_clock>::min())
+        if(finaldeadline == time_point<steady_clock>::min())
             break;
 
-        nextdeadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(curr_to.to);
+        nextdeadline = steady_clock::now() + milliseconds(curr_to.to);
         if(nextdeadline > finaldeadline) {
             nextdeadline = finaldeadline;
-            finaldeadline = std::chrono::time_point<std::chrono::steady_clock>::min();
+            finaldeadline = time_point<steady_clock>::min();
         }
 
         {
             lock cal(ca.m);
             while (!ca.done){
                 jsl_log(JSL_DBG_2, "rpcc:call1: wait\n");
-                if(ca.c.wait_until(cal, nextdeadline) == std::cv_status::timeout){
+                if(ca.c.wait_until(cal, nextdeadline) == cv_status::timeout){
                     jsl_log(JSL_DBG_2, "rpcc::call1: timeout\n");
                     break;
                 }
@@ -421,7 +404,7 @@ rpcs::got_pdu(connection *c, char *b, size_t sz)
 
     djob_t *j = new djob_t(c, b, sz);
     c->incref();
-    bool succ = dispatchpool_->addJob(std::bind(&rpcs::dispatch, this, j));
+    bool succ = dispatchpool_->addJob(bind(&rpcs::dispatch, this, j));
     if(!succ || !reachable_){
         c->decref();
         delete j;
@@ -447,16 +430,15 @@ rpcs::updatestat(proc_t proc)
     if(curr_counts_ == 0){
         LOG("RPC STATS: ");
         for (auto i = counts_.begin(); i != counts_.end(); i++)
-            LOG(std::hex << i->first << ":" << std::dec << i->second);
+            LOG(hex << i->first << ":" << dec << i->second);
 
         lock rwl(reply_window_m_);
-        map<unsigned int,list<reply_t> >::iterator clt;
 
         size_t totalrep = 0, maxrep = 0;
-        for (clt = reply_window_.begin(); clt != reply_window_.end(); clt++){
-            totalrep += clt->second.size();
-            if(clt->second.size() > maxrep)
-                maxrep = clt->second.size();
+        for (auto clt : reply_window_) {
+            totalrep += clt.second.size();
+            if(clt.second.size() > maxrep)
+                maxrep = clt.second.size();
         }
         jsl_log(JSL_DBG_1, "REPLY WINDOW: clients %d total reply %lu max per client %lu\n",
                         (int) reply_window_.size()-1, totalrep, maxrep);
@@ -639,8 +621,7 @@ rpcs::checkduplicate_and_update(unsigned int clt_nonce, int xid,
 
     int past_xid_rep = l.begin()->xid;
 
-    list<reply_t>::iterator start = l.begin(), it;
-    it = ++start;
+    list<reply_t>::iterator start = l.begin(), it = ++start;
 
     if (past_xid_rep < xid_rep || past_xid_rep == -1) {
         // scan for deletion candidates
@@ -700,24 +681,19 @@ rpcs::add_reply(unsigned int clt_nonce, int xid,
     }
 }
 
-void
-rpcs::free_reply_window(void)
-{
+void rpcs::free_reply_window(void) {
     lock rwl(reply_window_m_);
-    for (auto clt = reply_window_.begin(); clt != reply_window_.end(); clt++){
-        for (auto it = clt->second.begin(); it != clt->second.end(); it++){
-            if (it->cb_present)
-                free(it->buf);
+    for (auto clt : reply_window_) {
+        for (auto it : clt.second){
+            if (it.cb_present)
+                free(it.buf);
         }
-        clt->second.clear();
+        clt.second.clear();
     }
     reply_window_.clear();
 }
 
-// rpc handler
-int
-rpcs::rpcbind(unsigned int &r, int)
-{
+int rpcs::rpcbind(unsigned int &r, int) {
     jsl_log(JSL_DBG_2, "rpcs::rpcbind called return nonce %u\n", nonce_);
     r = nonce_;
     return 0;