]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/net: remove duplicated error codes and conditions 32632/head
authorYingxin Cheng <yingxin.cheng@intel.com>
Mon, 10 Feb 2020 09:00:31 +0000 (17:00 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Mon, 17 Feb 2020 06:18:30 +0000 (14:18 +0800)
The duplicated error codes and conditions were originally introduced to
match connection errors with both system category (thrown by seastar)
and generic category (thrown by standard library).  Since error_code
with system category can be matched by error_condition with generic
category (see std::errc and
system_error_category::default_error_condition(int)), our duplicated
counterparts are not needed actually.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/net/Errors.cc
src/crimson/net/Errors.h
src/crimson/net/Protocol.cc
src/crimson/net/ProtocolV1.cc
src/crimson/net/Socket.cc
src/crimson/net/Socket.h
src/crimson/net/SocketMessenger.cc
src/test/crimson/test_socket.cc

index bc92bc75d3695ad0c68f0795620e297ac2b3f008..d07c090db737a60d275e0c7661cbf797bdc81d43 100644 (file)
@@ -35,104 +35,14 @@ const std::error_category& net_category()
           return "negotiation failure";
         case error::read_eof:
           return "read eof";
-        case error::connection_aborted:
-          return "connection aborted";
-        case error::connection_refused:
-          return "connection refused";
-        case error::connection_reset:
-          return "connection reset";
         case error::corrupted_message:
           return "corrupted message";
-        case error::invalid_argument:
-          return "invalid argument";
-        case error::address_in_use:
-          return "address in use";
-        case error::broken_pipe:
-          return "broken pipe";
         case error::protocol_aborted:
           return "protocol aborted";
         default:
           return "unknown";
       }
     }
-
-    // unfortunately, seastar throws connection errors with the system category,
-    // rather than the generic category that would match their counterparts
-    // in std::errc. we add our own errors for them, so we can match either
-    std::error_condition default_error_condition(int ev) const noexcept override {
-      switch (static_cast<error>(ev)) {
-        case error::connection_aborted:
-          return std::errc::connection_aborted;
-        case error::connection_refused:
-          return std::errc::connection_refused;
-        case error::connection_reset:
-          return std::errc::connection_reset;
-        case error::invalid_argument:
-          return std::errc::invalid_argument;
-        case error::address_in_use:
-          return std::errc::address_in_use;
-        case error::broken_pipe:
-          return std::errc::broken_pipe;
-        default:
-          return std::error_condition(ev, *this);
-      }
-    }
-
-    bool equivalent(int code, const std::error_condition& cond) const noexcept override {
-      if (error_category::equivalent(code, cond)) {
-        return true;
-      }
-      switch (static_cast<error>(code)) {
-        case error::connection_aborted:
-          return cond == std::errc::connection_aborted
-              || cond == std::error_condition(ECONNABORTED, std::system_category());
-        case error::connection_refused:
-          return cond == std::errc::connection_refused
-              || cond == std::error_condition(ECONNREFUSED, std::system_category());
-        case error::connection_reset:
-          return cond == std::errc::connection_reset
-              || cond == std::error_condition(ECONNRESET, std::system_category());
-        case error::invalid_argument:
-          return cond == std::errc::invalid_argument
-              || cond == std::error_condition(EINVAL, std::system_category());
-        case error::address_in_use:
-          return cond == std::errc::address_in_use
-              || cond == std::error_condition(EADDRINUSE, std::system_category());
-        case error::broken_pipe:
-          return cond == std::errc::broken_pipe
-              || cond == std::error_condition(EPIPE, std::system_category());
-        default:
-          return false;
-      }
-    }
-
-    bool equivalent(const std::error_code& code, int cond) const noexcept override {
-      if (error_category::equivalent(code, cond)) {
-        return true;
-      }
-      switch (static_cast<error>(cond)) {
-        case error::connection_aborted:
-          return code == std::errc::connection_aborted
-              || code == std::error_code(ECONNABORTED, std::system_category());
-        case error::connection_refused:
-          return code == std::errc::connection_refused
-              || code == std::error_code(ECONNREFUSED, std::system_category());
-        case error::connection_reset:
-          return code == std::errc::connection_reset
-              || code == std::error_code(ECONNRESET, std::system_category());
-        case error::invalid_argument:
-          return code == std::errc::invalid_argument
-              || code == std::error_code(EINVAL, std::system_category());
-        case error::address_in_use:
-          return code == std::errc::address_in_use
-              || code == std::error_code(EADDRINUSE, std::system_category());
-        case error::broken_pipe:
-          return code == std::errc::broken_pipe
-              || code == std::error_code(EPIPE, std::system_category());
-        default:
-          return false;
-      }
-    }
   };
   static category instance;
   return instance;
index 0957517b0085e40f36c952dfe8766917c5987613..3a17a103a1982525ebe4489762d5f07d6c35201d 100644 (file)
@@ -25,13 +25,7 @@ enum class error {
   bad_peer_address,
   negotiation_failure,
   read_eof,
-  connection_aborted,
-  connection_refused,
-  connection_reset,
   corrupted_message,
-  invalid_argument,
-  address_in_use,
-  broken_pipe,
   protocol_aborted,
 };
 
index 10e232a7eca2daafd8db27035e885d2e030829a1..bf2633c1c221444988580273351ff48fb44b53c8 100644 (file)
@@ -257,8 +257,8 @@ seastar::future<> Protocol::do_write_dispatch_sweep()
       ceph_assert(false);
     }
   }).handle_exception_type([this] (const std::system_error& e) {
-    if (e.code() != error::broken_pipe &&
-        e.code() != error::connection_reset &&
+    if (e.code() != std::errc::broken_pipe &&
+        e.code() != std::errc::connection_reset &&
         e.code() != error::negotiation_failure) {
       logger().error("{} write_event(): unexpected error at {} -- {}",
                      conn, get_state_name(write_state), e);
index e079a290916353c1863c946b31b7fe825e729c3b..3eac0d2c924312a4e7b82015901206de077ba537 100644 (file)
@@ -324,7 +324,7 @@ void ProtocolV1::start_connect(const entity_addr_t& _peer_addr,
           socket = std::move(sock);
           if (state == state_t::closing) {
             return socket->close().then([] {
-              throw std::system_error(make_error_code(error::connection_aborted));
+              throw std::system_error(make_error_code(error::protocol_aborted));
             });
           }
           return seastar::now();
@@ -878,7 +878,7 @@ seastar::future<> ProtocolV1::handle_tags()
             return handle_keepalive2_ack();
           case CEPH_MSGR_TAG_CLOSE:
             logger().info("{} got tag close", conn);
-            throw std::system_error(make_error_code(error::connection_aborted));
+            throw std::system_error(make_error_code(error::protocol_aborted));
           default:
             logger().error("{} got unknown msgr tag {}",
                            conn, static_cast<int>(buf[0]));
@@ -899,8 +899,8 @@ void ProtocolV1::execute_open()
       return handle_tags()
         .handle_exception_type([this] (const std::system_error& e) {
           logger().warn("{} open fault: {}", conn, e);
-          if (e.code() == error::connection_aborted ||
-              e.code() == error::connection_reset) {
+          if (e.code() == error::protocol_aborted ||
+              e.code() == std::errc::connection_reset) {
             return dispatcher.ms_handle_reset(
                 seastar::static_pointer_cast<SocketConnection>(conn.shared_from_this()))
               .then([this] {
index 86b5f6752cc08e16df31b153db0cb7dbe809f6d5..75c215bf144f270f1be8c70f8a0e205701ad1bba 100644 (file)
@@ -115,8 +115,8 @@ static inline seastar::future<>
 close_and_handle_errors(seastar::output_stream<char>& out)
 {
   return out.close().handle_exception_type([] (const std::system_error& e) {
-    if (e.code() != error::broken_pipe &&
-        e.code() != error::connection_reset) {
+    if (e.code() != std::errc::broken_pipe &&
+        e.code() != std::errc::connection_reset) {
       logger().error("Socket::close(): unexpected error {}", e);
       ceph_abort();
     }
index 2123136bdda28d2c6b6a703624adb961084a67c9..c97554f50bab7c4c34f6ab85aec5b6b142e93a92 100644 (file)
@@ -178,7 +178,7 @@ public:
       lo.set_fixed_cpu(ss.cpu);
       ss.listener = seastar::listen(s_addr, lo);
     }).handle_exception_type([addr] (const std::system_error& e) {
-      if (e.code() == error::address_in_use) {
+      if (e.code() == std::errc::address_in_use) {
         logger().trace("FixedCPUServerSocket::listen({}): address in use", addr);
         throw;
       } else {
@@ -230,8 +230,8 @@ public:
             });
           });
         }).handle_exception_type([&ss] (const std::system_error& e) {
-          if (e.code() == error::connection_aborted ||
-              e.code() == error::invalid_argument) {
+          if (e.code() == std::errc::connection_aborted ||
+              e.code() == std::errc::invalid_argument) {
             logger().trace("FixedCPUServerSocket({})::accept(): stopped ({})",
                            ss.addr, e);
           } else {
index 807511712f017617b23e265754688594a9bea6ff..423e7d4edc987303681b0acb98945b958bb69a09 100644 (file)
@@ -99,7 +99,7 @@ SocketMessenger::try_bind(const entity_addrvec_t& addrs,
         logger().info("{} try_bind: done", *this);
         return stop_t::yes;
       }).handle_exception_type([this, max_port, &port] (const std::system_error& e) {
-        assert(e.code() == error::address_in_use);
+        assert(e.code() == std::errc::address_in_use);
         logger().trace("{} try_bind: {} already used", *this, port);
         if (port == max_port) {
           throw;
index 3810f4fd072915f80fc7666746d5bc84dee465cc..cb44373f8de58e2966c3003981a0a1c357cbba07 100644 (file)
@@ -43,7 +43,7 @@ future<> test_refused() {
   return socket_connect().discard_result().then([] {
     ceph_abort_msg("connection is not refused");
   }).handle_exception_type([] (const std::system_error& e) {
-    if (e.code() != error::connection_refused) {
+    if (e.code() != std::errc::connection_refused) {
       logger.error("test_refused() got unexpeted error {}", e);
       ceph_abort();
     } else {
@@ -69,7 +69,7 @@ future<> test_bind_same() {
         }).finally([pss2] {
           return pss2->destroy();
         }).handle_exception_type([] (const std::system_error& e) {
-          if (e.code() != error::address_in_use) {
+          if (e.code() != std::errc::address_in_use) {
             logger.error("test_bind_same() got unexpeted error {}", e);
             ceph_abort();
           } else {
@@ -246,8 +246,8 @@ class Connection {
     ).then([] {
       ceph_abort();
     }).handle_exception_type([this] (const std::system_error& e) {
-      if (e.code() != error::broken_pipe &&
-          e.code() != error::connection_reset) {
+      if (e.code() != std::errc::broken_pipe &&
+          e.code() != std::errc::connection_reset) {
         logger.error("dispatch_write_unbounded(): "
                      "unexpected error {}", e);
         throw;
@@ -305,7 +305,7 @@ class Connection {
       ceph_abort();
     }).handle_exception_type([this] (const std::system_error& e) {
       if (e.code() != error::read_eof
-       && e.code() != error::connection_reset) {
+       && e.code() != std::errc::connection_reset) {
         logger.error("dispatch_read_unbounded(): "
                      "unexpected error {}", e);
         throw;