From acffe3761b6677e0968ff2d95799c5c83ece656e Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 21 Mar 2022 20:22:59 +0800 Subject: [PATCH] 1 --- server/gameserver/httpproxy.cc | 17 +++++++++++------ server/gameserver/httpproxy.h | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/server/gameserver/httpproxy.cc b/server/gameserver/httpproxy.cc index 61634e5d..34b80a5a 100644 --- a/server/gameserver/httpproxy.cc +++ b/server/gameserver/httpproxy.cc @@ -68,17 +68,16 @@ std::string HttpProxy::HttpGet(a8::XParams param, JsonDataMgr::Instance()->GetHttpProxyUrl(proxy_url); f8::HttpClientPool::Instance()->HttpGet (a8::XParams() - .SetSender(request), + .SetSender(request->req_id), [] (a8::XParams& param, a8::XObject& data) { - HttpProxyRequest* req = (HttpProxyRequest*)(param.sender.GetUserData()); - req->on_ok(req->param, data); - HttpProxy::Instance()->DestoryRequest(req); }, [] (a8::XParams& param, const std::string& response) { - HttpProxyRequest* req = (HttpProxyRequest*)(param.sender.GetUserData()); - req->on_error(req->param, response); + HttpProxyRequest* req = HttpProxy::Instance()->GetRequest(param.sender.GetString()); + if (req) { + req->on_error(req->param, response); + } HttpProxy::Instance()->DestoryRequest(req); }, proxy_url.c_str(), @@ -94,6 +93,12 @@ std::string HttpProxy::CreateRequestId() return request_prefix_ + a8::XValue(App::Instance()->NewUuid()).GetString(); } +HttpProxyRequest* HttpProxy::GetRequest(const std::string& req_id) +{ + auto itr = request_hash_.find(req_id); + return itr != request_hash_.end() ? itr->second : nullptr; +} + void HttpProxy::DestoryRequest(HttpProxyRequest* request) { request_hash_.erase(request->req_id); diff --git a/server/gameserver/httpproxy.h b/server/gameserver/httpproxy.h index 87faa22c..b4cdb47d 100644 --- a/server/gameserver/httpproxy.h +++ b/server/gameserver/httpproxy.h @@ -21,11 +21,12 @@ class HttpProxy : public a8::Singleton const char* url, a8::XObject url_params ); + HttpProxyRequest* GetRequest(const std::string& req_id); + void DestoryRequest(HttpProxyRequest* request); private: std::string CreateRequestId(); - void DestoryRequest(HttpProxyRequest* request); private: std::map request_hash_;