2019-07-28 10:31:56 +08:00
|
|
|
|
#include "stdafx.h"
|
2014-11-19 00:25:21 +08:00
|
|
|
|
#include "master_service.h"
|
|
|
|
|
|
2015-09-16 21:03:02 +08:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
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_str;
|
|
|
|
|
acl::master_str_tbl var_conf_str_tab[] = {
|
|
|
|
|
{ "str", "test_msg", &var_cfg_str },
|
|
|
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int var_cfg_bool;
|
|
|
|
|
acl::master_bool_tbl var_conf_bool_tab[] = {
|
|
|
|
|
{ "bool", 1, &var_cfg_bool },
|
|
|
|
|
|
|
|
|
|
{ 0, 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-18 21:45:40 +08:00
|
|
|
|
int var_cfg_rw_timeout;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
acl::master_int_tbl var_conf_int_tab[] = {
|
2016-11-18 21:45:40 +08:00
|
|
|
|
{ "rw_timeout", 30, &var_cfg_rw_timeout, 0, 0 },
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
{ 0, 0 , 0 , 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
long long int var_cfg_int64;
|
|
|
|
|
acl::master_int64_tbl var_conf_int64_tab[] = {
|
|
|
|
|
{ "int64", 120, &var_cfg_int64, 0, 0 },
|
|
|
|
|
|
|
|
|
|
{ 0, 0 , 0 , 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-16 21:03:02 +08:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
2019-07-20 16:41:23 +08:00
|
|
|
|
master_service::master_service(void)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 16:41:23 +08:00
|
|
|
|
master_service::~master_service(void)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool master_service::thread_on_read(acl::socket_stream* conn)
|
|
|
|
|
{
|
|
|
|
|
acl::string buf;
|
|
|
|
|
|
2019-07-20 16:41:23 +08:00
|
|
|
|
if (!conn->gets(buf)) {
|
2014-11-19 00:25:21 +08:00
|
|
|
|
logger_warn("gets error from %s, fd %d",
|
|
|
|
|
conn->get_peer(), conn->sock_handle());
|
|
|
|
|
return false;
|
2019-07-20 16:41:23 +08:00
|
|
|
|
} else if(conn->format("%s\r\n", buf.c_str()) == -1) {
|
2014-11-19 00:25:21 +08:00
|
|
|
|
return false;
|
2019-07-20 16:41:23 +08:00
|
|
|
|
} else if (buf == "quit") {
|
2014-11-19 00:25:21 +08:00
|
|
|
|
return false;
|
2019-07-20 16:41:23 +08:00
|
|
|
|
} else {
|
2014-11-19 00:25:21 +08:00
|
|
|
|
return true;
|
2019-07-20 16:41:23 +08:00
|
|
|
|
}
|
2014-11-19 00:25:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool master_service::thread_on_accept(acl::socket_stream* conn)
|
|
|
|
|
{
|
|
|
|
|
logger("connect from %s, fd: %d", conn->get_peer(true),
|
|
|
|
|
conn->sock_handle());
|
2016-11-18 21:45:40 +08:00
|
|
|
|
conn->set_rw_timeout(var_cfg_rw_timeout);
|
2019-07-20 16:41:23 +08:00
|
|
|
|
if (var_cfg_rw_timeout > 0) {
|
2016-11-18 21:45:40 +08:00
|
|
|
|
conn->set_tcp_non_blocking(true);
|
2019-07-20 16:41:23 +08:00
|
|
|
|
}
|
2014-11-19 00:25:21 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool master_service::thread_on_timeout(acl::socket_stream* conn)
|
|
|
|
|
{
|
|
|
|
|
logger("read timeout from %s, fd: %d", conn->get_peer(),
|
|
|
|
|
conn->sock_handle());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void master_service::thread_on_close(acl::socket_stream* conn)
|
|
|
|
|
{
|
|
|
|
|
logger("disconnect from %s, fd: %d", conn->get_peer(),
|
|
|
|
|
conn->sock_handle());
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 16:41:23 +08:00
|
|
|
|
void master_service::thread_on_init(void)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 16:41:23 +08:00
|
|
|
|
void master_service::thread_on_exit(void)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 20:09:21 +08:00
|
|
|
|
void master_service::proc_on_listen(acl::server_socket& ss)
|
|
|
|
|
{
|
|
|
|
|
logger(">>>listen %s ok<<<", ss.get_addr());
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 16:41:23 +08:00
|
|
|
|
void master_service::proc_on_init(void)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
{
|
2017-07-05 10:27:33 +08:00
|
|
|
|
logger(">>>proc_on_init<<<");
|
2014-11-19 00:25:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-25 19:44:37 +08:00
|
|
|
|
bool master_service::proc_exit_timer(size_t nclients, size_t nthreads)
|
|
|
|
|
{
|
2019-07-20 16:41:23 +08:00
|
|
|
|
if (nclients == 0) {
|
2014-11-25 19:44:37 +08:00
|
|
|
|
logger("clients count: %d, threads count: %d",
|
|
|
|
|
(int) nclients, (int) nthreads);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 16:41:23 +08:00
|
|
|
|
void master_service::proc_on_exit(void)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
{
|
2017-07-05 10:27:33 +08:00
|
|
|
|
logger(">>>proc_on_exit<<<");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-09 00:30:39 +08:00
|
|
|
|
bool master_service::proc_on_sighup(acl::string&)
|
2017-07-05 10:27:33 +08:00
|
|
|
|
{
|
|
|
|
|
logger(">>>proc_on_sighup<<<");
|
2017-09-09 00:30:39 +08:00
|
|
|
|
return true;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
}
|