]> 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>
Fri, 10 May 2019 15:30:10 +0000 (17:30 +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>
(cherry picked from commit c149934f9cd287e2eee5816ec29f7dc737fe6f4f)

 Conflicts:
src/rgw/rgw_rest_conn.h
Conflicts due to optional_yield_context in master

src/rgw/rgw_rest_conn.h

index 8d82334747d4d8690de3cb4977a91c07d6f54938..1b45d6e5305b2fb7c3be7a28cbe5e2365c0d96d6 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) {
-    int ret = req.wait();
+  template <class E = std::nullptr_t>
+  int wait(bufferlist *pbl, 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>
   int wait(T *dest, E *err_result = nullptr);
 };
 
-template <class T, class E>
-int RGWRESTSendResource::decode_resource(T *dest, E *err_result)
+template <class T, class E=std::nullptr_t>
+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, E *err_result)
-{
-  int ret = req.wait();
-  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 {