From: Radoslaw Zarzynski Date: Tue, 26 Jul 2016 09:23:35 +0000 (+0200) Subject: rgw: introduce RGWStreamIOBase to separate all non-IO related things. X-Git-Tag: v11.1.0~454^2~64 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e4ee1d0329fe872a47ea94cb4679f2ffc4a2388d;p=ceph.git rgw: introduce RGWStreamIOBase to separate all non-IO related things. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_client_io.cc b/src/rgw/rgw_client_io.cc index b326a61b7faf..090636bbf90d 100644 --- a/src/rgw/rgw_client_io.cc +++ b/src/rgw/rgw_client_io.cc @@ -22,7 +22,7 @@ void RGWClientIO::init(CephContext *cct) { } } -int RGWStreamIO::print(const char *format, ...) +int RGWStreamIOBase::print(const char *format, ...) { #define LARGE_ENOUGH 128 int size = LARGE_ENOUGH; @@ -48,34 +48,51 @@ int RGWStreamIO::print(const char *format, ...) /* not reachable */ } -int RGWStreamIO::write(const char *buf, int len) +int RGWStreamIOBase::write(const char *buf, int len) { if (len == 0) { return 0; } - int ret = write_data(buf, len); - if (ret < 0) + const auto ret = write_data(buf, len); + if (ret < 0) { return ret; - - if (account()) - bytes_sent += ret; - - if (ret < len) { + } else if (ret < len) { /* sent less than tried to send, error out */ return -EIO; + } else { + return ret; } - - return 0; } -int RGWStreamIO::read(char *buf, int max, int *actual, bool hash /* = false */) +int RGWStreamIOBase::read(char *buf, int max, int *actual, bool hash /* = false */) { int ret = read_data(buf, max); - if (ret < 0) + if (ret < 0) { return ret; + } *actual = ret; + return 0; +} + +int RGWStreamIO::write(const char* const buf, const int len) +{ + const auto ret = RGWStreamIOBase::write(buf, len); + + if (ret >= 0 && account()) { + bytes_sent += ret; + } + + return ret; +} + +int RGWStreamIO::read(char *buf, int max, int *actual, bool hash /* = false */) +{ + int ret = RGWStreamIOBase::read(buf, max, actual, hash); + if (ret < 0) { + return ret; + } bytes_received += *actual; @@ -86,7 +103,7 @@ int RGWStreamIO::read(char *buf, int max, int *actual, bool hash /* = false */) calc_hash_sha256_update_stream(sha256_hash, buf, *actual); } - return 0; + return ret; } string RGWStreamIO::grab_aws4_sha256_hash() diff --git a/src/rgw/rgw_client_io.h b/src/rgw/rgw_client_io.h index 09cf332b1eca..13cc6c7487b1 100644 --- a/src/rgw/rgw_client_io.h +++ b/src/rgw/rgw_client_io.h @@ -4,6 +4,7 @@ #ifndef CEPH_RGW_CLIENT_IO_H #define CEPH_RGW_CLIENT_IO_H +#include #include #include #include @@ -19,6 +20,7 @@ protected: RGWEnv env; virtual void init_env(CephContext *cct) = 0; + bool account() { return _account; } public: virtual ~RGWClientIO() {} @@ -27,7 +29,6 @@ public: void init(CephContext *cct); RGWEnv& get_env() { return env; } - bool account() { return _account; } void set_account(bool _accnt) { _account = _accnt; } @@ -38,33 +39,43 @@ public: virtual uint64_t get_bytes_received() { return 0; } }; /* RGWClient IO */ -/* HTTP IO */ -class RGWStreamIO : public RGWClientIO { - - size_t bytes_sent; - size_t bytes_received; - - SHA256 *sha256_hash; - +class RGWStreamIOBase : public RGWClientIO { protected: virtual int write_data(const char *buf, int len) = 0; virtual int read_data(char *buf, int max) = 0; public: - virtual ~RGWStreamIO() {} - RGWStreamIO() : bytes_sent(0), bytes_received(0), sha256_hash(nullptr) {} - - int print(const char *format, ...); - int write(const char *buf, int len); + virtual int print(const char *format, ...); + virtual int write(const char *buf, int len); virtual void flush() = 0; - int read(char *buf, int max, int *actual, bool hash = false); - - string grab_aws4_sha256_hash(); + virtual int read(char *buf, int max, int *actual, bool hash = false); virtual int send_status(int status, const char *status_name) = 0; virtual int send_100_continue() = 0; virtual int complete_header() = 0; virtual int send_content_length(uint64_t len) = 0; +}; + + +/* HTTP IO */ +class RGWStreamIO : public RGWStreamIOBase { + size_t bytes_sent; + size_t bytes_received; + + SHA256 *sha256_hash; + +public: + virtual ~RGWStreamIO() {} + RGWStreamIO() + : bytes_sent(0), + bytes_received(0), + sha256_hash(nullptr) { + } + + int write(const char *buf, int len) override; + int read(char *buf, int max, int *actual, bool hash = false) override; + + std::string grab_aws4_sha256_hash(); uint64_t get_bytes_sent() { return bytes_sent; } uint64_t get_bytes_received() { return bytes_received; }