55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#pragma once
|
|
|
|
namespace f8
|
|
{
|
|
|
|
struct HttpContext
|
|
{
|
|
std::string response;
|
|
};
|
|
|
|
typedef std::function<void(bool, a8::XObject*, f8::HttpContext*)> HttpProxyCb;
|
|
|
|
class HttpClientPoolImpl;
|
|
class HttpClientPool : public a8::Singleton<HttpClientPool>
|
|
{
|
|
private:
|
|
HttpClientPool() {};
|
|
friend class a8::Singleton<HttpClientPool>;
|
|
|
|
public:
|
|
volatile long long max_sys_request_delay = 0;
|
|
volatile long long max_user_request_delay = 0;
|
|
volatile int thread_num = 0;
|
|
volatile int sys_num = 0;
|
|
volatile int user_num = 0;
|
|
|
|
public:
|
|
void Init(int thread_num, int sys_num, int user_num);
|
|
void UnInit();
|
|
|
|
//执行异步http get
|
|
void HttpGet(
|
|
f8::HttpProxyCb cb,
|
|
const char* url,
|
|
a8::XObject url_params,
|
|
long long hash_code,
|
|
a8::XObject* headers = nullptr);
|
|
//执行异步http post
|
|
void HttpPost(
|
|
f8::HttpProxyCb cb,
|
|
const char* url,
|
|
a8::XObject url_params,
|
|
const std::string& content,
|
|
long long hash_code,
|
|
a8::XObject* headers = nullptr);
|
|
|
|
//获取执行中的数量
|
|
long long GetPendingNum();
|
|
|
|
private:
|
|
HttpClientPoolImpl* impl_ = nullptr;
|
|
};
|
|
|
|
}
|