diff --git a/http/client/HttpClient.cpp b/http/client/HttpClient.cpp index 0960b682b..39cdf5bdb 100644 --- a/http/client/HttpClient.cpp +++ b/http/client/HttpClient.cpp @@ -1,5 +1,6 @@ #include "HttpClient.h" +#include #include #ifdef WITH_CURL @@ -731,3 +732,10 @@ int http_client_send_async(HttpRequestPtr req, HttpResponseCallback resp_cb) { return http_client_exec_async(hv_default_async_http_client(), req, std::move(resp_cb)); } + +int http_client_reuse_loop(http_client_t *cli, hv::EventLoopPtr loop) { + if (!cli || !loop) return ERR_NULL_POINTER; + cli->async_client_ = std::make_shared(std::move(loop)); + return 0; +} + diff --git a/http/client/HttpClient.h b/http/client/HttpClient.h index 4891bb621..5020cc93a 100644 --- a/http/client/HttpClient.h +++ b/http/client/HttpClient.h @@ -1,6 +1,7 @@ #ifndef HV_HTTP_CLIENT_H_ #define HV_HTTP_CLIENT_H_ +#include "EventLoop.h" #include "hexport.h" #include "hssl.h" #include "HttpMessage.h" @@ -76,6 +77,7 @@ HV_EXPORT int http_client_send_data(http_client_t* cli, const char* data, int si HV_EXPORT int http_client_recv_data(http_client_t* cli, char* data, int size); HV_EXPORT int http_client_recv_response(http_client_t* cli, HttpResponse* resp); HV_EXPORT int http_client_close(http_client_t* cli); +HV_EXPORT int http_client_reuse_loop(http_client_t *cli, hv::EventLoopPtr loop); namespace hv { @@ -161,6 +163,10 @@ class HttpClient { int close() { return http_client_close(_client); } + //if need, set once, set before sendAsync + int reuseLoop(EventLoopPtr loop) { + return http_client_reuse_loop(_client, std::move(loop)); + } private: http_client_t* _client;