]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rest_conn: wait bl takes an optional error template
authorAbhishek Lekshmanan <abhishek@suse.com>
Thu, 18 Apr 2019 13:05:41 +0000 (15:05 +0200)
committerAbhishek Lekshmanan <abhishek@suse.com>
Thu, 18 Apr 2019 13:05:41 +0000 (15:05 +0200)
This allows for functions that require a bufferlist but might have a json error
response to take this path. Also dropped decode_resource and wait using the json
template arguments itself performs both the functions.

Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
src/rgw/rgw_rest_conn.h

index 5bc0728b636d4591aaaaa8df902cc67677f24dd3..af4ad0c07c754d67099ccaf6cc05d878d34e84f9 100644 (file)
@@ -410,9 +410,6 @@ public:
     return req.get_io_user_info();
   }
 
-  template <class T, class E>
-  int decode_resource(T *dest, E *err_result);
-
   int send(bufferlist& bl);
 
   int aio_send(bufferlist& bl);
@@ -425,61 +422,54 @@ public:
     return req.get_http_status();
   }
 
-  int wait(bufferlist *pbl, optional_yield y) {
+  template <class E = std::nullptr_t>
+  int wait(bufferlist *pbl, optional_yield y, E *err_result = nullptr) {
     int ret = req.wait(y);
     *pbl = bl;
-    if (ret < 0) {
-      return ret;
+
+    if (ret >=0) {
+      ret = req.get_status();
     }
 
-    if (req.get_status() < 0) {
-      return req.get_status();
+    if (ret < 0) {
+      if constexpr (!std::is_same_v<E, std::nullptr_t>) {
+        if (err_result) {
+          ret = parse_decode_json(*err_result, bl);
+        }
+      }
     }
-    return 0;
+
+    return ret;
   }
 
-  template <class T, class E = int>
+  template <class T, class E = std::nullptr_t>
   int wait(T *dest, optional_yield y, E *err_result = nullptr);
 };
 
 template <class T, class E>
-int RGWRESTSendResource::decode_resource(T *dest, E *err_result)
+int RGWRESTSendResource::wait(T *dest, optional_yield y, E *err_result)
 {
-  int ret = req.get_status();
-  if (ret < 0) {
-    if (err_result) {
-      parse_decode_json(*err_result, bl);
-    }
-    return ret;
-  }
-
-  if (!dest) {
-    return 0;
+  int ret = req.wait(y);
+  if (ret >=0) {
+    ret = req.get_status();
   }
 
-  ret = parse_decode_json(*dest, bl);
-  if (ret < 0) {
-    return ret;
+  if constexpr (!std::is_same_v<E, std::nullptr_t>) {
+    if (ret <0 && err_result) {
+      ret = parse_decode_json(*err_result, bl);
+    }
   }
-  return 0;
-}
 
-template <class T, class E>
-int RGWRESTSendResource::wait(T *dest, optional_yield y, E *err_result)
-{
-  int ret = req.wait(y);
-  if (ret < 0) {
-    if (err_result) {
-      parse_decode_json(*err_result, bl);
-    }
+  if (ret < 0){
     return ret;
   }
 
-  ret = decode_resource(dest, err_result);
+  ret = parse_decode_json(*dest, bl);
   if (ret < 0) {
     return ret;
   }
   return 0;
+
 }
 
 class RGWRESTPostResource : public RGWRESTSendResource {