2016-07-29 16:43:46 +08:00
|
|
|
|
#pragma once
|
2017-07-27 18:16:39 +08:00
|
|
|
|
//#include "acl_cpp/master/master_base.hpp"
|
2017-07-26 19:09:48 +08:00
|
|
|
|
|
|
|
|
|
struct ACL_VSTREAM;
|
2016-07-29 16:43:46 +08:00
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
2017-07-26 19:09:48 +08:00
|
|
|
|
class socket_stream;
|
|
|
|
|
|
2016-07-29 16:43:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 基于协程方式的网络服务类
|
|
|
|
|
*/
|
|
|
|
|
class master_fiber : public master_base
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* 在 acl_master 框架下运行本网络服务对象
|
|
|
|
|
* @param argc {int} 传入的参数数组大小
|
|
|
|
|
* @param argv {char**} 传入的参数数组
|
|
|
|
|
*/
|
|
|
|
|
void run_daemon(int argc, char** argv);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 以独立运行模式启动本网络服务对象
|
|
|
|
|
* @param addrs {const char*} 监听的本机服务地址列表,格式:
|
|
|
|
|
* ip:port, ip:port, ...
|
|
|
|
|
* @param path {const char*} 非 NULL 指定配置文件路径
|
|
|
|
|
*/
|
2017-03-12 14:49:48 +08:00
|
|
|
|
bool run_alone(const char* addrs, const char* path = NULL);
|
2016-07-29 16:43:46 +08:00
|
|
|
|
|
2017-07-22 21:32:21 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获得配置文件路径
|
|
|
|
|
* @return {const char*} 返回值为 NULL 表示没有设配置文件
|
|
|
|
|
*/
|
|
|
|
|
const char* get_conf_path(void) const;
|
|
|
|
|
|
2016-07-29 16:43:46 +08:00
|
|
|
|
protected:
|
|
|
|
|
master_fiber();
|
2017-07-04 23:33:28 +08:00
|
|
|
|
|
2016-07-29 16:43:46 +08:00
|
|
|
|
virtual ~master_fiber();
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-03 20:09:21 +08:00
|
|
|
|
* 虚函数,当协程服务器接收到客户端连接后调用本函数
|
2016-07-29 16:43:46 +08:00
|
|
|
|
* @param stream {socket_stream&} 客户端连接对象,本函数返回后,协程
|
|
|
|
|
* 服务框架将会关闭该连接对象
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_accept(socket_stream& stream) = 0;
|
|
|
|
|
|
2017-07-04 23:33:28 +08:00
|
|
|
|
/**
|
|
|
|
|
* 当线程初始化时该虚方法将被调用
|
|
|
|
|
*/
|
|
|
|
|
virtual void thread_on_init(void) {}
|
|
|
|
|
|
2016-07-29 16:43:46 +08:00
|
|
|
|
private:
|
2017-07-04 23:33:28 +08:00
|
|
|
|
static void service_on_listen(void*, ACL_VSTREAM*);
|
|
|
|
|
static void service_on_accept(void*, ACL_VSTREAM*);
|
2016-07-29 16:43:46 +08:00
|
|
|
|
static void service_pre_jail(void*);
|
|
|
|
|
static void service_init(void*);
|
2017-07-04 23:33:28 +08:00
|
|
|
|
static void thread_init(void*);
|
2016-07-29 16:43:46 +08:00
|
|
|
|
static void service_exit(void*);
|
2017-07-05 10:27:33 +08:00
|
|
|
|
static void service_on_sighup(void*);
|
2017-07-04 23:33:28 +08:00
|
|
|
|
|
|
|
|
|
void run(int argc, char** argv);
|
2016-07-29 16:43:46 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|