From: Radoslaw Zarzynski Date: Mon, 3 Oct 2016 14:12:00 +0000 (+0200) Subject: rgw: make RGWRestfulIOEngine::Exception alias to std::system_error. X-Git-Tag: v11.1.0~454^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dad4d16a22e8f5f4bc29159356dc8d1ef788e867;p=ceph.git rgw: make RGWRestfulIOEngine::Exception alias to std::system_error. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_asio_client.cc b/src/rgw/rgw_asio_client.cc index 7b2dcf80dec..a274000e773 100644 --- a/src/rgw/rgw_asio_client.cc +++ b/src/rgw/rgw_asio_client.cc @@ -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; } diff --git a/src/rgw/rgw_civetweb.cc b/src/rgw/rgw_civetweb.cc index 68ea8f27bb0..025ae04ad3a 100644 --- a/src/rgw/rgw_civetweb.cc +++ b/src/rgw/rgw_civetweb.cc @@ -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)...); 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(ret); } diff --git a/src/rgw/rgw_client_io.cc b/src/rgw/rgw_client_io.cc index 39f429aabfe..745cfc03f14 100644 --- a/src/rgw/rgw_client_io.cc +++ b/src/rgw/rgw_client_io.cc @@ -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(); } } diff --git a/src/rgw/rgw_client_io.h b/src/rgw/rgw_client_io.h index 5ca3adbc226..09ae4acc506 100644 --- a/src/rgw/rgw_client_io.h +++ b/src/rgw/rgw_client_io.h @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -43,17 +44,7 @@ class RGWRestfulIOEngine : public RGWClientIO { template 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; diff --git a/src/rgw/rgw_fcgi.cc b/src/rgw/rgw_fcgi.cc index d08635e61c8..78b36686f95 100644 --- a/src/rgw/rgw_fcgi.cc +++ b/src/rgw/rgw_fcgi.cc @@ -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; } diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index f5d6263fb21..bc76e79f5d1 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -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(); } }