Repository: mesos
Updated Branches:
  refs/heads/master 93fb57f36 -> d785a1c54


Changed routing diagnosis socket state from enum to int so that they can
be bitwiseor'ed together.

Review: https://reviews.apache.org/r/26236


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d785a1c5
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d785a1c5
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d785a1c5

Branch: refs/heads/master
Commit: d785a1c5469e9dbdcdca918c865534dfebae30d1
Parents: 93fb57f
Author: Chi Zhang <[email protected]>
Authored: Wed Oct 1 12:07:02 2014 -0700
Committer: Jie Yu <[email protected]>
Committed: Wed Oct 1 12:07:02 2014 -0700

----------------------------------------------------------------------
 src/linux/routing/diagnosis/diagnosis.cpp |  6 ++--
 src/linux/routing/diagnosis/diagnosis.hpp | 49 +++++++++++++-------------
 src/tests/routing_tests.cpp               |  2 +-
 3 files changed, 30 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d785a1c5/src/linux/routing/diagnosis/diagnosis.cpp
----------------------------------------------------------------------
diff --git a/src/linux/routing/diagnosis/diagnosis.cpp 
b/src/linux/routing/diagnosis/diagnosis.cpp
index 36e4e2d..d826ae2 100644
--- a/src/linux/routing/diagnosis/diagnosis.cpp
+++ b/src/linux/routing/diagnosis/diagnosis.cpp
@@ -48,7 +48,7 @@ static Option<net::IP> IP(nl_addr* _ip)
 }
 
 
-Try<vector<Info> > infos(int family, State states)
+Try<vector<Info> > infos(int family, int states)
 {
   Try<Netlink<struct nl_sock> > sock = routing::socket(NETLINK_INET_DIAG);
   if (sock.isError()) {
@@ -68,9 +68,11 @@ Try<vector<Info> > infos(int family, State states)
        o != NULL; o = nl_cache_get_next(o)) {
     struct idiagnl_msg* msg = (struct idiagnl_msg*)o;
 
+    // For 'state', libnl-idiag only returns the number of left
+    // shifts. Convert it back to power-of-2 number.
     results.push_back(Info(
         idiagnl_msg_get_family(msg),
-        (State) idiagnl_msg_get_state(msg),
+        1 << idiagnl_msg_get_state(msg),
         idiagnl_msg_get_sport(msg),
         idiagnl_msg_get_dport(msg),
         IP(idiagnl_msg_get_src(msg)),

http://git-wip-us.apache.org/repos/asf/mesos/blob/d785a1c5/src/linux/routing/diagnosis/diagnosis.hpp
----------------------------------------------------------------------
diff --git a/src/linux/routing/diagnosis/diagnosis.hpp 
b/src/linux/routing/diagnosis/diagnosis.hpp
index aa1b3a3..2edde67 100644
--- a/src/linux/routing/diagnosis/diagnosis.hpp
+++ b/src/linux/routing/diagnosis/diagnosis.hpp
@@ -34,28 +34,28 @@ namespace diagnosis {
 
 namespace socket {
 
-// The connection state of a socket.
+namespace state {
+
+// The different connection states of a socket.
 // TODO(chzhcn): libnl3-idiag still uses the old idiag kernel API,
 // which only supports TCP sockets. When it moves to the newer API,
 // consider changing this to a per-family state structure.
-enum State
-{
-  UNKNOWN,
-  ESTABLISHED,
-  SYN_SENT,
-  SYN_RECV,
-  FIN_WAIT1,
-  FIN_WAIT2,
-  TIME_WAIT,
-  CLOSE,
-  CLOSE_WAIT,
-  LAST_ACK,
-  LISTEN,
-  CLOSING,
-  MAX,
-  ALL = (1 << MAX) - 1
-};
-
+const int UNKNOWN = 0;
+const int ESTABLISHED = 1 << 1;
+const int SYN_SENT = 1 << 2;
+const int SYN_RECV = 1 << 3;
+const int FIN_WAIT1 = 1 << 4;
+const int FIN_WAIT2 = 1 << 5;
+const int TIME_WAIT = 1 << 6;
+const int CLOSE = 1 << 7;
+const int CLOSE_WAIT = 1 << 8;
+const int LAST_ACK = 1 << 9;
+const int LISTEN = 1 << 10;
+const int CLOSING = 1 << 11;
+const int MAX = 1 << 12;
+const int ALL = MAX - 1;
+
+} // namespace state {
 
 // The diagnosis information of a socket. We only included a few
 // members of 'struct idiagnl_msg' from libnl3-idiag, but more could
@@ -64,7 +64,7 @@ class Info
 {
 public:
   Info(int _family,
-       State _state,
+       int _state,
        const Option<uint16_t>& _sourcePort,
        const Option<uint16_t>& _destinationPort,
        const Option<net::IP>& _sourceIP,
@@ -79,7 +79,7 @@ public:
       tcpInfo_(_tcpInfo) {}
 
   int family() const { return family_; }
-  State state() const { return state_; }
+  int state() const { return state_; }
   const Option<uint16_t>& sourcePort() const { return sourcePort_; }
   const Option<uint16_t>& destinationPort() const { return destinationPort_; }
   const Option<net::IP>& sourceIP() const { return sourceIP_; }
@@ -88,7 +88,7 @@ public:
 
 private:
   int family_;
-  State state_;
+  int state_;
 
   // sourcePort, destinationPort, sourceIP and destinationIP should
   // all be present because this version of kernel API that libnl3
@@ -107,11 +107,12 @@ private:
 
 
 // Return a list of socket information that matches the given protocol
-// family and socket state.
+// family and socket states. 'states' can accpet multiple states using
+// bitwise OR.
 // NOTE: 'family' is actually igored here because the older kernel
 // idiag API libnl3 uses only supports TCP and ingores this value. We
 // keep it here to follow libnl3-idiag's suit.
-Try<std::vector<Info> > infos(int familiy, State states);
+Try<std::vector<Info> > infos(int familiy, int states);
 
 } // namespace socket {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/d785a1c5/src/tests/routing_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/routing_tests.cpp b/src/tests/routing_tests.cpp
index 179f50b..4ef9fac 100644
--- a/src/tests/routing_tests.cpp
+++ b/src/tests/routing_tests.cpp
@@ -233,7 +233,7 @@ TEST_F(RoutingTest, Lo)
 TEST_F(RoutingTest, INETSockets)
 {
   Try<vector<diagnosis::socket::Info> > infos =
-    diagnosis::socket::infos(AF_INET, diagnosis::socket::State::ALL);
+    diagnosis::socket::infos(AF_INET, diagnosis::socket::state::ALL);
 
   EXPECT_SOME(infos);
 

Reply via email to