1
This commit is contained in:
parent
ba2b5ee8d7
commit
869ba41905
@ -27,34 +27,40 @@ struct HttpProxyRequest
|
||||
class HttpProxyPromise : public a8::Promise
|
||||
{
|
||||
public:
|
||||
|
||||
HttpProxyPromise(const char* url, a8::XObject url_params)
|
||||
HttpProxyPromise(const char* url, a8::XObject url_params, bool* ret, std::shared_ptr<a8::XObject>* rsp)
|
||||
{
|
||||
url_ = url;
|
||||
url_params_ = url_params;
|
||||
ret_ = ret;
|
||||
rsp_ = rsp;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void DoAwait() override
|
||||
{
|
||||
HttpProxy::Instance()->HttpGet
|
||||
f8::HttpClientPool::Instance()->HttpGet
|
||||
(
|
||||
[this, _self = shared_from_this()]
|
||||
(bool ret, a8::XObject* xobj, f8::HttpContext* context)
|
||||
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||
{
|
||||
std::shared_ptr<a8::XObject> data = std::make_shared<a8::XObject>();
|
||||
*data = *xobj;
|
||||
SetResult({ret, data});
|
||||
*ret_ = ok;
|
||||
if (ok) {
|
||||
**rsp_ = *rsp_obj;
|
||||
}
|
||||
DoDone();
|
||||
},
|
||||
url_.c_str(),
|
||||
url_params_);
|
||||
url_params_,
|
||||
rand() % MAX_SYS_HTTP_NUM
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string url_;
|
||||
a8::XObject url_params_;
|
||||
bool* ret_ = nullptr;
|
||||
std::shared_ptr<a8::XObject>* rsp_ = nullptr;
|
||||
};
|
||||
|
||||
static void _ProxyCallback(std::shared_ptr<f8::JsonHttpRequest> request)
|
||||
@ -175,7 +181,11 @@ void HttpProxy::DestoryRequest(std::shared_ptr<HttpProxyRequest> request)
|
||||
}
|
||||
|
||||
std::shared_ptr<a8::Awaiter> HttpProxy::CoHttpGet(const char* url,
|
||||
a8::XObject url_params)
|
||||
a8::XObject url_params,
|
||||
bool* ret,
|
||||
std::shared_ptr<a8::XObject>* rsp)
|
||||
{
|
||||
return std::make_shared<HttpProxyPromise>(url, url_params);
|
||||
*ret = false;
|
||||
*rsp = std::make_shared<a8::XObject>();
|
||||
return std::make_shared<HttpProxyPromise>(url, url_params, ret, rsp);
|
||||
}
|
||||
|
@ -31,7 +31,9 @@ class HttpProxy : public a8::Singleton<HttpProxy>
|
||||
void DestoryRequest(std::shared_ptr<HttpProxyRequest> request);
|
||||
|
||||
std::shared_ptr<a8::Awaiter> CoHttpGet(const char* url,
|
||||
a8::XObject url_params);
|
||||
a8::XObject url_params,
|
||||
bool* ret,
|
||||
std::shared_ptr<a8::XObject>* rsp);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -116,6 +116,8 @@ void JsonDataMgr::GetApiUrl(std::string& url)
|
||||
|
||||
void JsonDataMgr::GetHttpProxyUrl(std::string& url)
|
||||
{
|
||||
url = "http://192.168.100.21:8321/webapp/index.php?c=Proxy&a=get";
|
||||
return;
|
||||
if (httpproxy_cluster_json_.Size() > 0) {
|
||||
std::shared_ptr<a8::XObject> conf = httpproxy_cluster_json_.At(0);
|
||||
url = conf->At("url")->AsXValue().GetString();
|
||||
|
@ -1,15 +1,38 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <f8/udplog.h>
|
||||
#include <f8/utils.h>
|
||||
#include <f8/msgqueue.h>
|
||||
#include <f8/comgr.h>
|
||||
#include <f8/coroutine.h>
|
||||
|
||||
#include "playermgr.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <f8/utils.h>
|
||||
#include <f8/msgqueue.h>
|
||||
#include "httpproxy.h"
|
||||
|
||||
void PlayerMgr::Init()
|
||||
{
|
||||
f8::CoMgr::Instance()->CreateCo
|
||||
(
|
||||
[] (f8::Coroutine* co)
|
||||
{
|
||||
bool ret = false;
|
||||
std::shared_ptr<a8::XObject> rsp;
|
||||
co->CoAwait
|
||||
(HttpProxy::Instance()->CoHttpGet
|
||||
(
|
||||
"https://game2006-test.kingsome.cn/webapp/index.php?c=Ops&a=selfChecking&",
|
||||
a8::XObject(),
|
||||
&ret,
|
||||
&rsp
|
||||
)
|
||||
);
|
||||
if (ret) {
|
||||
a8::XPrintf("rsp:%s\n", {rsp->ToJsonStr()});
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void PlayerMgr::UnInit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user