1
This commit is contained in:
parent
dd38a6a7c7
commit
21332b63ad
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
@ -347,6 +348,7 @@ namespace f8
|
|||||||
long long hash_code)
|
long long hash_code)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
++pending_num;
|
||||||
AsyncHttpRequest* p = new AsyncHttpRequest();
|
AsyncHttpRequest* p = new AsyncHttpRequest();
|
||||||
{
|
{
|
||||||
p->context_id = ++curr_seqid;
|
p->context_id = ++curr_seqid;
|
||||||
@ -401,6 +403,7 @@ namespace f8
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
long long curr_seqid = 0;
|
long long curr_seqid = 0;
|
||||||
|
std::atomic<long long> pending_num = {0};
|
||||||
std::map<long long, AsyncHttpRequest*> async_http_hash;
|
std::map<long long, AsyncHttpRequest*> async_http_hash;
|
||||||
|
|
||||||
unsigned short exec_async_http_msgid = 0;
|
unsigned short exec_async_http_msgid = 0;
|
||||||
@ -418,6 +421,7 @@ namespace f8
|
|||||||
MsgQueue::Instance()->RegisterCallBack(impl_->exec_async_http_msgid,
|
MsgQueue::Instance()->RegisterCallBack(impl_->exec_async_http_msgid,
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
{
|
{
|
||||||
|
--(HttpClientPool::Instance()->impl_->pending_num);
|
||||||
if (param.param1.GetInt() == AHE_NO_ERROR) {
|
if (param.param1.GetInt() == AHE_NO_ERROR) {
|
||||||
a8::XObject* xobj = (a8::XObject*)param.param2.GetUserData();
|
a8::XObject* xobj = (a8::XObject*)param.param2.GetUserData();
|
||||||
HttpClientPool::Instance()->impl_->AsyncHttpOnOk(param.sender, *xobj);
|
HttpClientPool::Instance()->impl_->AsyncHttpOnOk(param.sender, *xobj);
|
||||||
@ -453,4 +457,9 @@ namespace f8
|
|||||||
impl_->InternalExecAsyncHttp(2, url, url_params, content.c_str(), headers, param, on_ok, on_error, hash_code);
|
impl_->InternalExecAsyncHttp(2, url, url_params, content.c_str(), headers, param, on_ok, on_error, hash_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long long HttpClientPool::GetPendingNum()
|
||||||
|
{
|
||||||
|
return impl_->pending_num;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ namespace f8
|
|||||||
void HttpPost(a8::XParams param, AsyncHttpOnOkFunc on_ok, AsyncHttpOnErrorFunc on_error,
|
void HttpPost(a8::XParams param, AsyncHttpOnOkFunc on_ok, AsyncHttpOnErrorFunc on_error,
|
||||||
const char* url, a8::XObject url_params, const std::string& content,
|
const char* url, a8::XObject url_params, const std::string& content,
|
||||||
long long hash_code, a8::XObject* headers = nullptr);
|
long long hash_code, a8::XObject* headers = nullptr);
|
||||||
|
//获取执行中的数量
|
||||||
|
long long GetPendingNum();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HttpClientPoolImpl* impl_ = nullptr;
|
HttpClientPoolImpl* impl_ = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user