1
This commit is contained in:
parent
0a591f7913
commit
7f272dc6b3
@ -25,15 +25,12 @@
|
|||||||
#include <f8/utils.h>
|
#include <f8/utils.h>
|
||||||
#include <f8/timer.h>
|
#include <f8/timer.h>
|
||||||
|
|
||||||
|
static const int AHE_NO_ERROR = 0;
|
||||||
|
static const int AHE_NO_CONN = 1;
|
||||||
|
|
||||||
namespace f8
|
namespace f8
|
||||||
{
|
{
|
||||||
|
|
||||||
enum AsyncHttpError
|
|
||||||
{
|
|
||||||
AHE_NO_ERROR = 0,
|
|
||||||
AHE_NO_CONN = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AsyncHttpRequest
|
struct AsyncHttpRequest
|
||||||
{
|
{
|
||||||
long long context_id = 0;
|
long long context_id = 0;
|
||||||
@ -218,7 +215,7 @@ namespace f8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
a8::XObject* xobj = new a8::XObject();
|
std::shared_ptr<a8::XObject> xobj = std::make_shared<a8::XObject>();
|
||||||
if (xobj->ReadFromJsonString(response)) {
|
if (xobj->ReadFromJsonString(response)) {
|
||||||
f8::MsgQueue::Instance()->PostMsg
|
f8::MsgQueue::Instance()->PostMsg
|
||||||
(exec_async_http_msgid,
|
(exec_async_http_msgid,
|
||||||
@ -226,7 +223,7 @@ namespace f8
|
|||||||
(
|
(
|
||||||
{
|
{
|
||||||
node->context_id,
|
node->context_id,
|
||||||
AHE_NO_ERROR,
|
(int)AHE_NO_ERROR,
|
||||||
xobj
|
xobj
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@ -237,11 +234,11 @@ namespace f8
|
|||||||
(
|
(
|
||||||
{
|
{
|
||||||
node->context_id,
|
node->context_id,
|
||||||
AHE_NO_CONN,
|
(int)AHE_NO_CONN,
|
||||||
|
xobj,
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
delete xobj;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
f8::MsgQueue::Instance()->PostMsg
|
f8::MsgQueue::Instance()->PostMsg
|
||||||
@ -348,11 +345,9 @@ namespace f8
|
|||||||
if (!request) {
|
if (!request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if 0
|
if (request->cb) {
|
||||||
if (request->on_ok) {
|
request->cb(true, &data, nullptr);
|
||||||
request->on_ok(request->param, data);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
async_http_hash.erase(seqid);
|
async_http_hash.erase(seqid);
|
||||||
delete request;
|
delete request;
|
||||||
}
|
}
|
||||||
@ -363,11 +358,9 @@ namespace f8
|
|||||||
if (!request) {
|
if (!request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if 0
|
if (request->cb) {
|
||||||
if (request->on_error) {
|
request->cb(false, nullptr, nullptr);
|
||||||
request->on_error(request->param, response);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
async_http_hash.erase(seqid);
|
async_http_hash.erase(seqid);
|
||||||
delete request;
|
delete request;
|
||||||
}
|
}
|
||||||
@ -457,16 +450,18 @@ namespace f8
|
|||||||
[] (const a8::Args& args)
|
[] (const a8::Args& args)
|
||||||
{
|
{
|
||||||
--(HttpClientPool::Instance()->impl_->pending_num);
|
--(HttpClientPool::Instance()->impl_->pending_num);
|
||||||
#if 0
|
long long context_id = args.Get<long long>(0);
|
||||||
if (param.param1.GetInt() == AHE_NO_ERROR) {
|
auto xobj = args.Get<std::shared_ptr<a8::XObject>>(1);
|
||||||
a8::XObject* xobj = (a8::XObject*)param.param2.GetUserData();
|
int code = args.Get<long long>(2);
|
||||||
HttpClientPool::Instance()->impl_->AsyncHttpOnOk(param.sender, *xobj);
|
if (code == AHE_NO_ERROR) {
|
||||||
delete xobj;
|
HttpClientPool::Instance()->impl_->AsyncHttpOnOk(context_id,
|
||||||
|
*xobj);
|
||||||
} else {
|
} else {
|
||||||
HttpClientPool::Instance()->impl_->AsyncHttpOnError(param.sender,
|
std::string response = args.Get<std::string>(3);
|
||||||
param.param2.GetString());
|
HttpClientPool::Instance()->impl_->AsyncHttpOnError(context_id,
|
||||||
|
response
|
||||||
|
);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
impl_->SetThreadNum(thread_num);
|
impl_->SetThreadNum(thread_num);
|
||||||
@ -545,9 +540,4 @@ namespace f8
|
|||||||
return impl_->pending_num;
|
return impl_->pending_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpClientPoolImpl* HttpClientPool::Impl()
|
|
||||||
{
|
|
||||||
return impl_;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ namespace f8
|
|||||||
|
|
||||||
//获取执行中的数量
|
//获取执行中的数量
|
||||||
long long GetPendingNum();
|
long long GetPendingNum();
|
||||||
HttpClientPoolImpl* Impl();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HttpClientPoolImpl* impl_ = nullptr;
|
HttpClientPoolImpl* impl_ = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user