Skip to content

Commit

Permalink
rgw: rest_conn: wait bl takes an optional error template
Browse files Browse the repository at this point in the history
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 c149934)

 Conflicts:
	src/rgw/rgw_rest_conn.h
Conflicts due to optional_yield_context in master
  • Loading branch information
theanalyst committed May 10, 2019
1 parent 0d1d9d9 commit 482c134
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions src/rgw/rgw_rest_conn.h
Expand Up @@ -410,9 +410,6 @@ class RGWRESTSendResource : public RefCountedObject, public RGWIOProvider {
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);
Expand All @@ -425,61 +422,54 @@ class RGWRESTSendResource : public RefCountedObject, public RGWIOProvider {
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 {
Expand Down

0 comments on commit 482c134

Please sign in to comment.