2019-07-28 10:31:56 +08:00
|
|
|
|
#include "stdafx.h"
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#include "http_job.h"
|
|
|
|
|
#include "db_store.h"
|
|
|
|
|
#include "master_service.h"
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
char* var_cfg_http_url_list;
|
|
|
|
|
char* var_cfg_dns_ip;
|
|
|
|
|
char* var_cfg_dbpath;
|
|
|
|
|
char* var_cfg_dbcharset;
|
|
|
|
|
acl::master_str_tbl var_conf_str_tab[] = {
|
|
|
|
|
{ "http_url_list", "http://www.baidu.com/", &var_cfg_http_url_list },
|
|
|
|
|
{ "dns_ip", "8.8.8.8", &var_cfg_dns_ip },
|
|
|
|
|
{ "dbpath", "./check.db", &var_cfg_dbpath },
|
|
|
|
|
{ "dbcharset", "utf-8", &var_cfg_dbcharset },
|
|
|
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
acl::master_bool_tbl var_conf_bool_tab[] = {
|
|
|
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int var_cfg_http_cocurrent;
|
|
|
|
|
int var_cfg_dns_port;
|
|
|
|
|
int var_cfg_conn_timeout;
|
|
|
|
|
int var_cfg_rw_timeout;
|
|
|
|
|
acl::master_int_tbl var_conf_int_tab[] = {
|
|
|
|
|
{ "http_cocurrent", 10, &var_cfg_http_cocurrent, 0, 0 },
|
|
|
|
|
{ "dns_port", 53, &var_cfg_dns_port, 0, 0 },
|
|
|
|
|
{ "conn_timeout", 60, &var_cfg_conn_timeout, 0, 0 },
|
|
|
|
|
{ "rw_timeout", 60, &var_cfg_rw_timeout, 0, 0 },
|
|
|
|
|
|
|
|
|
|
{ 0, 0 , 0 , 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
acl::master_int64_tbl var_conf_int64_tab[] = {
|
|
|
|
|
|
|
|
|
|
{ 0, 0 , 0 , 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
acl::thread_pool* var_thrpool;
|
|
|
|
|
acl::db_pool* var_dbpool;
|
|
|
|
|
|
|
|
|
|
master_service::master_service()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
master_service::~master_service()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void master_service::on_trigger()
|
|
|
|
|
{
|
|
|
|
|
std::vector<acl::string>::const_iterator cit = url_list_.begin();
|
|
|
|
|
for (; cit != url_list_.end(); ++cit)
|
|
|
|
|
{
|
|
|
|
|
const char* url = (*cit).c_str();
|
|
|
|
|
for (int i = 0; i < var_cfg_http_cocurrent; i++)
|
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><F1A3ACB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳߳<DFB3>ȥִ<C8A5><D6B4>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
acl::thread_job* job = new http_job(*var_thrpool, url,
|
|
|
|
|
var_cfg_dns_ip, var_cfg_dns_port);
|
|
|
|
|
var_thrpool->execute(job);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20>ȴ<EFBFBD><C8B4>̳߳ؽ<CCB3><D8BD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
var_thrpool->wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void master_service::proc_on_init()
|
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// ȡ<><C8A1><EFBFBD><EFBFBD>Ҫ̽<D2AA><CCBD><EFBFBD><EFBFBD> URL <20>б<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
acl::string buf(var_cfg_http_url_list);
|
|
|
|
|
const std::list<acl::string>& tokens = buf.split(",; \t");
|
|
|
|
|
std::list<acl::string>::const_iterator cit = tokens.begin();
|
|
|
|
|
for (; cit != tokens.end(); ++cit)
|
|
|
|
|
{
|
|
|
|
|
url_list_.push_back(*cit);
|
|
|
|
|
logger("add url: %s", (*cit).c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ӳ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
var_dbpool = new acl::sqlite_pool(var_cfg_dbpath,
|
|
|
|
|
var_cfg_http_cocurrent * url_list_.size());
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
db_store store;
|
|
|
|
|
if (store.db_create() == false)
|
|
|
|
|
logger_fatal("create db failed!");
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>̳߳ز<CCB3><D8B2><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
var_thrpool = new acl::thread_pool;
|
|
|
|
|
var_thrpool->set_limit(var_cfg_http_cocurrent);
|
|
|
|
|
var_thrpool->set_idle(300);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>̳߳ع<CCB3><D8B9><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
var_thrpool->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void master_service::proc_on_exit()
|
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>̳߳<DFB3>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
delete var_thrpool;
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ӳ<EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
delete var_dbpool;
|
|
|
|
|
}
|