}
-int RGWStreamIOLegacyWrapper::recv_body(char *buf, std::size_t max, bool calculate_hash)
+int RGWStreamIO::recv_body(char *buf, std::size_t max, bool calculate_hash)
{
- const auto len = recv_body(buf, max);
-
- if (len >= 0 && calculate_hash) {
- if (!sha256_hash) {
- sha256_hash = calc_hash_sha256_open_stream();
+ try {
+ const auto sent = recv_body(buf, max);
+
+ if (calculate_hash) {
+ if (! sha256_hash) {
+ sha256_hash = calc_hash_sha256_open_stream();
+ }
+ calc_hash_sha256_update_stream(sha256_hash, buf, sent);
}
- calc_hash_sha256_update_stream(sha256_hash, buf, len);
+ return sent;
+ } catch (RGWStreamIOEngine::Exception& e) {
+ return e.value();
}
-
- return len;
}
string RGWStreamIO::grab_aws4_sha256_hash()
class RGWStreamIOEngine : public RGWClientIO {
friend class RGWStreamIOLegacyWrapper;
+ template<typename T> friend class RGWDecoratedStreamIO;
public:
class Exception : public std::exception {
/* HTTP IO: compatibility layer */
-class RGWStreamIO : public RGWClientIO,
- public RGWClientIOAccounter {
+class RGWStreamIO : public RGWClientIOAccounter,
+ public RGWDecoratedStreamIO<RGWStreamIOEngine*> {
protected:
bool _account;
size_t bytes_sent;
RGWEnv env;
public:
- virtual int send_status(int status, const char *status_name) = 0;
- virtual int send_100_continue() = 0;
- virtual std::size_t send_header(const boost::string_ref& name,
- const boost::string_ref& value) noexcept = 0;
- virtual int send_content_length(uint64_t len) = 0;
- virtual int send_chunked_transfer_encoding() = 0;
- virtual int complete_header() = 0;
-
- virtual int recv_body(char* buf, std::size_t max) = 0;
- virtual int recv_body(char* buf, std::size_t max, bool calculate_hash) = 0;
- virtual int send_body(const char* buf, std::size_t len) = 0;
- virtual void flush() = 0;
-
virtual ~RGWStreamIO() {}
- RGWStreamIO()
- : _account(false),
+ RGWStreamIO(RGWStreamIOEngine* engine)
+ : RGWDecoratedStreamIO<RGWStreamIOEngine*>(std::move(engine)),
+ _account(false),
bytes_sent(0),
bytes_received(0),
sha256_hash(nullptr) {
}
+ using RGWDecoratedStreamIO<RGWStreamIOEngine*>::recv_body;
+ virtual int recv_body(char* buf, std::size_t max, bool calculate_hash);
std::string grab_aws4_sha256_hash();
RGWEnv& get_env() noexcept override {
* from RGWDecoratedStreamIO<> to avoid using virtual inheritance in engine.
* Should be removed after converting all clients. */
class RGWStreamIOLegacyWrapper : public RGWStreamIO {
- RGWStreamIOEngine * const engine;
-
- RGWStreamIOEngine& get_decoratee() {
- return *engine;
- }
-
-#define EXCPT_TO_RC(code) \
- try { \
- return code; \
- } catch (RGWStreamIOEngine::Exception& e) { \
- return e.value(); \
- }
-
-#define EXCPT_TO_VOID(code) \
- try { \
- return code; \
- } catch (RGWStreamIOEngine::Exception& e) { \
- return; \
- }
-
-protected:
- void init_env(CephContext *cct) override {
- EXCPT_TO_VOID(get_decoratee().init_env(cct));
- }
-
public:
RGWStreamIOLegacyWrapper(RGWStreamIOEngine * const engine)
- : engine(engine) {
- }
-
- int send_status(const int status, const char* const status_name) override {
- EXCPT_TO_RC(get_decoratee().send_status(status, status_name));
- }
-
- std::size_t send_header(const boost::string_ref& name,
- const boost::string_ref& value) noexcept override {
- EXCPT_TO_RC(get_decoratee().send_header(name, value));
- }
-
- int send_100_continue() override {
- EXCPT_TO_RC(get_decoratee().send_100_continue());
- }
-
- int send_content_length(const uint64_t len) override {
- EXCPT_TO_RC(get_decoratee().send_content_length(len));
- }
-
- int send_chunked_transfer_encoding() override {
- EXCPT_TO_RC(get_decoratee().send_chunked_transfer_encoding());
- }
-
- int complete_header() override {
- EXCPT_TO_RC(get_decoratee().complete_header());
- }
-
- int recv_body(char* buf, const std::size_t max) override {
- EXCPT_TO_RC(get_decoratee().recv_body(buf, max));
- }
-
- int recv_body(char* buf, std::size_t max, bool calculate_hash) override;
-
- int send_body(const char* const buf, const std::size_t len) override {
- EXCPT_TO_RC(get_decoratee().send_body(buf, len));
- }
-
-
- void flush() override {
- EXCPT_TO_VOID(get_decoratee().flush());
- }
-
- RGWEnv& get_env() noexcept override {
- return get_decoratee().get_env();
- }
-
- int complete_request() override {
- EXCPT_TO_RC(get_decoratee().complete_request());
+ : RGWStreamIO(std::move(engine)) {
}
};
const char *status_name)
{
s->formatter->set_status(status, status_name);
- int r = STREAM_IO(s)->send_status(status, status_name);
- if (r < 0) {
- ldout(s->cct, 0) << "ERROR: s->cio->send_status() returned err=" << r
- << dendl;
+ try {
+ STREAM_IO(s)->send_status(status, status_name);
+ } catch (RGWStreamIOEngine::Exception& e) {
+ ldout(s->cct, 0) << "ERROR: s->cio->send_status() returned err="
+ << e.value() << dendl;
}
}
const boost::string_ref& name,
const boost::string_ref& val)
{
- const int r = STREAM_IO(s)->send_header(name, val);
- if (r < 0) {
+ try {
+ STREAM_IO(s)->send_header(name, val);
+ } catch (RGWStreamIOEngine::Exception& e) {
ldout(s->cct, 0) << "ERROR: s->cio->send_header() returned err="
- << r << dendl;
+ << e.value() << dendl;
}
}
void dump_content_length(struct req_state* const s, const uint64_t len)
{
- int r = STREAM_IO(s)->send_content_length(len);
- if (r < 0) {
+ try {
+ STREAM_IO(s)->send_content_length(len);
+ } catch (RGWStreamIOEngine::Exception& e) {
ldout(s->cct, 0) << "ERROR: s->cio->send_content_length() returned err="
- << r << dendl;
+ << e.value() << dendl;
}
dump_header(s, "Accept-Ranges", "bytes");
}
if (content_type) {
dump_header(s, "Content-Type", content_type);
}
- int r = STREAM_IO(s)->complete_header();
- if (r < 0) {
+
+ try {
+ STREAM_IO(s)->complete_header();
+ } catch (RGWStreamIOEngine::Exception& e) {
ldout(s->cct, 0) << "ERROR: STREAM_IO(s)->complete_header() returned err="
- << r << dendl;
+ << e.value() << dendl;
}
STREAM_IO(s)->set_account(true);
perfcounter->inc(l_rgw_failed_req);
}
-void dump_continue(struct req_state *s)
+void dump_continue(struct req_state * const s)
{
- STREAM_IO(s)->send_100_continue();
+ try {
+ STREAM_IO(s)->send_100_continue();
+ } catch (RGWStreamIOEngine::Exception& e) {
+ ldout(s->cct, 0) << "ERROR: STREAM_IO(s)->send_100_continue() returned err="
+ << e.value() << dendl;
+ }
}
void dump_range(struct req_state* const s,
const char* const buf,
const std::size_t len)
{
- return STREAM_IO(s)->send_body(buf, len);
+ try {
+ return STREAM_IO(s)->send_body(buf, len);
+ } catch (RGWStreamIOEngine::Exception& e) {
+ return e.value();
+ }
}
int dump_body(struct req_state* const s, /* const */ ceph::buffer::list& bl)
char* const buf,
const std::size_t max)
{
- return STREAM_IO(s)->recv_body(buf, max, s->aws4_auth_needs_complete);
+ try {
+ return STREAM_IO(s)->recv_body(buf, max, s->aws4_auth_needs_complete);
+ } catch (RGWStreamIOEngine::Exception& e) {
+ return e.value();
+ }
}
int RGWGetObj_ObjStore::get_params()