]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: introduce RGWStreamIOBase to separate all non-IO related things.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 26 Jul 2016 09:23:35 +0000 (11:23 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 21 Oct 2016 20:57:17 +0000 (22:57 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_client_io.cc
src/rgw/rgw_client_io.h

index b326a61b7faf0517ef7518ea7f310ad328f365bf..090636bbf90d338f4606eb2149d445f9fb51fb56 100644 (file)
@@ -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()
index 09cf332b1ecae46fbd24c1eb481f84f279517eb0..13cc6c7487b117d00ae9fb39c8cd498953e6f7c8 100644 (file)
@@ -4,6 +4,7 @@
 #ifndef CEPH_RGW_CLIENT_IO_H
 #define CEPH_RGW_CLIENT_IO_H
 
+#include <string>
 #include <streambuf>
 #include <istream>
 #include <stdlib.h>
@@ -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; }