This commit is contained in:
aozhiwei 2022-12-18 15:05:52 +08:00
parent 0a591f7913
commit 7f272dc6b3
2 changed files with 21 additions and 32 deletions

View File

@ -25,15 +25,12 @@
#include <f8/utils.h>
#include <f8/timer.h>
static const int AHE_NO_ERROR = 0;
static const int AHE_NO_CONN = 1;
namespace f8
{
enum AsyncHttpError
{
AHE_NO_ERROR = 0,
AHE_NO_CONN = 1,
};
struct AsyncHttpRequest
{
long long context_id = 0;
@ -218,7 +215,7 @@ namespace f8
}
}
if (ret) {
a8::XObject* xobj = new a8::XObject();
std::shared_ptr<a8::XObject> xobj = std::make_shared<a8::XObject>();
if (xobj->ReadFromJsonString(response)) {
f8::MsgQueue::Instance()->PostMsg
(exec_async_http_msgid,
@ -226,7 +223,7 @@ namespace f8
(
{
node->context_id,
AHE_NO_ERROR,
(int)AHE_NO_ERROR,
xobj
}
));
@ -237,11 +234,11 @@ namespace f8
(
{
node->context_id,
AHE_NO_CONN,
(int)AHE_NO_CONN,
xobj,
response
}
));
delete xobj;
}
} else {
f8::MsgQueue::Instance()->PostMsg
@ -348,11 +345,9 @@ namespace f8
if (!request) {
return;
}
#if 0
if (request->on_ok) {
request->on_ok(request->param, data);
if (request->cb) {
request->cb(true, &data, nullptr);
}
#endif
async_http_hash.erase(seqid);
delete request;
}
@ -363,11 +358,9 @@ namespace f8
if (!request) {
return;
}
#if 0
if (request->on_error) {
request->on_error(request->param, response);
if (request->cb) {
request->cb(false, nullptr, nullptr);
}
#endif
async_http_hash.erase(seqid);
delete request;
}
@ -457,16 +450,18 @@ namespace f8
[] (const a8::Args& args)
{
--(HttpClientPool::Instance()->impl_->pending_num);
#if 0
if (param.param1.GetInt() == AHE_NO_ERROR) {
a8::XObject* xobj = (a8::XObject*)param.param2.GetUserData();
HttpClientPool::Instance()->impl_->AsyncHttpOnOk(param.sender, *xobj);
delete xobj;
long long context_id = args.Get<long long>(0);
auto xobj = args.Get<std::shared_ptr<a8::XObject>>(1);
int code = args.Get<long long>(2);
if (code == AHE_NO_ERROR) {
HttpClientPool::Instance()->impl_->AsyncHttpOnOk(context_id,
*xobj);
} else {
HttpClientPool::Instance()->impl_->AsyncHttpOnError(param.sender,
param.param2.GetString());
std::string response = args.Get<std::string>(3);
HttpClientPool::Instance()->impl_->AsyncHttpOnError(context_id,
response
);
}
#endif
}
);
impl_->SetThreadNum(thread_num);
@ -545,9 +540,4 @@ namespace f8
return impl_->pending_num;
}
HttpClientPoolImpl* HttpClientPool::Impl()
{
return impl_;
}
}

View File

@ -42,7 +42,6 @@ namespace f8
//获取执行中的数量
long long GetPendingNum();
HttpClientPoolImpl* Impl();
private:
HttpClientPoolImpl* impl_ = nullptr;