mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-15 01:10:52 +08:00
109 lines
2.3 KiB
C++
109 lines
2.3 KiB
C++
#include "stdafx.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "http_servlet.h"
|
|
|
|
static char *var_cfg_debug_msg;
|
|
|
|
static acl::master_str_tbl var_conf_str_tab[] = {
|
|
{ "debug_msg", "test_msg", &var_cfg_debug_msg },
|
|
|
|
{ 0, 0, 0 }
|
|
};
|
|
|
|
static int var_cfg_debug_enable;
|
|
|
|
static acl::master_bool_tbl var_conf_bool_tab[] = {
|
|
{ "debug_enable", 1, &var_cfg_debug_enable },
|
|
|
|
{ 0, 0, 0 }
|
|
};
|
|
|
|
static int var_cfg_io_timeout;
|
|
|
|
static acl::master_int_tbl var_conf_int_tab[] = {
|
|
{ "io_timeout", 120, &var_cfg_io_timeout, 0, 0 },
|
|
|
|
{ 0, 0 , 0 , 0, 0 }
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
class master_fiber_test : public acl::master_fiber
|
|
{
|
|
public:
|
|
master_fiber_test(void) {}
|
|
~master_fiber_test(void) {}
|
|
|
|
protected:
|
|
// @override
|
|
void on_accept(acl::socket_stream& conn) {
|
|
acl_msg_info(">>>accept connection: %d", conn.sock_handle());
|
|
conn.set_rw_timeout(10);
|
|
acl::memcache_session session("127.0.0.1:11211");
|
|
http_servlet servlet(&conn, &session);
|
|
servlet.setLocalCharset("gb2312");
|
|
|
|
while (true) {
|
|
if (!servlet.doRun()) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
acl_msg_info(">>>close one connection: %d, %s",
|
|
conn.sock_handle(), acl::last_serror());
|
|
}
|
|
|
|
// @override
|
|
void proc_pre_jail(void) {
|
|
acl_msg_info(">>>proc_pre_jail<<<");
|
|
}
|
|
|
|
// @override
|
|
void proc_on_init(void) {
|
|
acl_msg_info(">>>proc_on_init<<<");
|
|
}
|
|
|
|
// @override
|
|
void proc_on_exit(void) {
|
|
acl_msg_info(">>>proc_on_exit<<<");
|
|
}
|
|
|
|
// @override
|
|
bool proc_on_sighup(acl::string&) {
|
|
acl_msg_info(">>>proc_on_sighup<<<");
|
|
return true;
|
|
}
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
master_fiber_test& mf =
|
|
acl::singleton2<master_fiber_test>::get_instance();
|
|
|
|
acl::acl_cpp_init();
|
|
acl::log::stdout_open(true);
|
|
|
|
mf.set_cfg_int(var_conf_int_tab);
|
|
mf.set_cfg_int64(NULL);
|
|
mf.set_cfg_str(var_conf_str_tab);
|
|
mf.set_cfg_bool(var_conf_bool_tab);
|
|
|
|
if (argc >= 2 && strcasecmp(argv[1], "alone") == 0) {
|
|
//const char* addr = "127.0.0.1|8088";
|
|
const char* addr = "0.0.0.0|8088";
|
|
//const char* addr = "*.*.*.*|8088";
|
|
//const char* addr = "192.168.*.*|8088";
|
|
//const char* addr = "|8088";
|
|
|
|
printf("listen: %s\r\n", addr);
|
|
acl::log::stdout_open(true);
|
|
|
|
mf.run_alone(addr, argc >= 3 ? argv[2] : NULL);
|
|
} else {
|
|
mf.run_daemon(argc, argv);
|
|
}
|
|
|
|
return 0;
|
|
}
|