1
This commit is contained in:
parent
4628973216
commit
4de95e5225
@ -32,7 +32,7 @@ static void _ProxyCallback(f8::JsonHttpRequest* request)
|
||||
});
|
||||
//#endif
|
||||
std::string seq_id = request->request.Get("seq_id");
|
||||
HttpProxyRequest* req = HttpProxy::Instance()->GetRequest(seq_id);
|
||||
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(seq_id);
|
||||
if (req) {
|
||||
a8::XObject data;
|
||||
|
||||
@ -68,7 +68,7 @@ std::string HttpProxy::HttpGet(a8::XParams param,
|
||||
a8::XObject url_params
|
||||
)
|
||||
{
|
||||
HttpProxyRequest* request = new HttpProxyRequest();
|
||||
std::shared_ptr<HttpProxyRequest> request = std::make_shared<HttpProxyRequest>();
|
||||
request->req_id = CreateRequestId();
|
||||
request->param = param;
|
||||
request->on_ok = on_ok;
|
||||
@ -97,7 +97,7 @@ std::string HttpProxy::HttpGet(a8::XParams param,
|
||||
.SetSender(request->req_id),
|
||||
[] (a8::XParams& param, a8::XObject& data)
|
||||
{
|
||||
HttpProxyRequest* req = HttpProxy::Instance()->GetRequest(param.sender.GetString());
|
||||
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(param.sender.GetString());
|
||||
if (req) {
|
||||
long long cost_time = a8::XGetTickCount() - req->add_tick;
|
||||
#ifdef DEBUG
|
||||
@ -112,7 +112,7 @@ std::string HttpProxy::HttpGet(a8::XParams param,
|
||||
},
|
||||
[] (a8::XParams& param, const std::string& response)
|
||||
{
|
||||
HttpProxyRequest* req = HttpProxy::Instance()->GetRequest(param.sender.GetString());
|
||||
std::shared_ptr<HttpProxyRequest> req = HttpProxy::Instance()->GetRequest(param.sender.GetString());
|
||||
if (req) {
|
||||
long long cost_time = a8::XGetTickCount() - req->add_tick;
|
||||
f8::UdpLog::Instance()->Warning("ProxyHttpGet error cost_time:%d url:%s params:%s response:%s",
|
||||
@ -138,14 +138,13 @@ std::string HttpProxy::CreateRequestId()
|
||||
return request_prefix_ + a8::XValue(App::Instance()->NewUuid()).GetString();
|
||||
}
|
||||
|
||||
HttpProxyRequest* HttpProxy::GetRequest(const std::string& req_id)
|
||||
std::shared_ptr<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)
|
||||
void HttpProxy::DestoryRequest(std::shared_ptr<HttpProxyRequest> request)
|
||||
{
|
||||
request_hash_.erase(request->req_id);
|
||||
delete request;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "f8/httpclientpool.h"
|
||||
|
||||
struct HttpProxyRequest;
|
||||
typedef std::function<void(a8::XObject&)> HttpProxyCb;
|
||||
class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
{
|
||||
|
||||
@ -23,15 +24,15 @@ class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
const char* url,
|
||||
a8::XObject url_params
|
||||
);
|
||||
HttpProxyRequest* GetRequest(const std::string& req_id);
|
||||
void DestoryRequest(HttpProxyRequest* request);
|
||||
std::shared_ptr<HttpProxyRequest> GetRequest(const std::string& req_id);
|
||||
void DestoryRequest(std::shared_ptr<HttpProxyRequest> request);
|
||||
|
||||
private:
|
||||
|
||||
std::string CreateRequestId();
|
||||
|
||||
private:
|
||||
std::map<std::string, HttpProxyRequest*> request_hash_;
|
||||
std::map<std::string, std::shared_ptr<HttpProxyRequest>> request_hash_;
|
||||
std::string request_prefix_;
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user