acl/lib_acl_cpp/include/acl_cpp/master/master_aio.hpp

110 lines
3.2 KiB
C++
Raw Normal View History

#pragma once
#include "../stdlib/thread_mutex.hpp"
2017-06-02 14:47:24 +08:00
#include "../stream/aio_handle.hpp"
#include "../stream/aio_listen_stream.hpp"
#include "master_base.hpp"
2014-11-19 00:25:21 +08:00
#ifndef ACL_CLIENT_ONLY
struct ACL_VSTREAM;
struct ACL_VSTRING;
2014-11-19 00:25:21 +08:00
namespace acl {
class aio_handle;
class aio_socket_stream;
/**
* acl_master 线
2014-11-19 00:25:21 +08:00
*/
class ACL_CPP_API master_aio : public master_base, public aio_accept_callback
2014-11-19 00:25:21 +08:00
{
public:
/**
* acl_master
*
* @param argc {int} main
* @param argv {char**} main
2014-11-19 00:25:21 +08:00
*/
void run_daemon(int argc, char** argv);
/**
*
* @param addrs {const char*} IP:PORT, IP:PORT...
* @param path {const char*}
* @param ht {aio_handle_type}
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool run_alone(const char* addrs, const char* path = NULL,
aio_handle_type ht = ENGINE_SELECT);
/**
* IO的事件引擎句柄
2014-11-19 00:25:21 +08:00
* @return {aio_handle*}
*/
aio_handle* get_handle() const;
/**
* run_alone 退
2014-11-19 00:25:21 +08:00
*/
void stop();
2017-07-22 21:32:21 +08:00
/**
*
* @return {const char*} NULL
2017-07-22 21:32:21 +08:00
*/
const char* get_conf_path(void) const;
2014-11-19 00:25:21 +08:00
protected:
master_aio();
virtual ~master_aio();
/**
*
* @param stream {aio_socket_stream*}
* @return {bool} false
*
2014-11-19 00:25:21 +08:00
*/
virtual bool on_accept(aio_socket_stream* stream) = 0;
2014-11-19 00:25:21 +08:00
private:
aio_handle* handle_;
2014-11-19 00:25:21 +08:00
/**
* aio_accept_callback
* @param client {aio_socket_stream*}
* @return {bool} true
2014-11-19 00:25:21 +08:00
*/
virtual bool accept_callback(aio_socket_stream* client);
private:
thread_mutex lock_;
void push_back(server_socket* ss);
2014-11-19 00:25:21 +08:00
private:
#if defined(_WIN32) || defined(_WIN64)
// 当接收到一个客户端连接时回调此函数
2014-11-19 00:25:21 +08:00
static void service_main(SOCKET, void*);
#else
static void service_main(int, void*);
#endif
// 当监听一个服务地址时回调此函数
static void service_on_listen(void*, ACL_VSTREAM*);
// 当进程切换用户身份后调用的回调函数
2014-11-19 00:25:21 +08:00
static void service_pre_jail(void*);
// 当进程切换用户身份后调用的回调函数
2014-11-19 00:25:21 +08:00
static void service_init(void*);
// 当进程退出时调用的回调函数
2014-11-19 00:25:21 +08:00
static void service_exit(void*);
// 当进程收到 SIGHUP 信号后会回调本函数
static int service_on_sighup(void*, ACL_VSTRING*);
2014-11-19 00:25:21 +08:00
};
} // namespace acl
#endif // ACL_CLIENT_ONLY