]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/net: scoped enum for proto_type
authorYingxin Cheng <yingxincheng@gmail.com>
Mon, 1 Apr 2019 14:12:41 +0000 (22:12 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 5 Apr 2019 03:21:19 +0000 (11:21 +0800)
Signed-off-by: Yingxin Cheng <yingxincheng@gmail.com>
src/crimson/net/Protocol.cc
src/crimson/net/Protocol.h
src/crimson/net/ProtocolV1.cc
src/crimson/net/ProtocolV2.cc

index f509ec28ec284b54876e7f8450db1d12c4c528af..c2d9b67605a2cc0c629631034fe90636372c93dd 100644 (file)
@@ -17,7 +17,7 @@ namespace {
 
 namespace ceph::net {
 
-Protocol::Protocol(int type,
+Protocol::Protocol(proto_t type,
                    Dispatcher& dispatcher,
                    SocketConnection& conn)
   : proto_type(type),
index 5d4a39496b8bc97c68a6136191535240aaee5a27..55af5927055059fcc252ee127a0d0873e060306f 100644 (file)
@@ -13,6 +13,12 @@ namespace ceph::net {
 
 class Protocol {
  public:
+  enum class proto_t {
+    none,
+    v1,
+    v2
+  };
+
   Protocol(Protocol&&) = delete;
   virtual ~Protocol();
 
@@ -32,7 +38,7 @@ class Protocol {
                             const entity_addr_t& peer_addr) = 0;
 
  protected:
-  Protocol(int type,
+  Protocol(proto_t type,
            Dispatcher& dispatcher,
            SocketConnection& conn);
 
@@ -46,7 +52,7 @@ class Protocol {
   virtual seastar::future<> do_keepalive_ack() = 0;
 
  public:
-  const int proto_type;
+  const proto_t proto_type;
 
  protected:
   Dispatcher &dispatcher;
index 03fa8b7ef5b14bdb901b8636fe18910855cb9313..3730e236013635e86fde50280d73d183e100f942 100644 (file)
@@ -143,7 +143,7 @@ namespace ceph::net {
 ProtocolV1::ProtocolV1(Dispatcher& dispatcher,
                        SocketConnection& conn,
                        SocketMessenger& messenger)
-  : Protocol(1, dispatcher, conn), messenger{messenger} {}
+  : Protocol(proto_t::v1, dispatcher, conn), messenger{messenger} {}
 
 ProtocolV1::~ProtocolV1() {}
 
@@ -515,9 +515,10 @@ seastar::future<stop_t> ProtocolV1::repeat_handle_connect()
         return send_connect_reply(tag, std::move(authorizer_reply));
       }
       if (auto existing = messenger.lookup_conn(conn.peer_addr); existing) {
-        if (existing->protocol->proto_type != 1) {
+        if (existing->protocol->proto_type != proto_t::v1) {
           logger().warn("{} existing {} proto version is {} not 1, close existing",
-                        conn, *existing, existing->protocol->proto_type);
+                        conn, *existing,
+                        static_cast<int>(existing->protocol->proto_type));
           existing->close();
         } else {
           return handle_connect_with_existing(existing, std::move(authorizer_reply));
index da096a68664c1a2126651484b7ea8d276262388d..038733f57c793ac396cb01c0287b9fc97eca05e8 100644 (file)
@@ -62,7 +62,7 @@ namespace ceph::net {
 ProtocolV2::ProtocolV2(Dispatcher& dispatcher,
                        SocketConnection& conn,
                        SocketMessenger& messenger)
-  : Protocol(2, dispatcher, conn, messenger) {}
+  : Protocol(proto_t::v2, dispatcher, conn), messenger{messenger} {}
 
 ProtocolV2::~ProtocolV2() {}
 
@@ -1013,9 +1013,10 @@ seastar::future<bool> ProtocolV2::server_connect()
     SocketConnectionRef existing = messenger.lookup_conn(conn.peer_addr);
 
     if (existing) {
-      if (existing->protocol->proto_type != 2) {
+      if (existing->protocol->proto_type != proto_t::v2) {
         logger().warn("{} existing {} proto version is {}, close",
-                      conn, *existing, existing->protocol->proto_type);
+                      conn, *existing,
+                      static_cast<int>(existing->protocol->proto_type));
         // should unregister the existing from msgr atomically
         existing->close();
       } else {
@@ -1104,9 +1105,11 @@ seastar::future<bool> ProtocolV2::server_reconnect()
       return send_reset(true);
     }
 
-    if (existing->protocol->proto_type != 2) {
+    if (existing->protocol->proto_type != proto_t::v2) {
       logger().warn("{} server_reconnect: existing {} proto version is {},"
-                    "close existing and resetting client.", conn, *existing);
+                    "close existing and resetting client.",
+                    conn, *existing,
+                    static_cast<int>(existing->protocol->proto_type));
       existing->close();
       return send_reset(true);
     }