mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-04 04:49:08 +08:00
Merge branch 'gitee-master' into gitlab-upstream
This commit is contained in:
commit
6199e3f619
@ -12,7 +12,7 @@ public:
|
||||
bool alive()
|
||||
{
|
||||
if (conn_.alive()) {
|
||||
printf(">>>alive called: true<<<\r\n");
|
||||
//printf(">>>alive called: true<<<\r\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,10 @@
|
||||
#include "connect_pool.h"
|
||||
#include "connect_manager.h"
|
||||
|
||||
connect_manager::connect_manager(size_t min_conns)
|
||||
connect_manager::connect_manager(size_t min_conns, time_t ttl)
|
||||
: min_conns_(min_conns)
|
||||
{
|
||||
this->set_idle_ttl(ttl);
|
||||
}
|
||||
|
||||
connect_manager::~connect_manager()
|
||||
@ -12,9 +13,10 @@ connect_manager::~connect_manager()
|
||||
}
|
||||
|
||||
acl::connect_pool* connect_manager::create_pool(const char* addr,
|
||||
size_t count, size_t idx)
|
||||
size_t max, size_t idx)
|
||||
{
|
||||
acl::connect_pool* pool = new connect_pool(addr, count, idx);
|
||||
acl::connect_pool* pool = new connect_pool(addr, max, idx);
|
||||
pool->set_conns_min(min_conns_);
|
||||
pool->set_idle_ttl(idle_ttl_);
|
||||
return pool;
|
||||
}
|
||||
|
@ -3,14 +3,13 @@
|
||||
class connect_manager : public acl::connect_manager
|
||||
{
|
||||
public:
|
||||
connect_manager(size_t min_conns);
|
||||
connect_manager(size_t min_conns, time_t ttl);
|
||||
|
||||
virtual ~connect_manager();
|
||||
|
||||
protected:
|
||||
// 基类纯虚函数的实现
|
||||
acl::connect_pool* create_pool(const char* addr,
|
||||
size_t count, size_t idx);
|
||||
acl::connect_pool* create_pool(const char* addr, size_t max, size_t idx);
|
||||
|
||||
private:
|
||||
size_t min_conns_;
|
||||
|
@ -2,13 +2,12 @@
|
||||
#include "connect_client.h"
|
||||
#include "connect_pool.h"
|
||||
|
||||
connect_pool::connect_pool(const char* addr, size_t count, size_t idx)
|
||||
: acl::connect_pool(addr, count, idx)
|
||||
connect_pool::connect_pool(const char* addr, size_t max, size_t idx)
|
||||
: acl::connect_pool(addr, max, idx)
|
||||
, addr_(addr)
|
||||
, conn_timeout_(30)
|
||||
, rw_timeout_(30)
|
||||
{
|
||||
this->set_conns_min(count);
|
||||
}
|
||||
|
||||
connect_pool::~connect_pool()
|
||||
|
@ -3,7 +3,7 @@
|
||||
class connect_pool : public acl::connect_pool
|
||||
{
|
||||
public:
|
||||
connect_pool(const char* addr, size_t count, size_t idx);
|
||||
connect_pool(const char* addr, size_t max, size_t idx);
|
||||
virtual ~connect_pool();
|
||||
|
||||
void set_timeout(int conn_timeout, int rw_timeout);
|
||||
|
@ -29,15 +29,14 @@ static void check_all_connections(void)
|
||||
}
|
||||
|
||||
// 初始化过程
|
||||
static void init(const char* addrs, int count, int check_type, const char* proto)
|
||||
static void init(const char* addrs, int max, int min, int ttl,
|
||||
int check_type, const char* proto)
|
||||
{
|
||||
// 创建 HTTP 请求连接池集群管理对象
|
||||
__conn_manager = new connect_manager((size_t) count);
|
||||
__conn_manager = new connect_manager((size_t) min, (time_t) ttl);
|
||||
|
||||
// 添加服务器集群地址
|
||||
__conn_manager->init(addrs, addrs, 100);
|
||||
|
||||
__conn_manager->set_idle_ttl(1);
|
||||
__conn_manager->init(addrs, addrs, (size_t) max);
|
||||
|
||||
printf(">>>start monitor thread\r\n");
|
||||
|
||||
@ -58,7 +57,7 @@ static void init(const char* addrs, int count, int check_type, const char* proto
|
||||
|
||||
printf(">>>create thread pool\r\n");
|
||||
// 创建线程池
|
||||
__thr_pool = acl_thread_pool_create(count, 60);
|
||||
__thr_pool = acl_thread_pool_create(max, 60);
|
||||
}
|
||||
|
||||
// 进程退出前清理资源
|
||||
@ -159,7 +158,9 @@ static void usage(const char* procname)
|
||||
{
|
||||
printf("usage: %s -h [help]\r\n"
|
||||
" -s server_addrs [www.sina.com.cn:80;www.263.net:80;www.qq.com:80]\r\n"
|
||||
" -c cocurrent [default: 10]\r\n"
|
||||
" -c cocurrent_and_max_conns [default: 10]\r\n"
|
||||
" -m min_conns[default: 0]\r\n"
|
||||
" -o idle_ttl[default: 10]\r\n"
|
||||
" -t check_type [0: no check; 1: sync check; 2: async check]\r\n"
|
||||
" -p protocol [http|pop3]\r\n"
|
||||
" -d delay_seconds\r\n"
|
||||
@ -169,7 +170,7 @@ static void usage(const char* procname)
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int ch, cocurrent = 10;
|
||||
int ch, max = 10, min = 0, ttl = 60;
|
||||
int check_type = 0, delay = 2;
|
||||
acl::string addrs("www.sina.com.cn:80;www.263.net:80;www.qq.com:81");
|
||||
acl::string proto("pop3");
|
||||
@ -180,7 +181,7 @@ int main(int argc, char* argv[])
|
||||
// 日志输出至标准输出
|
||||
acl::log::stdout_open(true);
|
||||
|
||||
while ((ch = getopt(argc, argv, "hs:n:c:t:p:d:C")) > 0) {
|
||||
while ((ch = getopt(argc, argv, "hs:n:c:m:t:o:p:d:C")) > 0) {
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
@ -189,7 +190,13 @@ int main(int argc, char* argv[])
|
||||
addrs = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
cocurrent = atoi(optarg);
|
||||
max = atoi(optarg);
|
||||
break;
|
||||
case 'o':
|
||||
ttl = atoi(optarg);
|
||||
break;
|
||||
case 'm':
|
||||
min = atoi(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
__loop_count = atoi(optarg);
|
||||
@ -215,8 +222,8 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
init(addrs, cocurrent, check_type, proto);
|
||||
run(cocurrent, delay);
|
||||
init(addrs, max, min, ttl, check_type, proto);
|
||||
run(max, delay);
|
||||
end();
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -608,7 +608,7 @@ connect_client* connect_pool::peek_back()
|
||||
|
||||
void connect_pool::put_front(connect_client* conn)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
//time_t now = time(NULL);
|
||||
|
||||
lock_.lock();
|
||||
|
||||
@ -631,7 +631,8 @@ void connect_pool::put_front(connect_client* conn)
|
||||
|
||||
alive_ = true; // 该连接充当服务检测成功功能,所以可在此处设置服务可用
|
||||
|
||||
conn->set_when(now);
|
||||
// 禁止更新过期时间,以防止永远无法过期释放!
|
||||
//conn->set_when(now);
|
||||
|
||||
// 将归还的连接放在链表首部,这样在调用释放过期连接
|
||||
// 时比较方便,有利于尽快将不忙的数据库连接关闭
|
||||
|
Loading…
Reference in New Issue
Block a user