]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: make RGWRestfulIOEngine::Exception alias to std::system_error.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 3 Oct 2016 14:12:00 +0000 (16:12 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 21 Oct 2016 20:57:21 +0000 (22:57 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_asio_client.cc
src/rgw/rgw_civetweb.cc
src/rgw/rgw_client_io.cc
src/rgw/rgw_client_io.h
src/rgw/rgw_fcgi.cc
src/rgw/rgw_rest.cc

index 7b2dcf80decfb7eceee1410d878372e5ca487b6d..a274000e7738bb24fb5d15bc0782a0b9c7ee17b1 100644 (file)
@@ -85,7 +85,7 @@ std::size_t RGWAsioClientIO::write_data(const char* const buf,
   auto bytes = boost::asio::write(socket, boost::asio::buffer(buf, len), ec);
   if (ec) {
     derr << "write_data failed with " << ec.message() << dendl;
-    throw RGWRestfulIOEngine::Exception(-ec.value());
+    throw RGWRestfulIOEngine::Exception(ec.value(), std::system_category());
   }
   return bytes;
 }
index 68ea8f27bb0944e669e46d0e0a58b254a4c37dee..025ae04ad3a7f670cd7dfbb89d0576504c763219 100644 (file)
@@ -17,9 +17,9 @@ std::size_t RGWCivetWeb::write_data(const char *buf, std::size_t len)
   const int ret = mg_write(conn, buf, len);
   if (ret == 0) {
     /* didn't send anything, error out */
-    throw RGWRestfulIOEngine::Exception(-EIO);
+    throw RGWRestfulIOEngine::Exception(EIO, std::system_category());
   } else if (ret < 0) {
-    throw RGWRestfulIOEngine::Exception(ret);
+    throw RGWRestfulIOEngine::Exception(-ret, std::system_category());
   }
   return ret;
 }
@@ -36,7 +36,7 @@ std::size_t RGWCivetWeb::read_data(char *buf, std::size_t len)
 {
   const int ret = mg_read(conn, buf, len);
   if (ret < 0) {
-    throw RGWRestfulIOEngine::Exception(ret);
+    throw RGWRestfulIOEngine::Exception(-ret, std::system_category());
   }
   return ret;
 }
@@ -121,9 +121,9 @@ static inline std::size_t safe_mg_printf(Args&&... args)
   const int ret = mg_printf(std::forward<Args>(args)...);
   if (ret == 0) {
     /* didn't send anything, error out */
-    throw RGWRestfulIOEngine::Exception(-EIO);
+    throw RGWRestfulIOEngine::Exception(EIO, std::system_category());
   } else if (ret < 0) {
-    throw RGWRestfulIOEngine::Exception(ret);
+    throw RGWRestfulIOEngine::Exception(-ret, std::system_category());
   }
   return static_cast<std::size_t>(ret);
 }
index 39f429aabfe0d59ee078122738ebaaab39715944..745cfc03f143579fde768f1ac48d878f9105facc 100644 (file)
@@ -36,7 +36,7 @@ int RGWRestfulIO::recv_body(char *buf, std::size_t max, bool calculate_hash)
     }
     return sent;
   } catch (RGWRestfulIOEngine::Exception& e) {
-    return e.value();
+    return -e.code().value();
   }
 }
 
index 5ca3adbc226f815dd332566986b727712fa2603b..09ae4acc5068d6a02ba88192563938a567f5a4db 100644 (file)
@@ -9,6 +9,7 @@
 #include <streambuf>
 #include <istream>
 #include <stdlib.h>
+#include <system_error>
 
 #include <boost/utility/string_ref.hpp>
 
@@ -43,17 +44,7 @@ class RGWRestfulIOEngine : public RGWClientIO {
   template<typename T> friend class RGWDecoratedRestfulIO;
 
 public:
-  class Exception : public std::exception {
-    int err;
-  public:
-    Exception(const int err)
-      : err(err) {
-    }
-
-    int value() {
-      return err;
-    }
-  };
+  typedef std::system_error Exception;
 
   virtual std::size_t send_status(int status, const char *status_name) = 0;
   virtual std::size_t send_100_continue() = 0;
index d08635e61c86f632101ff13eb8f02e756104a1f6..78b36686f953763c59711ddf0bee685e3790e867 100644 (file)
@@ -2,14 +2,13 @@
 // vim: ts=8 sw=2 smarttab
 
 #include "rgw_fcgi.h"
-
 #include "acconfig.h"
 
 std::size_t RGWFCGX::write_data(const char* const buf, const std::size_t len)
 {
   const auto ret = FCGX_PutStr(buf, len, fcgx->out);
   if (ret < 0) {
-    throw RGWRestfulIOEngine::Exception(ret);
+    throw RGWRestfulIOEngine::Exception(-ret, std::system_category());
   }
   return ret;
 }
@@ -18,7 +17,7 @@ std::size_t RGWFCGX::read_data(char* const buf, const std::size_t len)
 {
   const auto ret = FCGX_GetStr(buf, len, fcgx->in);
   if (ret < 0) {
-    throw RGWRestfulIOEngine::Exception(ret);
+    throw RGWRestfulIOEngine::Exception(-ret, std::system_category());
   }
   return ret;
 }
index f5d6263fb21b843f092b77a0b10f9e249a2acb36..bc76e79f5d1d7a86ac990f23ea3a756b3894fa2e 100644 (file)
@@ -283,7 +283,7 @@ static void dump_status(struct req_state *s, int status,
     RESTFUL_IO(s)->send_status(status, status_name);
   } catch (RGWRestfulIOEngine::Exception& e) {
     ldout(s->cct, 0) << "ERROR: s->cio->send_status() returned err="
-                     << e.value() << dendl;
+                     << e.what() << dendl;
   }
 }
 
@@ -378,7 +378,7 @@ void dump_header(struct req_state* const s,
     RESTFUL_IO(s)->send_header(name, val);
   } catch (RGWRestfulIOEngine::Exception& e) {
     ldout(s->cct, 0) << "ERROR: s->cio->send_header() returned err="
-                     << e.value() << dendl;
+                     << e.what() << dendl;
   }
 }
 
@@ -417,7 +417,7 @@ void dump_content_length(struct req_state* const s, const uint64_t len)
     RESTFUL_IO(s)->send_content_length(len);
   } catch (RGWRestfulIOEngine::Exception& e) {
     ldout(s->cct, 0) << "ERROR: s->cio->send_content_length() returned err="
-                     << e.value() << dendl;
+                     << e.what() << dendl;
   }
   dump_header(s, "Accept-Ranges", "bytes");
 }
@@ -710,7 +710,7 @@ void end_header(struct req_state* s, RGWOp* op, const char *content_type,
     RESTFUL_IO(s)->complete_header();
   } catch (RGWRestfulIOEngine::Exception& e) {
     ldout(s->cct, 0) << "ERROR: RESTFUL_IO(s)->complete_header() returned err="
-                    << e.value() << dendl;
+                    << e.what() << dendl;
   }
 
   ACCOUNTING_IO(s)->set_account(true);
@@ -800,7 +800,7 @@ void dump_continue(struct req_state * const s)
     RESTFUL_IO(s)->send_100_continue();
   } catch (RGWRestfulIOEngine::Exception& e) {
     ldout(s->cct, 0) << "ERROR: RESTFUL_IO(s)->send_100_continue() returned err="
-                    << e.value() << dendl;
+                    << e.what() << dendl;
   }
 }
 
@@ -835,7 +835,7 @@ int dump_body(struct req_state* const s,
   try {
     return RESTFUL_IO(s)->send_body(buf, len);
   } catch (RGWRestfulIOEngine::Exception& e) {
-    return e.value();
+    return -e.code().value();
   }
 }
 
@@ -856,7 +856,7 @@ int recv_body(struct req_state* const s,
   try {
     return RESTFUL_IO(s)->recv_body(buf, max, s->aws4_auth_needs_complete);
   } catch (RGWRestfulIOEngine::Exception& e) {
-    return e.value();
+    return -e.code().value();
   }
 }