From: Abhishek Lekshmanan Date: Thu, 18 Apr 2019 13:05:41 +0000 (+0200) Subject: rgw: rest_conn: wait bl takes an optional error template X-Git-Tag: v15.1.0~2709^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c149934f9cd287e2eee5816ec29f7dc737fe6f4f;p=ceph.git rgw: rest_conn: wait bl takes an optional error template 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 --- diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index 5bc0728b636d..af4ad0c07c75 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -410,9 +410,6 @@ public: return req.get_io_user_info(); } - template - 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 + 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) { + if (err_result) { + ret = parse_decode_json(*err_result, bl); + } + } } - return 0; + + return ret; } - template + template int wait(T *dest, optional_yield y, E *err_result = nullptr); }; template -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) { + if (ret <0 && err_result) { + ret = parse_decode_json(*err_result, bl); + } } - return 0; -} -template -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 {