}
}
-int RGWStreamIO::print(const char *format, ...)
+int RGWStreamIOBase::print(const char *format, ...)
{
#define LARGE_ENOUGH 128
int size = LARGE_ENOUGH;
/* 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;
calc_hash_sha256_update_stream(sha256_hash, buf, *actual);
}
- return 0;
+ return ret;
}
string RGWStreamIO::grab_aws4_sha256_hash()
#ifndef CEPH_RGW_CLIENT_IO_H
#define CEPH_RGW_CLIENT_IO_H
+#include <string>
#include <streambuf>
#include <istream>
#include <stdlib.h>
RGWEnv env;
virtual void init_env(CephContext *cct) = 0;
+ bool account() { return _account; }
public:
virtual ~RGWClientIO() {}
void init(CephContext *cct);
RGWEnv& get_env() { return env; }
- bool account() { return _account; }
void set_account(bool _accnt) {
_account = _accnt;
}
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; }