Cleanups
[invirt/third/libt4.git] / rpc / rpc.h
index 245f277..c0420a5 100644 (file)
--- a/rpc/rpc.h
+++ b/rpc/rpc.h
@@ -27,12 +27,6 @@ class rpc_const {
         static const int cancel_failure = -7;
 };
 
-struct ReturnOnFailure {
-    static inline int unmarshall_args_failure() {
-        return rpc_const::unmarshal_args_failure;
-    }
-};
-
 // rpc client endpoint.
 // manages a xid space per destination socket
 // threaded: multiple threads can be sending RPCs,
@@ -42,10 +36,10 @@ class rpcc : public chanmgr {
 
         //manages per rpc info
         struct caller {
-            caller(unsigned int xxid, unmarshall *un);
+            caller(int xxid, unmarshall *un);
             ~caller();
 
-            unsigned int xid;
+            int xid;
             unmarshall *un;
             int intret;
             bool done;
@@ -54,14 +48,14 @@ class rpcc : public chanmgr {
         };
 
         void get_refconn(connection **ch);
-        void update_xid_rep(unsigned int xid);
+        void update_xid_rep(int xid);
 
 
         sockaddr_in dst_;
         unsigned int clt_nonce_;
         unsigned int srv_nonce_;
         bool bind_done_;
-        unsigned int xid_;
+        int xid_;
         int lossytest_;
         bool retrans_;
         bool reachable_;
@@ -75,17 +69,17 @@ class rpcc : public chanmgr {
         std::condition_variable destroy_wait_c_;
 
         std::map<int, caller *> calls_;
-        std::list<unsigned int> xid_rep_window_;
-                
-                struct request {
-                    request() { clear(); }
-                    void clear() { buf.clear(); xid = -1; }
-                    bool isvalid() { return xid != -1; }
-                    std::string buf;
-                    int xid;
-                };
-                struct request dup_req_;
-                int xid_rep_done_;
+        std::list<int> xid_rep_window_;
+
+        struct request {
+            request() { clear(); }
+            void clear() { buf.clear(); xid = -1; }
+            bool isvalid() { return xid != -1; }
+            std::string buf;
+            int xid;
+        };
+        struct request dup_req_;
+        int xid_rep_done_;
     public:
 
         rpcc(sockaddr_in d, bool retrans=true);
@@ -111,7 +105,7 @@ class rpcc : public chanmgr {
         int call1(unsigned int proc, 
                 marshall &req, unmarshall &rep, TO to);
 
-        bool got_pdu(connection *c, char *b, int sz);
+        bool got_pdu(connection *c, char *b, size_t sz);
 
 
         template<class R>
@@ -173,25 +167,25 @@ 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 (unsigned int _xid) {
+        reply_t (int _xid) {
             xid = _xid;
             cb_present = false;
             buf = NULL;
             sz = 0;
         }
-        reply_t (unsigned int _xid, char *_buf, int _sz) {
+        reply_t (int _xid, char *_buf, size_t _sz) {
             xid = _xid;
             cb_present = true;
             buf = _buf;
             sz = _sz;
         }
-        unsigned int xid;
+        int xid;
         bool cb_present; // whether the reply buffer is valid
         char *buf;      // the reply buffer
-        int sz;         // the size of reply buffer
+        size_t sz;         // the size of reply buffer
     };
 
-    int port_;
+    unsigned int port_;
     unsigned int nonce_;
 
     // provide at most once semantics by maintaining a window of replies
@@ -200,11 +194,11 @@ class rpcs : public chanmgr {
     std::map<unsigned int, std::list<reply_t> > reply_window_;
 
     void free_reply_window(void);
-    void add_reply(unsigned int clt_nonce, unsigned int xid, char *b, int sz);
+    void add_reply(unsigned int clt_nonce, int xid, char *b, size_t sz);
 
     rpcstate_t checkduplicate_and_update(unsigned int clt_nonce, 
-            unsigned int xid, unsigned int rep_xid,
-            char **b, int *sz);
+            int xid, int rep_xid,
+            char **b, size_t *sz);
 
     void updatestat(unsigned int proc);
 
@@ -212,15 +206,15 @@ class rpcs : public chanmgr {
     std::map<unsigned int, connection *> conns_;
 
     // counting
-    const int counting_;
-    int curr_counts_;
-    std::map<int, int> counts_;
+    const size_t counting_;
+    size_t curr_counts_;
+    std::map<unsigned int, size_t> counts_;
 
     int lossytest_; 
     bool reachable_;
 
     // map proc # to function
-    std::map<int, handler *> procs_;
+    std::map<unsigned int, handler *> procs_;
 
     std::mutex procs_m_; // protect insert/delete to procs[]
     std::mutex count_m_;  //protect modification of counts
@@ -231,9 +225,9 @@ class rpcs : public chanmgr {
     protected:
 
     struct djob_t {
-        djob_t (connection *c, char *b, int bsz):buf(b),sz(bsz),conn(c) {}
+        djob_t (connection *c, char *b, size_t bsz):buf(b),sz(bsz),conn(c) {}
         char *buf;
-        int sz;
+        size_t sz;
         connection *conn;
     };
     void dispatch(djob_t *);
@@ -245,25 +239,31 @@ class rpcs : public chanmgr {
     tcpsconn* listener_;
 
     public:
-    rpcs(unsigned int port, int counts=0);
+    rpcs(unsigned int port, size_t counts=0);
     ~rpcs();
-    inline int port() { return listener_->port(); }
+    inline unsigned int port() { return listener_->port(); }
     //RPC handler for clients binding
-    int rpcbind(int &r, int a);
+    int rpcbind(unsigned int &r, int a);
 
     void set_reachable(bool r) { reachable_ = r; }
 
-    bool got_pdu(connection *c, char *b, int sz);
+    bool got_pdu(connection *c, char *b, size_t sz);
 
     template<class F, class C=void> void reg(unsigned int proc, F f, C *c=nullptr);
 };
 
+struct ReturnOnFailure {
+    static inline int unmarshall_args_failure() {
+        return rpc_const::unmarshal_args_failure;
+    }
+};
+
 template<class F, class C> void rpcs::reg(unsigned int proc, F f, C *c) {
-    reg1(proc, marshalled_func<F, F, ReturnOnFailure>::wrap(f, c));
+    reg1(proc, marshalled_func<F, ReturnOnFailure>::wrap(f, c));
 }
 
-void make_sockaddr(const char *hostandport, struct sockaddr_in *dst);
-void make_sockaddr(const char *host, const char *port,
-        struct sockaddr_in *dst);
+void make_sockaddr(const std::string &hostandport, struct sockaddr_in *dst);
+void make_sockaddr(const std::string &host, const std::string &port, struct
+        sockaddr_in *dst);
 
 #endif