From 7f272dc6b3c72839997921cfa1a78a0118eb504c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 18 Dec 2022 15:05:52 +0800 Subject: [PATCH] 1 --- f8/httpclientpool.cc | 52 ++++++++++++++++++-------------------------- f8/httpclientpool.h | 1 - 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/f8/httpclientpool.cc b/f8/httpclientpool.cc index e9ee764..5384755 100644 --- a/f8/httpclientpool.cc +++ b/f8/httpclientpool.cc @@ -25,15 +25,12 @@ #include #include +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 xobj = std::make_shared(); 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(0); + auto xobj = args.Get>(1); + int code = args.Get(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(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_; - } - } diff --git a/f8/httpclientpool.h b/f8/httpclientpool.h index 7742b7e..eac7f86 100644 --- a/f8/httpclientpool.h +++ b/f8/httpclientpool.h @@ -42,7 +42,6 @@ namespace f8 //获取执行中的数量 long long GetPendingNum(); - HttpClientPoolImpl* Impl(); private: HttpClientPoolImpl* impl_ = nullptr;