44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
#pragma once
|
|
|
|
namespace f8
|
|
{
|
|
|
|
typedef void (*AsyncHttpOnOkFunc)(a8::XParams& param, a8::XObject& data);
|
|
typedef void (*AsyncHttpOnErrorFunc)(a8::XParams& param, const std::string& response);
|
|
|
|
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(a8::XParams param, AsyncHttpOnOkFunc on_ok, AsyncHttpOnErrorFunc on_error,
|
|
const char* url, a8::XObject url_params,
|
|
long long hash_code, a8::XObject* headers = nullptr);
|
|
//执行异步http post
|
|
void HttpPost(a8::XParams param, AsyncHttpOnOkFunc on_ok, AsyncHttpOnErrorFunc on_error,
|
|
const char* url, a8::XObject url_params, const std::string& content,
|
|
long long hash_code, a8::XObject* headers = nullptr);
|
|
//获取执行中的数量
|
|
long long GetPendingNum();
|
|
HttpClientPoolImpl* Impl();
|
|
|
|
private:
|
|
HttpClientPoolImpl* impl_ = nullptr;
|
|
};
|
|
|
|
}
|