acl/app/wizard/tmpl/master/master_aio.cpp

167 lines
3.6 KiB
C++
Raw Normal View History

#include "stdafx.h"
2014-11-19 00:25:21 +08:00
#include "master_service.h"
2015-09-16 21:03:02 +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 }
};
int var_cfg_int;
acl::master_int_tbl var_conf_int_tab[] = {
{ "int", 120, &var_cfg_int, 0, 0 },
{ 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
// acl::aio_callback <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0B6A8>
2014-11-19 00:25:21 +08:00
class io_callback : public acl::aio_callback
{
public:
2019-07-20 16:41:23 +08:00
io_callback(acl::aio_socket_stream* client) : client_(client) {}
2014-11-19 00:25:21 +08:00
2019-07-20 16:41:23 +08:00
~io_callback(void) {}
2014-11-19 00:25:21 +08:00
protected:
/**
2019-07-20 16:41:23 +08:00
* @override
* ʵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param data {char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
* @param len {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>رո<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
2019-07-20 16:41:23 +08:00
bool read_callback(char* data, int len)
2014-11-19 00:25:21 +08:00
{
2019-07-20 16:41:23 +08:00
if (strncmp(data, "quit", 4) == 0) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB2BD><EFBFBD>Ĺرչ<D8B1><D5B9>̣<EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD> false
// ֪ͨ<CDA8><EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>رո<D8B1><D5B8><EFBFBD><ECB2BD>
2014-11-19 00:25:21 +08:00
// client_->close();
return false;
}
client_->write(data, len);
return true;
}
/**
2019-07-20 16:41:23 +08:00
* @override
* ʵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ɹ<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>رո<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
2019-07-20 16:41:23 +08:00
bool write_callback(void)
2014-11-19 00:25:21 +08:00
{
return true;
}
/**
2019-07-20 16:41:23 +08:00
* @override
* ʵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺرջص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
2019-07-20 16:41:23 +08:00
void close_callback(void)
2014-11-19 00:25:21 +08:00
{
// <20><><EFBFBD><EFBFBD><EFBFBD>ڴ˴<DAB4>ɾ<EFBFBD><C9BE><EFBFBD>ö<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD>ֹ<EFBFBD>ڴ<EFBFBD>й¶
2014-11-19 00:25:21 +08:00
delete this;
}
/**
2019-07-20 16:41:23 +08:00
* @override
* ʵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʱ<EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>رո<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
2019-07-20 16:41:23 +08:00
bool timeout_callback(void)
2014-11-19 00:25:21 +08:00
{
// <20><><EFBFBD><EFBFBD> false ֪ͨ<CDA8><EFBFBD><ECB2BD><EFBFBD>ܹرո<D8B1><D5B8><EFBFBD><ECB2BD>
2014-11-19 00:25:21 +08:00
return false;
}
private:
acl::aio_socket_stream* client_;
};
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::on_accept(acl::aio_socket_stream* client)
{
logger("connect from %s, fd %d", client->get_peer(true),
client->sock_handle());
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD>
2014-11-19 00:25:21 +08:00
io_callback* callback = new io_callback(client);
// ע<><D7A2><EFBFBD><EFBFBD><ECB2BD><EFBFBD>Ķ<EFBFBD><C4B6>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
client->add_read_callback(callback);
// ע<><D7A2><EFBFBD><EFBFBD><ECB2BD><EFBFBD><EFBFBD>д<EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
client->add_write_callback(callback);
// ע<><D7A2><EFBFBD><EFBFBD><ECB2BD><EFBFBD>Ĺرջص<D5BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
client->add_close_callback(callback);
// ע<><D7A2><EFBFBD><EFBFBD><ECB2BD><EFBFBD>ij<EFBFBD>ʱ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
client->add_timeout_callback(callback);
// д<><D0B4>ӭ<EFBFBD><D3AD>Ϣ
2014-11-19 00:25:21 +08:00
// client->format("hello, you're welcome\r\n");
// <20><><EFBFBD><EFBFBD><ECB2BD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ص<EFBFBD> acl::aio_callback
// <20>е<EFBFBD> read_callback <20><EFBFBD><E9BAAF>
2014-11-19 00:25:21 +08:00
client->gets(10, false);
// <20><><EFBFBD><EFBFBD><ECB2BD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD><DDBA>ص<EFBFBD> acl::aio_callback
// <20>е<EFBFBD> read_callback <20><EFBFBD><E9BAAF>
2014-11-19 00:25:21 +08:00
// client->read();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB2BD><EFBFBD>Ķ<EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿɶ<DDBF>ʱ<EFBFBD><CAB1><EFBFBD>ص<EFBFBD> acl::aio_callback
// <20>е<EFBFBD> read_wakeup <20><EFBFBD><E9BAAF>
2014-11-19 00:25:21 +08:00
// client->read_wait();
return true;
}
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
{
logger(">>>proc_on_init<<<");
2014-11-19 00:25:21 +08:00
}
2019-07-20 16:41:23 +08:00
void master_service::proc_on_exit(void)
2014-11-19 00:25:21 +08:00
{
logger(">>>proc_on_exit<<<");
}
bool master_service::proc_on_sighup(acl::string&)
{
logger(">>>proc_on_sighup<<<");
return true;
2014-11-19 00:25:21 +08:00
}