mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 20:08:21 +08:00
add codes
This commit is contained in:
commit
9a73031b22
2
Makefile
2
Makefile
@ -81,7 +81,7 @@ endif
|
||||
##############################################################################
|
||||
|
||||
.PHONY = check help all_lib all samples all clean install uninstall uninstall_all build_bin build_src build_one
|
||||
VERSION = 3.2.2
|
||||
VERSION = 3.2.2_2
|
||||
|
||||
help:
|
||||
@(echo "usage: make help|all|all_lib|all_samples|clean|install|uninstall|uninstall_all|build_bin|build_src|build_one")
|
||||
|
@ -1,3 +1,8 @@
|
||||
|
||||
10) 2016.11.18
|
||||
10.1) master_proc.cpp/master_threads.cpp: 在 on_accept 中当 var_cfg_rw_timeout > 0
|
||||
时,将套接口设为非阻塞模式,以防止写超时
|
||||
|
||||
9) 2015.12.21
|
||||
9.1) bugfix: master_threads.cpp 中的函数 proc_exit_timer 在只有当 nclients 为0
|
||||
时才允许退出
|
||||
|
@ -16,15 +16,13 @@ bool http_servlet::doError(acl::HttpServletRequest&,
|
||||
acl::HttpServletResponse& res)
|
||||
{
|
||||
res.setStatus(400);
|
||||
res.setContentType("text/html; charset=$<CHARSET>");
|
||||
// 发送 http 响应头
|
||||
if (res.sendHeader() == false)
|
||||
return false;
|
||||
res.setContentType("text/xml; charset=utf-8");
|
||||
|
||||
// 发送 http 响应体
|
||||
acl::string buf;
|
||||
buf.format("<root error='some error happened!' />\r\n");
|
||||
(void) res.getOutputStream().write(buf);
|
||||
res.write(buf);
|
||||
res.write(NULL, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -32,14 +30,12 @@ bool http_servlet::doOther(acl::HttpServletRequest&,
|
||||
acl::HttpServletResponse& res, const char* method)
|
||||
{
|
||||
res.setStatus(400);
|
||||
res.setContentType("text/html; charset=$<CHARSET>");
|
||||
// 发送 http 响应头
|
||||
if (res.sendHeader() == false)
|
||||
return false;
|
||||
res.setContentType("text/xml; charset=utf-8");
|
||||
// 发送 http 响应体
|
||||
acl::string buf;
|
||||
buf.format("<root error='unkown request method %s' />\r\n", method);
|
||||
(void) res.getOutputStream().write(buf);
|
||||
res.write(buf);
|
||||
res.write(NULL, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,11 @@ void master_service::proc_pre_jail(void)
|
||||
logger(">>>proc_pre_jail<<<");
|
||||
}
|
||||
|
||||
void master_service::proc_on_listen(acl::server_socket& ss)
|
||||
{
|
||||
logger(">>>listen %s ok<<<", ss.get_addr());
|
||||
}
|
||||
|
||||
void master_service::proc_on_init(void)
|
||||
{
|
||||
logger(">>>proc_on_init<<<");
|
||||
|
@ -20,6 +20,9 @@ protected:
|
||||
// @override
|
||||
void proc_pre_jail(void);
|
||||
|
||||
// @override
|
||||
void proc_on_listen(acl::server_socket& ss);
|
||||
|
||||
// @override
|
||||
void proc_on_init(void);
|
||||
|
||||
|
@ -19,9 +19,9 @@ acl::master_bool_tbl var_conf_bool_tab[] = {
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
int var_cfg_int;
|
||||
int var_cfg_rw_timeout;
|
||||
acl::master_int_tbl var_conf_int_tab[] = {
|
||||
{ "int", 120, &var_cfg_int, 0, 0 },
|
||||
{ "rw_timeout", 30, &var_cfg_rw_timeout, 0, 0 },
|
||||
|
||||
{ 0, 0 , 0 , 0, 0 }
|
||||
};
|
||||
@ -48,7 +48,9 @@ void master_service::on_accept(acl::socket_stream* conn)
|
||||
logger("connect from %s, fd %d", conn->get_peer(),
|
||||
conn->sock_handle());
|
||||
|
||||
conn->set_rw_timeout(10);
|
||||
conn->set_rw_timeout(var_cfg_rw_timeout);
|
||||
if (var_cfg_rw_timeout > 0)
|
||||
conn->set_tcp_non_blocking(true);
|
||||
|
||||
acl::memcache_session session("127.0.0.1:11211");
|
||||
http_servlet servlet(conn, &session);
|
||||
@ -64,6 +66,11 @@ void master_service::on_accept(acl::socket_stream* conn)
|
||||
logger("disconnect from %s", conn->get_peer());
|
||||
}
|
||||
|
||||
void master_service::proc_on_listen(acl::server_socket& ss)
|
||||
{
|
||||
logger(">>>listen %s ok<<<", ss.get_addr());
|
||||
}
|
||||
|
||||
void master_service::proc_on_init()
|
||||
{
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ extern acl::master_str_tbl var_conf_str_tab[];
|
||||
extern int var_cfg_bool;
|
||||
extern acl::master_bool_tbl var_conf_bool_tab[];
|
||||
|
||||
extern int var_cfg_int;
|
||||
extern acl::master_int_tbl var_conf_int_tab[];
|
||||
|
||||
extern long long int var_cfg_int64;
|
||||
@ -29,20 +28,30 @@ public:
|
||||
|
||||
protected:
|
||||
/**
|
||||
* 纯虚函数:当接收到一个客户端连接时调用此函数
|
||||
* @override
|
||||
* 虚函数:当接收到一个客户端连接时调用此函数
|
||||
* @param stream {aio_socket_stream*} 新接收到的客户端异步流对象
|
||||
* 注:该函数返回后,流连接将会被关闭,用户不应主动关闭该流
|
||||
*/
|
||||
virtual void on_accept(acl::socket_stream* stream);
|
||||
void on_accept(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 在进程启动时,服务进程每成功监听一个本地地址,便调用本函数
|
||||
* @param ss {acl::server_socket&} 监听对象
|
||||
*/
|
||||
void proc_on_listen(acl::server_socket& ss);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程切换用户身份后调用的回调函数,此函数被调用时,进程
|
||||
* 的权限为普通受限级别
|
||||
*/
|
||||
virtual void proc_on_init();
|
||||
void proc_on_init();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程退出前调用的回调函数
|
||||
*/
|
||||
virtual void proc_on_exit();
|
||||
void proc_on_exit();
|
||||
};
|
||||
|
@ -60,7 +60,10 @@ bool master_service::thread_on_accept(acl::socket_stream* conn)
|
||||
{
|
||||
logger("connect from %s, fd: %d", conn->get_peer(true),
|
||||
conn->sock_handle());
|
||||
|
||||
conn->set_rw_timeout(var_cfg_rw_timeout);
|
||||
if (var_cfg_rw_timeout > 0)
|
||||
conn->set_tcp_non_blocking(true);
|
||||
|
||||
acl::session* session;
|
||||
if (var_cfg_use_redis_session)
|
||||
@ -100,6 +103,11 @@ void master_service::thread_on_exit()
|
||||
{
|
||||
}
|
||||
|
||||
void master_service::proc_on_listen(acl::server_socket& ss)
|
||||
{
|
||||
logger(">>>listen %s ok<<<", ss.get_addr());
|
||||
}
|
||||
|
||||
void master_service::proc_on_init()
|
||||
{
|
||||
// create redis cluster for session cluster
|
||||
|
@ -9,7 +9,6 @@ extern acl::master_str_tbl var_conf_str_tab[];
|
||||
extern int var_cfg_bool;
|
||||
extern acl::master_bool_tbl var_conf_bool_tab[];
|
||||
|
||||
extern int var_cfg_int;
|
||||
extern acl::master_int_tbl var_conf_int_tab[];
|
||||
|
||||
extern long long int var_cfg_int64;
|
||||
@ -27,54 +26,69 @@ public:
|
||||
|
||||
protected:
|
||||
/**
|
||||
* 纯虚函数:当某个客户端连接有数据可读或关闭或出错时调用此函数
|
||||
* @override
|
||||
* 虚函数:当某个客户端连接有数据可读或关闭或出错时调用此函数
|
||||
* @param stream {socket_stream*}
|
||||
* @return {bool} 返回 false 则表示当函数返回后需要关闭连接,
|
||||
* 否则表示需要保持长连接,如果该流出错,则应用应该返回 false
|
||||
*/
|
||||
virtual bool thread_on_read(acl::socket_stream* stream);
|
||||
bool thread_on_read(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当线程池中的某个线程获得一个连接时的回调函数,
|
||||
* 子类可以做一些初始化工作
|
||||
* @param stream {socket_stream*}
|
||||
* @return {bool} 如果返回 false 则表示子类要求关闭连接,而不
|
||||
* 必将该连接再传递至 thread_main 过程
|
||||
*/
|
||||
virtual bool thread_on_accept(acl::socket_stream* stream);
|
||||
bool thread_on_accept(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* 当某个网络连接的 IO 读写超时时的回调函数,如果该函数返回 true 则表示继续等待下一次
|
||||
* 读写,否则则希望关闭该连接
|
||||
* @override
|
||||
* 当某个网络连接的 IO 读写超时时的回调函数,如果该函数返回 true 则
|
||||
* 表示继续等待下一次读写,否则则希望关闭该连接
|
||||
* @param stream {socket_stream*}
|
||||
* @return {bool} 如果返回 false 则表示子类要求关闭连接,而不
|
||||
* 必将该连接再传递至 thread_main 过程
|
||||
*/
|
||||
virtual bool thread_on_timeout(acl::socket_stream* stream);
|
||||
bool thread_on_timeout(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当与某个线程绑定的连接关闭时的回调函数
|
||||
* @param stream {socket_stream*}
|
||||
*/
|
||||
virtual void thread_on_close(acl::socket_stream* stream);
|
||||
void thread_on_close(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当线程池中一个新线程被创建时的回调函数
|
||||
*/
|
||||
virtual void thread_on_init();
|
||||
void thread_on_init();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当线程池中一个线程退出时的回调函数
|
||||
*/
|
||||
virtual void thread_on_exit();
|
||||
void thread_on_exit();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 在进程启动时,服务进程每成功监听一个本地地址,便调用本函数
|
||||
* @param ss {acl::server_socket&} 监听对象
|
||||
*/
|
||||
void proc_on_listen(acl::server_socket& ss);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程切换用户身份后调用的回调函数,此函数被调用时,进程
|
||||
* 的权限为普通受限级别
|
||||
*/
|
||||
virtual void proc_on_init();
|
||||
void proc_on_init();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当子进程需要退出时框架将回调此函数,框架决定子进程是否退出取决于:
|
||||
* 1) 如果此函数返回 true 则子进程立即退出,否则:
|
||||
* 2) 如果该子进程所有客户端连接都已关闭,则子进程立即退出,否则:
|
||||
@ -86,12 +100,13 @@ protected:
|
||||
* @return {bool} 返回 false 表示当前子进程还不能退出,否则表示当前
|
||||
* 子进程可以退出了
|
||||
*/
|
||||
virtual bool proc_exit_timer(size_t nclients, size_t nthreads);
|
||||
bool proc_exit_timer(size_t nclients, size_t nthreads);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程退出前调用的回调函数
|
||||
*/
|
||||
virtual void proc_on_exit();
|
||||
void proc_on_exit();
|
||||
|
||||
private:
|
||||
// redis 集群对象
|
||||
|
@ -146,6 +146,11 @@ bool master_service::on_accept(acl::aio_socket_stream* client)
|
||||
return true;
|
||||
}
|
||||
|
||||
void master_service::proc_on_listen(acl::server_socket& ss)
|
||||
{
|
||||
logger(">>>listen %s ok<<<", ss.get_addr());
|
||||
}
|
||||
|
||||
void master_service::proc_on_init()
|
||||
{
|
||||
}
|
||||
|
@ -27,7 +27,8 @@ public:
|
||||
|
||||
protected:
|
||||
/**
|
||||
* 纯虚函数:当接收到一个客户端连接时调用此函数
|
||||
* @override
|
||||
* 虚函数:当接收到一个客户端连接时调用此函数
|
||||
* @param stream {aio_socket_stream*} 新接收到的客户端异步流对象
|
||||
* @return {bool} 该函数如果返回 false 则通知服务器框架不再接收
|
||||
* 远程客户端连接,否则继续接收客户端连接
|
||||
@ -35,13 +36,22 @@ protected:
|
||||
bool on_accept(acl::aio_socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 在进程启动时,服务进程每成功监听一个本地地址,便调用本函数
|
||||
* @param ss {acl::server_socket&} 监听对象
|
||||
*/
|
||||
void proc_on_listen(acl::server_socket& ss);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程切换用户身份后调用的回调函数,此函数被调用时,进程
|
||||
* 的权限为普通受限级别
|
||||
*/
|
||||
virtual void proc_on_init();
|
||||
void proc_on_init();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程退出前调用的回调函数
|
||||
*/
|
||||
virtual void proc_on_exit();
|
||||
void proc_on_exit();
|
||||
};
|
||||
|
@ -65,6 +65,11 @@ void master_service::proc_pre_jail(void)
|
||||
logger(">>>proc_pre_jail<<<");
|
||||
}
|
||||
|
||||
void master_service::proc_on_listen(acl::server_socket& ss)
|
||||
{
|
||||
logger(">>>listen %s ok<<<", ss.get_addr());
|
||||
}
|
||||
|
||||
void master_service::proc_on_init(void)
|
||||
{
|
||||
logger(">>>proc_on_init<<<");
|
||||
|
@ -17,6 +17,9 @@ protected:
|
||||
// @override
|
||||
void on_accept(acl::socket_stream& conn);
|
||||
|
||||
// @override
|
||||
void proc_on_listen(acl::server_socket& ss);
|
||||
|
||||
// @override
|
||||
void proc_pre_jail(void);
|
||||
|
||||
|
@ -18,9 +18,9 @@ acl::master_bool_tbl var_conf_bool_tab[] = {
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
int var_cfg_int;
|
||||
int var_cfg_rw_timeout;
|
||||
acl::master_int_tbl var_conf_int_tab[] = {
|
||||
{ "int", 120, &var_cfg_int, 0, 0 },
|
||||
{ "rw_timeout", 30, &var_cfg_rw_timeout, 0, 0 },
|
||||
|
||||
{ 0, 0 , 0 , 0, 0 }
|
||||
};
|
||||
@ -47,7 +47,10 @@ void master_service::on_accept(acl::socket_stream* conn)
|
||||
logger("connect from %s, fd %d", conn->get_peer(),
|
||||
conn->sock_handle());
|
||||
|
||||
conn->set_rw_timeout(10);
|
||||
conn->set_rw_timeout(var_cfg_rw_timeout);
|
||||
if (var_cfg_rw_timeout > 0)
|
||||
conn->set_tcp_non_blocking(true);
|
||||
|
||||
acl::string buf;
|
||||
while (true)
|
||||
{
|
||||
@ -62,6 +65,11 @@ void master_service::on_accept(acl::socket_stream* conn)
|
||||
logger("disconnect from %s", conn->get_peer());
|
||||
}
|
||||
|
||||
void master_service::proc_on_listen(acl::server_socket& ss)
|
||||
{
|
||||
logger(">>>listen %s ok<<<", ss.get_addr());
|
||||
}
|
||||
|
||||
void master_service::proc_on_init()
|
||||
{
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ extern acl::master_str_tbl var_conf_str_tab[];
|
||||
extern int var_cfg_bool;
|
||||
extern acl::master_bool_tbl var_conf_bool_tab[];
|
||||
|
||||
extern int var_cfg_int;
|
||||
extern int var_cfg_rw_timeout;
|
||||
extern acl::master_int_tbl var_conf_int_tab[];
|
||||
|
||||
extern long long int var_cfg_int64;
|
||||
@ -27,20 +27,30 @@ public:
|
||||
|
||||
protected:
|
||||
/**
|
||||
* 纯虚函数:当接收到一个客户端连接时调用此函数
|
||||
* @override
|
||||
* 当接收到一个客户端连接时调用此函数
|
||||
* @param stream {aio_socket_stream*} 新接收到的客户端异步流对象
|
||||
* 注:该函数返回后,流连接将会被关闭,用户不应主动关闭该流
|
||||
*/
|
||||
virtual void on_accept(acl::socket_stream* stream);
|
||||
void on_accept(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 在进程启动时,服务进程每成功监听一个本地地址,便调用本函数
|
||||
* @param ss {acl::server_socket&} 监听对象
|
||||
*/
|
||||
void proc_on_listen(acl::server_socket& ss);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程切换用户身份后调用的回调函数,此函数被调用时,进程
|
||||
* 的权限为普通受限级别
|
||||
*/
|
||||
virtual void proc_on_init();
|
||||
void proc_on_init();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程退出前调用的回调函数
|
||||
*/
|
||||
virtual void proc_on_exit();
|
||||
void proc_on_exit();
|
||||
};
|
||||
|
@ -18,9 +18,9 @@ acl::master_bool_tbl var_conf_bool_tab[] = {
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
int var_cfg_int;
|
||||
int var_cfg_rw_timeout;
|
||||
acl::master_int_tbl var_conf_int_tab[] = {
|
||||
{ "int", 120, &var_cfg_int, 0, 0 },
|
||||
{ "rw_timeout", 30, &var_cfg_rw_timeout, 0, 0 },
|
||||
|
||||
{ 0, 0 , 0 , 0, 0 }
|
||||
};
|
||||
@ -64,7 +64,9 @@ bool master_service::thread_on_accept(acl::socket_stream* conn)
|
||||
{
|
||||
logger("connect from %s, fd: %d", conn->get_peer(true),
|
||||
conn->sock_handle());
|
||||
conn->set_rw_timeout(5);
|
||||
conn->set_rw_timeout(var_cfg_rw_timeout);
|
||||
if (var_cfg_rw_timeout > 0)
|
||||
conn->set_tcp_non_blocking(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -89,6 +91,11 @@ void master_service::thread_on_exit()
|
||||
{
|
||||
}
|
||||
|
||||
void master_service::proc_on_listen(acl::server_socket& ss)
|
||||
{
|
||||
logger(">>>listen %s ok<<<", ss.get_addr());
|
||||
}
|
||||
|
||||
void master_service::proc_on_init()
|
||||
{
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ extern acl::master_str_tbl var_conf_str_tab[];
|
||||
extern int var_cfg_bool;
|
||||
extern acl::master_bool_tbl var_conf_bool_tab[];
|
||||
|
||||
extern int var_cfg_int;
|
||||
extern int var_cfg_rw_timeout;
|
||||
extern acl::master_int_tbl var_conf_int_tab[];
|
||||
|
||||
extern long long int var_cfg_int64;
|
||||
@ -27,54 +27,69 @@ public:
|
||||
|
||||
protected:
|
||||
/**
|
||||
* 纯虚函数:当某个客户端连接有数据可读或关闭或出错时调用此函数
|
||||
* @override
|
||||
* 虚函数:当某个客户端连接有数据可读或关闭或出错时调用此函数
|
||||
* @param stream {socket_stream*}
|
||||
* @return {bool} 返回 false 则表示当函数返回后需要关闭连接,
|
||||
* 否则表示需要保持长连接,如果该流出错,则应用应该返回 false
|
||||
*/
|
||||
virtual bool thread_on_read(acl::socket_stream* stream);
|
||||
bool thread_on_read(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当线程池中的某个线程获得一个连接时的回调函数,
|
||||
* 子类可以做一些初始化工作
|
||||
* @param stream {socket_stream*}
|
||||
* @return {bool} 如果返回 false 则表示子类要求关闭连接,而不
|
||||
* 必将该连接再传递至 thread_main 过程
|
||||
*/
|
||||
virtual bool thread_on_accept(acl::socket_stream* stream);
|
||||
bool thread_on_accept(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当某个网络连接的 IO 读写超时时的回调函数,如果该函数返回 true 则
|
||||
* 表示继续等待下一次读写,否则则希望关闭该连接
|
||||
* @param stream {socket_stream*}
|
||||
* @return {bool} 如果返回 false 则表示子类要求关闭连接,而不
|
||||
* 必将该连接再传递至 thread_main 过程
|
||||
*/
|
||||
virtual bool thread_on_timeout(acl::socket_stream* stream);
|
||||
bool thread_on_timeout(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当与某个线程绑定的连接关闭时的回调函数
|
||||
* @param stream {socket_stream*}
|
||||
*/
|
||||
virtual void thread_on_close(acl::socket_stream* stream);
|
||||
void thread_on_close(acl::socket_stream* stream);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当线程池中一个新线程被创建时的回调函数
|
||||
*/
|
||||
virtual void thread_on_init();
|
||||
void thread_on_init();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当线程池中一个线程退出时的回调函数
|
||||
*/
|
||||
virtual void thread_on_exit();
|
||||
void thread_on_exit();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 在进程启动时,服务进程每成功监听一个本地地址,便调用本函数
|
||||
* @param ss {acl::server_socket&} 监听对象
|
||||
*/
|
||||
void proc_on_listen(acl::server_socket& ss);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程切换用户身份后调用的回调函数,此函数被调用时,进程
|
||||
* 的权限为普通受限级别
|
||||
*/
|
||||
virtual void proc_on_init();
|
||||
void proc_on_init();
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当子进程需要退出时框架将回调此函数,框架决定子进程是否退出取决于:
|
||||
* 1) 如果此函数返回 true 则子进程立即退出,否则:
|
||||
* 2) 如果该子进程所有客户端连接都已关闭,则子进程立即退出,否则:
|
||||
@ -86,10 +101,11 @@ protected:
|
||||
* @return {bool} 返回 false 表示当前子进程还不能退出,否则表示当前
|
||||
* 子进程可以退出了
|
||||
*/
|
||||
virtual bool proc_exit_timer(size_t nclients, size_t nthreads);
|
||||
bool proc_exit_timer(size_t nclients, size_t nthreads);
|
||||
|
||||
/**
|
||||
* @override
|
||||
* 当进程退出前调用的回调函数
|
||||
*/
|
||||
virtual void proc_on_exit();
|
||||
void proc_on_exit();
|
||||
};
|
||||
|
@ -1,5 +1,7 @@
|
||||
修改历史列表:
|
||||
------------------------------------------------------------------------
|
||||
101) 2016.11.3 --- acl 3.2.2.2 版本发布!
|
||||
100) 2016.11.2 --- acl 3.2.2.1 版本发布!
|
||||
99) 2016.11.1 --- acl 3.2.2 版本发布!
|
||||
98) 2016.9.7 --- acl 3.2.1 版本发布!
|
||||
97) 2016.8.27 --- acl 3.2.0 版本发布!
|
||||
|
BIN
dist/master/libexec/linux64/acl_master
vendored
Normal file
BIN
dist/master/libexec/linux64/acl_master
vendored
Normal file
Binary file not shown.
2
dist/master/libexec/mingw/keep
vendored
Normal file
2
dist/master/libexec/mingw/keep
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
keepme
|
||||
|
@ -30,6 +30,7 @@ CFLAGS = -c -g -W \
|
||||
-D_POSIX_PTHREAD_SEMANTICS \
|
||||
-DACL_PREPARE_COMPILE \
|
||||
-Winvalid-pch
|
||||
#-DDEBUG_MEM
|
||||
#-DUSE_EPOLL \
|
||||
#-Wno-tautological-compare \
|
||||
#-Wno-invalid-source-encoding \
|
||||
|
@ -1,5 +1,28 @@
|
||||
修改历史列表:
|
||||
|
||||
573) 2016.12.29
|
||||
573.1) bugfix: acl_slice.c 中修复了 SLICE1 方式分配内存的一处 BUG
|
||||
|
||||
572) 2016.12.28
|
||||
572.1) feature: acl_mem_slice.c 中的函数 tls_mem_realloc 允许源指针为 NULL
|
||||
|
||||
571) 2016.12.1
|
||||
571.1) feature: acl_aio_server.c/acl_threads_server.c/acl_single_server.c 增加
|
||||
回调函数 __service_on_listen,以便于将监听的流对象传递给应用
|
||||
|
||||
570) 2016.11.30
|
||||
570.1) feature: acl_master 服务器框架支持监听地址的模糊匹配机制,以便于多机部署
|
||||
时的配置文件一致性
|
||||
|
||||
569) 2016.11.27
|
||||
569.1) feature: 增加了内存调试函数 acl_default_meminfo 用来显示内存分配及释放情况
|
||||
|
||||
568) 2016.11.18
|
||||
568.1) bugfix: acl_vstream.c 中的函数 acl_vstream_fdopen 设置 IO 句柄为非阻塞
|
||||
模式是存在问题的,上层应用应该自己决定是否设为非阻塞模式
|
||||
568.2) workaround: 将 acl_master 服务器中的所有服务器模板的 use_limit 和 idle_limit
|
||||
的缺省都设为 0,即服务子进程默认情况下是不退出的
|
||||
|
||||
567) 2016.10.28
|
||||
567.1) compile: 可以在 centos4.7 上使用 gcc 3.x.x 编译
|
||||
|
||||
|
@ -34,7 +34,7 @@ extern int acl_var_aio_max_threads;
|
||||
extern int acl_var_aio_thread_idle_limit;
|
||||
|
||||
#define ACL_VAR_AIO_IDLE_LIMIT "aio_idle_limit"
|
||||
#define ACL_DEF_AIO_IDLE_LIMIT 180
|
||||
#define ACL_DEF_AIO_IDLE_LIMIT 0
|
||||
extern int acl_var_aio_idle_limit;
|
||||
|
||||
#define ACL_VAR_AIO_QUEUE_DIR "aio_queue_dir"
|
||||
@ -70,7 +70,7 @@ extern char *acl_var_aio_event_mode;
|
||||
extern int acl_var_aio_daemon_timeout;
|
||||
|
||||
#define ACL_VAR_AIO_USE_LIMIT "aio_use_limit"
|
||||
#define ACL_DEF_AIO_USE_LIMIT 10
|
||||
#define ACL_DEF_AIO_USE_LIMIT 0
|
||||
extern int acl_var_aio_use_limit;
|
||||
|
||||
#define ACL_VAR_AIO_MASTER_MAXPROC "master_maxproc"
|
||||
|
@ -37,7 +37,7 @@ extern int acl_var_ioctl_stacksize;
|
||||
extern int acl_var_ioctl_thread_idle_limit;
|
||||
|
||||
#define ACL_VAR_IOCTL_IDLE_LIMIT "ioctl_idle_limit"
|
||||
#define ACL_DEF_IOCTL_IDLE_LIMIT 180
|
||||
#define ACL_DEF_IOCTL_IDLE_LIMIT 0
|
||||
extern int acl_var_ioctl_idle_limit;
|
||||
|
||||
#define ACL_VAR_IOCTL_QUEUE_DIR "ioctl_queue_dir"
|
||||
@ -73,7 +73,7 @@ extern char *acl_var_ioctl_event_mode;
|
||||
extern int acl_var_ioctl_daemon_timeout;
|
||||
|
||||
#define ACL_VAR_IOCTL_USE_LIMIT "ioctl_use_limit"
|
||||
#define ACL_DEF_IOCTL_USE_LIMIT 10
|
||||
#define ACL_DEF_IOCTL_USE_LIMIT 0
|
||||
extern int acl_var_ioctl_use_limit;
|
||||
|
||||
#define ACL_VAR_IOCTL_MASTER_MAXPROC "master_maxproc"
|
||||
|
@ -25,7 +25,7 @@ extern int acl_var_multi_rw_timeout;
|
||||
extern int acl_var_multi_in_flow_delay;
|
||||
|
||||
#define ACL_VAR_MULTI_IDLE_LIMIT "multi_idle_limit"
|
||||
#define ACL_DEF_MULTI_IDLE_LIMIT 180
|
||||
#define ACL_DEF_MULTI_IDLE_LIMIT 0
|
||||
extern int acl_var_multi_idle_limit;
|
||||
|
||||
#define ACL_VAR_MULTI_QUEUE_DIR "multi_queue_dir"
|
||||
@ -53,7 +53,7 @@ extern int acl_var_multi_delay_usec;
|
||||
extern int acl_var_multi_daemon_timeout;
|
||||
|
||||
#define ACL_VAR_MULTI_USE_LIMIT "multi_use_limit"
|
||||
#define ACL_DEF_MULTI_USE_LIMIT 10
|
||||
#define ACL_DEF_MULTI_USE_LIMIT 0
|
||||
extern int acl_var_multi_use_limit;
|
||||
|
||||
#define ACL_VAR_MULTI_ENABLE_CORE "multi_enable_core"
|
||||
|
@ -43,6 +43,7 @@ extern "C" {
|
||||
#define ACL_MASTER_SERVER_DENY_INFO 25
|
||||
|
||||
#define ACL_MASTER_SERVER_EXIT_TIMER 26
|
||||
#define ACL_MASTER_SERVER_ON_LISTEN 27
|
||||
|
||||
#define ACL_APP_CTL_END ACL_MASTER_SERVER_END
|
||||
#define ACL_APP_CTL_CFG_INT ACL_MASTER_SERVER_INT_TABLE
|
||||
@ -64,6 +65,7 @@ extern "C" {
|
||||
typedef void (*ACL_MASTER_SERVER_INIT_FN) (void *);
|
||||
typedef int (*ACL_MASTER_SERVER_LOOP_FN) (void *);
|
||||
typedef void (*ACL_MASTER_SERVER_EXIT_FN) (void *);
|
||||
typedef void (*ACL_MASTER_SERVER_LISTEN_FN) (void *);
|
||||
typedef int (*ACL_MASTER_SERVER_ACCEPT_FN) (ACL_VSTREAM *);
|
||||
typedef int (*ACL_MASTER_SERVER_HANDSHAKE_FN) (ACL_VSTREAM *);
|
||||
typedef void (*ACL_MASTER_SERVER_DISCONN_FN) (ACL_VSTREAM *, void *);
|
||||
|
@ -29,7 +29,7 @@ extern int acl_var_single_in_flow_delay;
|
||||
* connection (except queue manager).
|
||||
*/
|
||||
#define ACL_VAR_SINGLE_IDLE_LIMIT "single_idle_limit"
|
||||
#define ACL_DEF_SINGLE_IDLE_LIMIT 180
|
||||
#define ACL_DEF_SINGLE_IDLE_LIMIT 0
|
||||
extern int acl_var_single_idle_limit;
|
||||
|
||||
#define ACL_VAR_SINGLE_QUEUE_DIR "single_queue_dir"
|
||||
@ -65,7 +65,7 @@ extern int acl_var_single_daemon_timeout;
|
||||
* subsystem terminates (except queue manager).
|
||||
*/
|
||||
#define ACL_VAR_SINGLE_USE_LIMIT "single_use_limit"
|
||||
#define ACL_DEF_SINGLE_USE_LIMIT 10
|
||||
#define ACL_DEF_SINGLE_USE_LIMIT 0
|
||||
extern int acl_var_single_use_limit;
|
||||
|
||||
#define ACL_VAR_SINGLE_ENABLE_CORE "single_enable_core"
|
||||
|
@ -31,11 +31,11 @@ extern int acl_var_threads_thread_stacksize;
|
||||
extern int acl_var_threads_thread_idle;
|
||||
|
||||
#define ACL_VAR_THREADS_IDLE_LIMIT "ioctl_idle_limit"
|
||||
#define ACL_DEF_THREADS_IDLE_LIMIT 180
|
||||
#define ACL_DEF_THREADS_IDLE_LIMIT 0
|
||||
extern int acl_var_threads_idle_limit;
|
||||
|
||||
#define ACL_VAR_THREADS_USE_LIMIT "ioctl_use_limit"
|
||||
#define ACL_DEF_THREADS_USE_LIMIT 10
|
||||
#define ACL_DEF_THREADS_USE_LIMIT 0
|
||||
extern int acl_var_threads_use_limit;
|
||||
|
||||
#define ACL_VAR_THREADS_QUEUE_DIR "ioctl_queue_dir"
|
||||
|
@ -25,7 +25,7 @@ extern int acl_var_trigger_rw_timeout;
|
||||
extern int acl_var_trigger_in_flow_delay;
|
||||
|
||||
#define ACL_VAR_TRIGGER_IDLE_LIMIT "trigger_idle_limit"
|
||||
#define ACL_DEF_TRIGGER_IDLE_LIMIT 180
|
||||
#define ACL_DEF_TRIGGER_IDLE_LIMIT 0
|
||||
extern int acl_var_trigger_idle_limit;
|
||||
|
||||
#define ACL_VAR_TRIGGER_QUEUE_DIR "trigger_queue_dir"
|
||||
@ -53,7 +53,7 @@ extern int acl_var_trigger_delay_usec;
|
||||
extern int acl_var_trigger_daemon_timeout;
|
||||
|
||||
#define ACL_VAR_TRIGGER_USE_LIMIT "trigger_use_limit"
|
||||
#define ACL_DEF_TRIGGER_USE_LIMIT 10
|
||||
#define ACL_DEF_TRIGGER_USE_LIMIT 0
|
||||
extern int acl_var_trigger_use_limit;
|
||||
|
||||
#define ACL_VAR_TRIGGER_ENABLE_CORE "trigger_enable_core"
|
||||
|
@ -22,7 +22,7 @@ extern int acl_var_udp_buf_size;
|
||||
extern int acl_var_udp_rw_timeout;
|
||||
|
||||
#define ACL_VAR_UDP_IDLE_LIMIT "udp_idle_limit"
|
||||
#define ACL_DEF_UDP_IDLE_LIMIT 180
|
||||
#define ACL_DEF_UDP_IDLE_LIMIT 0
|
||||
extern int acl_var_udp_idle_limit;
|
||||
|
||||
#define ACL_VAR_UDP_QUEUE_DIR "udp_queue_dir"
|
||||
|
@ -68,6 +68,8 @@ ACL_API int acl_mempool_total_allocated(void);
|
||||
ACL_API void acl_default_memstat(const char *filename, int line,
|
||||
void *ptr, size_t *len, size_t *real_len);
|
||||
|
||||
ACL_API void acl_default_meminfo(void);
|
||||
|
||||
/**
|
||||
* 设置内存分配最大报警值,即当调用者分配的内存大小达到此报警值后,内部会自动
|
||||
* 记录报警日志,同时将调用堆栈打印至日志中;内部缺少值是 100000000
|
||||
|
@ -128,6 +128,12 @@ ACL_API char *acl_slice_pool_strdup(const char *filename, int line,
|
||||
ACL_API char *acl_slice_pool_strndup(const char *filename, int line,
|
||||
ACL_SLICE_POOL *asp, const char *str, size_t len);
|
||||
|
||||
ACL_API void acl_slice_mem_hook(void *(*malloc_hook)(const char*, int, size_t),
|
||||
void *(*calloc_hook)(const char*, int, size_t, size_t),
|
||||
void *(*realloc_hook)(const char*, int, void*, size_t),
|
||||
void (*free_hook)(const char*, int, void*));
|
||||
ACL_API void acl_slice_mem_unhook(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
3
lib_acl/samples/hook_close/Makefile
Normal file
3
lib_acl/samples/hook_close/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
include ../Makefile_cpp.in
|
||||
EXTLIBS = -ldl
|
||||
PROG = trace
|
156
lib_acl/samples/hook_close/hook_close.cpp
Normal file
156
lib_acl/samples/hook_close/hook_close.cpp
Normal file
@ -0,0 +1,156 @@
|
||||
#include "lib_acl.h"
|
||||
#include <unistd.h>
|
||||
#include <execinfo.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef __USE_GNU
|
||||
#define __USE_GNU
|
||||
#endif
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "hook_close.h"
|
||||
|
||||
static acl_pthread_key_t __trace_key;
|
||||
static acl_pthread_once_t __trace_once = ACL_PTHREAD_ONCE_INIT;
|
||||
static unsigned int *__main_buf = NULL;
|
||||
|
||||
static void trace_buf_free(void *buf)
|
||||
{
|
||||
if ((unsigned long) acl_pthread_self() != acl_main_thread_self())
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static void main_buf_free(void)
|
||||
{
|
||||
if (__main_buf)
|
||||
free(__main_buf);
|
||||
}
|
||||
|
||||
static void trace_buf_init(void)
|
||||
{
|
||||
acl_assert(acl_pthread_key_create(&__trace_key, trace_buf_free) == 0);
|
||||
}
|
||||
|
||||
static void trace_info(const char* prompt)
|
||||
{
|
||||
void *buffer[1000];
|
||||
size_t n, i;
|
||||
char **results;
|
||||
unsigned int *intbuf;
|
||||
|
||||
if (acl_pthread_once(&__trace_once, trace_buf_init) != 0)
|
||||
return;
|
||||
intbuf = (unsigned int *) acl_pthread_getspecific(__trace_key);
|
||||
if (intbuf == NULL) {
|
||||
intbuf = (unsigned int *) malloc(sizeof(int));
|
||||
*intbuf = 0;
|
||||
acl_assert(acl_pthread_setspecific(__trace_key, intbuf) == 0);
|
||||
if ((unsigned long) acl_pthread_self() == acl_main_thread_self()) {
|
||||
__main_buf = intbuf;
|
||||
atexit(main_buf_free);
|
||||
}
|
||||
}
|
||||
|
||||
if ((*intbuf) > 0)
|
||||
return;
|
||||
|
||||
n = backtrace(buffer, 1000);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
(*intbuf)++;
|
||||
|
||||
results = backtrace_symbols(buffer, n);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
acl_msg_info("%s->backtrace: %s", prompt, results[i]);
|
||||
|
||||
if (results != NULL)
|
||||
free(results);
|
||||
|
||||
(*intbuf)--;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
typedef int (*close_fn)(int);
|
||||
static close_fn __sys_close = NULL;
|
||||
|
||||
void hook_setup(void) __attribute__ ((constructor));
|
||||
void hook_setup(void)
|
||||
{
|
||||
__sys_close = (close_fn) dlsym(RTLD_NEXT, "close");
|
||||
}
|
||||
|
||||
static int __monitor_ports[100];
|
||||
static int __monitor_ports_max = sizeof(__monitor_ports);
|
||||
static int __monitor_ports_cur = 0;
|
||||
|
||||
int monitor_port_add(int port)
|
||||
{
|
||||
if (port <= 0) {
|
||||
acl_msg_error("%s(%d), %s: invalid port: %d",
|
||||
__FILE__, __LINE__, __FUNCTION__, port);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (__monitor_ports_cur >= __monitor_ports_max) {
|
||||
acl_msg_error("too many ports added, cur: %d, max: %d",
|
||||
__monitor_ports_cur, __monitor_ports_max);
|
||||
return __monitor_ports_cur;
|
||||
}
|
||||
|
||||
__monitor_ports[__monitor_ports_cur] = port;
|
||||
__monitor_ports_cur++;
|
||||
return __monitor_ports_cur;
|
||||
}
|
||||
|
||||
static int should_check(int port)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (port <= 0) {
|
||||
acl_msg_error("%s(%d), %s: invalid port: %d",
|
||||
__FILE__, __LINE__, __FUNCTION__, port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < __monitor_ports_cur; i++) {
|
||||
if (__monitor_ports[i] == port)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
char peer[64], *at, buf[256];
|
||||
|
||||
if (fd < 0) {
|
||||
acl_msg_error("%s(%d), %s: invalid fd: %d",
|
||||
__FILE__, __LINE__, __FUNCTION__, fd);
|
||||
trace_info("invalid fd");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (__monitor_ports_cur == 0
|
||||
|| acl_getpeername(fd, peer, sizeof(peer)) == -1)
|
||||
{
|
||||
peer[0] = 0;
|
||||
} else if ((at = strchr(peer, ':')) && *++at && should_check(atoi(at))) {
|
||||
snprintf(buf, sizeof(buf), "closing %s", peer);
|
||||
trace_info(buf);
|
||||
}
|
||||
|
||||
if (__sys_close(fd) == 0)
|
||||
return 0;
|
||||
|
||||
snprintf(buf, sizeof(buf), "close error %s, fd=%d, peer=%s",
|
||||
acl_last_serror(), fd, peer);
|
||||
trace_info(buf);
|
||||
|
||||
return -1;
|
||||
}
|
14
lib_acl/samples/hook_close/hook_close.h
Normal file
14
lib_acl/samples/hook_close/hook_close.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __HOOK_CLOSE_H_INCLUDE__
|
||||
#define __HOOK_CLOSE_H_INCLUDE__
|
||||
|
||||
#ifdef __cpluplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
int monitor_port_add(int port);
|
||||
|
||||
#ifdef __cpluplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
69
lib_acl/samples/hook_close/main.cpp
Normal file
69
lib_acl/samples/hook_close/main.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "lib_acl.h"
|
||||
#include "hook_close.h"
|
||||
|
||||
static void check_connection(const char *server_addr)
|
||||
{
|
||||
ACL_VSTREAM *conn = acl_vstream_connect(server_addr, ACL_BLOCKING,
|
||||
0, 0, 8192);
|
||||
|
||||
if (conn == NULL) {
|
||||
printf("connect %s error %s\r\n", server_addr, acl_last_serror());
|
||||
return;
|
||||
}
|
||||
|
||||
acl_vstream_close(conn);
|
||||
}
|
||||
|
||||
static void usage(const char *procname)
|
||||
{
|
||||
printf("usage: %s -h[help] -s server_addr[default: 127.0.0.1:6379]\r\n"
|
||||
" -p monitor_ports[default: 6379]\r\n", procname);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
char addr[64], ports[256];
|
||||
ACL_ARGV *tokens;
|
||||
ACL_ITER iter;
|
||||
|
||||
acl_msg_stdout_enable(1);
|
||||
|
||||
snprintf(addr, sizeof(addr), "127.0.0.1:6379");
|
||||
snprintf(ports, sizeof(ports), "6379");
|
||||
|
||||
while ((ch = getopt(argc, argv, "hs:p:")) > 0) {
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
return 0;
|
||||
case 's':
|
||||
snprintf(addr, sizeof(addr), "%s", optarg);
|
||||
break;
|
||||
case 'p':
|
||||
snprintf(ports, sizeof(ports), "%s", optarg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tokens = acl_argv_split(ports, ",; \t");
|
||||
|
||||
acl_foreach(iter, tokens) {
|
||||
const char *ptr = (const char *) iter.data;
|
||||
int port = atoi(ptr);
|
||||
|
||||
monitor_port_add(port); // add one port to be monitored
|
||||
}
|
||||
|
||||
acl_argv_free(tokens);
|
||||
|
||||
check_connection(addr);
|
||||
|
||||
return (0);
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
#include "db/zdb.h"
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#if defined(ACL_LINUX) && !defined(MINGW) && defined(__GNUC__) && __GNUC__ >= 4
|
||||
# ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
@ -25,6 +26,7 @@
|
||||
# define PREAD pread64
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "zdb_private.h"
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include "init.h"
|
||||
|
||||
static char *version = "acl_3.2.2";
|
||||
static char *version = "acl_3.2.2_2";
|
||||
|
||||
const char *acl_version(void)
|
||||
{
|
||||
|
@ -291,6 +291,96 @@ static void service_unix(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
|
||||
|
||||
/* Inet/Unix socket service */
|
||||
|
||||
static unsigned addr_matched(const ACL_ARGV *tokens, const char *ip)
|
||||
{
|
||||
ACL_ARGV *tokens_addr = acl_argv_split(ip, ".");
|
||||
ACL_ITER iter;
|
||||
int i = 0;
|
||||
|
||||
if (tokens_addr->argc != 4) {
|
||||
acl_msg_warn("%s(%d), %s: invalid ip: %s",
|
||||
__FILE__, __LINE__, __FUNCTION__, ip);
|
||||
acl_argv_free(tokens_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
acl_foreach(iter, tokens_addr) {
|
||||
const char* ptr = (const char *) iter.data;
|
||||
const char* arg = tokens->argv[i];
|
||||
if (strcmp(arg, "*") != 0 && strcmp(arg, ptr) != 0) {
|
||||
acl_argv_free(tokens_addr);
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
acl_argv_free(tokens_addr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static unsigned service_inet_expand(ACL_MASTER_SERV *serv, const char *path)
|
||||
{
|
||||
ACL_ARGV *tokens = NULL;
|
||||
ACL_IFCONF *ifconf = NULL;
|
||||
char buf[256], *colon;
|
||||
int port;
|
||||
ACL_ITER iter;
|
||||
unsigned naddr = 0;
|
||||
|
||||
#define RETURN(x) do { \
|
||||
if (tokens != NULL) \
|
||||
acl_argv_free(tokens); \
|
||||
if (ifconf != NULL) \
|
||||
acl_free_ifaddrs(ifconf); \
|
||||
return (x); \
|
||||
} while (0)
|
||||
|
||||
/* xxx.xxx.xxx.xxx:port, xxx.xxx.xxx.*:port ...*/
|
||||
snprintf(buf, sizeof(buf), "%s", path);
|
||||
colon = strchr(buf, ':');
|
||||
if (colon == NULL || colon == buf || *(colon + 1) == 0)
|
||||
RETURN(0);
|
||||
*colon++ = 0;
|
||||
port = atoi(colon);
|
||||
if (port < 0) {
|
||||
acl_msg_warn("%s(%d), %s: invalid port: %d, path: %s",
|
||||
__FILE__, __LINE__, __FUNCTION__, port, path);
|
||||
RETURN(0);
|
||||
}
|
||||
|
||||
/* format: xxx.xxx.xxx.*, xxx.xxx.*.*, xxx.*.*.* */
|
||||
tokens = acl_argv_split(buf, ".");
|
||||
if (tokens->argc != 4)
|
||||
RETURN(0);
|
||||
|
||||
ifconf = acl_get_ifaddrs();
|
||||
if (ifconf == NULL) {
|
||||
acl_msg_error("%s(%d), %s: acl_get_ifaddrs error %s",
|
||||
__FILE__, __LINE__, __FUNCTION__, acl_last_serror());
|
||||
RETURN(0);
|
||||
}
|
||||
|
||||
acl_foreach(iter, ifconf) {
|
||||
const ACL_IFADDR* ifaddr = (const ACL_IFADDR *) iter.data;
|
||||
|
||||
if (addr_matched(tokens, ifaddr->ip)) {
|
||||
ACL_MASTER_ADDR *addr = (ACL_MASTER_ADDR*)
|
||||
acl_mycalloc(1, sizeof(ACL_MASTER_ADDR));
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s:%d", ifaddr->ip, port);
|
||||
addr->type = ACL_MASTER_SERV_TYPE_INET;
|
||||
addr->addr = acl_mystrdup(buf);
|
||||
acl_array_append(serv->addrs, addr);
|
||||
serv->listen_fd_count++;
|
||||
naddr++;
|
||||
acl_msg_info("%s(%d), %s: add addr=%s", __FILE__,
|
||||
__LINE__, __FUNCTION__, buf);
|
||||
}
|
||||
}
|
||||
|
||||
return naddr;
|
||||
}
|
||||
|
||||
static void service_sock(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
|
||||
{
|
||||
/*
|
||||
@ -307,23 +397,33 @@ static void service_sock(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
|
||||
|
||||
acl_foreach(iter, tokens) {
|
||||
const char *path = (const char*) iter.data;
|
||||
ACL_MASTER_ADDR *addr = (ACL_MASTER_ADDR*)
|
||||
acl_mycalloc(1, sizeof(ACL_MASTER_ADDR));
|
||||
|
||||
if (acl_ipv4_addr_valid(path) || acl_alldig(path)
|
||||
|| (*path == ':' && acl_alldig(path + 1)))
|
||||
{
|
||||
ACL_MASTER_ADDR *addr = (ACL_MASTER_ADDR*)
|
||||
acl_mycalloc(1, sizeof(ACL_MASTER_ADDR));
|
||||
|
||||
addr->type = ACL_MASTER_SERV_TYPE_INET;
|
||||
addr->addr = acl_mystrdup(path);
|
||||
} else {
|
||||
acl_array_append(serv->addrs, addr);
|
||||
serv->listen_fd_count++;
|
||||
acl_msg_info("%s(%d), %s: add addr=%s", __FILE__,
|
||||
__LINE__, __FUNCTION__, path);
|
||||
} else if (service_inet_expand(serv, path) == 0) {
|
||||
ACL_MASTER_ADDR *addr = (ACL_MASTER_ADDR*)
|
||||
acl_mycalloc(1, sizeof(ACL_MASTER_ADDR));
|
||||
|
||||
addr->type = ACL_MASTER_SERV_TYPE_UNIX;
|
||||
addr->addr = acl_master_pathname(
|
||||
acl_var_master_queue_dir, private_val
|
||||
? ACL_MASTER_CLASS_PRIVATE :
|
||||
acl_var_master_queue_dir,
|
||||
private_val ? ACL_MASTER_CLASS_PRIVATE :
|
||||
ACL_MASTER_CLASS_PUBLIC, path);
|
||||
acl_array_append(serv->addrs, addr);
|
||||
serv->listen_fd_count++;
|
||||
acl_msg_info("%s(%d), %s: add addr=%s", __FILE__,
|
||||
__LINE__, __FUNCTION__, path);
|
||||
}
|
||||
acl_array_append(serv->addrs, addr);
|
||||
serv->listen_fd_count++;
|
||||
}
|
||||
|
||||
acl_argv_free(tokens);
|
||||
|
@ -157,6 +157,7 @@ static pthread_mutex_t __counter_mutex;
|
||||
static ACL_AIO_SERVER_FN __service_main;
|
||||
static ACL_AIO_SERVER2_FN __service2_main;
|
||||
static ACL_MASTER_SERVER_EXIT_FN __service_onexit;
|
||||
static ACL_MASTER_SERVER_LISTEN_FN __service_on_listen;
|
||||
static char *__service_name;
|
||||
static char **__service_argv;
|
||||
static void *__service_ctx;
|
||||
@ -1173,6 +1174,8 @@ static ACL_ASTREAM **create_listener(ACL_AIO *aio, int event_mode acl_unused,
|
||||
|
||||
/* ÉèÖÃÒì²½¼àÌý */
|
||||
acl_aio_listen(as);
|
||||
if (__service_on_listen)
|
||||
__service_on_listen(vs);
|
||||
sstreams[i++] = as;
|
||||
|
||||
if (acl_var_aio_accept_timer <= 0)
|
||||
@ -1372,6 +1375,10 @@ static void server_main(int argc, char **argv, va_list ap)
|
||||
__service_onexit =
|
||||
va_arg(ap, ACL_MASTER_SERVER_EXIT_FN);
|
||||
break;
|
||||
case ACL_MASTER_SERVER_ON_LISTEN:
|
||||
__service_on_listen =
|
||||
va_arg(ap, ACL_MASTER_SERVER_LISTEN_FN);
|
||||
break;
|
||||
default:
|
||||
acl_msg_warn("%s: unknown argument type: %d",
|
||||
myname, key);
|
||||
|
@ -109,6 +109,7 @@ static int use_count;
|
||||
static ACL_EVENT *__eventp = NULL;
|
||||
static ACL_VSTREAM **__sstreams = NULL;
|
||||
|
||||
static ACL_MASTER_SERVER_LISTEN_FN __service_on_listen;
|
||||
static ACL_SINGLE_SERVER_FN __service_main;
|
||||
static ACL_MASTER_SERVER_EXIT_FN __service_onexit;
|
||||
static char *__service_name;
|
||||
@ -506,6 +507,9 @@ void acl_single_server_main(int argc, char **argv, ACL_SINGLE_SERVER_FN service,
|
||||
acl_get_app_conf_bool_table(va_arg(ap, ACL_CONFIG_BOOL_TABLE *));
|
||||
break;
|
||||
|
||||
case ACL_MASTER_SERVER_ON_LISTEN:
|
||||
__service_on_listen = va_arg(ap, ACL_MASTER_SERVER_LISTEN_FN);
|
||||
break;
|
||||
case ACL_MASTER_SERVER_CTX:
|
||||
__service_ctx = va_arg(ap, void *);
|
||||
break;
|
||||
@ -669,6 +673,8 @@ void acl_single_server_main(int argc, char **argv, ACL_SINGLE_SERVER_FN service,
|
||||
for (; fd < ACL_MASTER_LISTEN_FD + socket_count; fd++) {
|
||||
stream = acl_vstream_fdopen(fd, O_RDWR, acl_var_single_buf_size,
|
||||
acl_var_single_rw_timeout, fdtype);
|
||||
if (__service_on_listen)
|
||||
__service_on_listen(stream);
|
||||
__sstreams[i++] = stream;
|
||||
|
||||
acl_event_enable_listen(__eventp, stream, 0,
|
||||
|
@ -166,6 +166,7 @@ static char __service_name[256];
|
||||
static void (*__server_accept) (int, ACL_EVENT *, ACL_VSTREAM *, void *);
|
||||
static ACL_THREADS_SERVER_FN __service_main;
|
||||
static ACL_MASTER_SERVER_EXIT_FN __server_onexit;
|
||||
static ACL_MASTER_SERVER_LISTEN_FN __server_on_listen;
|
||||
static ACL_MASTER_SERVER_ACCEPT_FN __server_on_accept;
|
||||
static ACL_MASTER_SERVER_HANDSHAKE_FN __server_on_handshake;
|
||||
static ACL_MASTER_SERVER_DISCONN_FN __server_on_close;
|
||||
@ -1131,7 +1132,9 @@ static ACL_VSTREAM **server_daemon_open(ACL_EVENT *event,
|
||||
acl_non_blocking(fd, ACL_NON_BLOCKING);
|
||||
acl_close_on_exec(fd, ACL_CLOSE_ON_EXEC);
|
||||
acl_event_enable_listen(event, stream, 0,
|
||||
__server_accept, threads);
|
||||
__server_accept, threads);
|
||||
if (__server_on_listen)
|
||||
__server_on_listen(stream);
|
||||
streams[i++] = stream;
|
||||
}
|
||||
|
||||
@ -1170,6 +1173,8 @@ static ACL_VSTREAM **server_alone_open(ACL_EVENT *event,
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (__server_on_listen)
|
||||
__server_on_listen(sstream);
|
||||
streams[i++] = sstream;
|
||||
|
||||
acl_non_blocking(ACL_VSTREAM_SOCK(sstream), ACL_NON_BLOCKING);
|
||||
@ -1322,6 +1327,10 @@ void acl_threads_server_main(int argc, char * argv[],
|
||||
case ACL_MASTER_SERVER_POST_INIT:
|
||||
post_init = va_arg(ap, ACL_MASTER_SERVER_INIT_FN);
|
||||
break;
|
||||
case ACL_MASTER_SERVER_ON_LISTEN:
|
||||
__server_on_listen =
|
||||
va_arg(ap, ACL_MASTER_SERVER_LISTEN_FN);
|
||||
break;
|
||||
case ACL_MASTER_SERVER_ON_ACCEPT:
|
||||
__server_on_accept =
|
||||
va_arg(ap, ACL_MASTER_SERVER_ACCEPT_FN);
|
||||
|
@ -2109,6 +2109,7 @@ ACL_VSTREAM *acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
{
|
||||
const char *myname = "acl_vstream_fdopen";
|
||||
ACL_VSTREAM *fp;
|
||||
int ret;
|
||||
|
||||
fp = (ACL_VSTREAM *) acl_mycalloc(1, sizeof(ACL_VSTREAM));
|
||||
|
||||
@ -2119,13 +2120,17 @@ ACL_VSTREAM *acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
myname, __LINE__, (int) buflen);
|
||||
}
|
||||
|
||||
if (buflen < ACL_VSTREAM_DEF_MAXLEN)
|
||||
buflen = ACL_VSTREAM_DEF_MAXLEN;
|
||||
|
||||
/* XXX: 只有非监听流才需要有读缓冲区 */
|
||||
/* XXX: 目前 UDP 服务端口号在 MASTER 框架中暂时当监听套接口用,所以
|
||||
ÐèÒª¸øÆä·ÖÅä¶Á»º³åÇø
|
||||
* 需要给其分配读缓冲区
|
||||
*/
|
||||
if (buflen < ACL_VSTREAM_DEF_MAXLEN)
|
||||
buflen = ACL_VSTREAM_DEF_MAXLEN;
|
||||
fp->read_buf = (unsigned char *) acl_mymalloc(buflen + 1);
|
||||
fp->read_buf_len = (int) buflen;
|
||||
fp->addr_local = __empty_string;
|
||||
fp->addr_peer = __empty_string;
|
||||
fp->path = __empty_string;
|
||||
|
||||
#ifdef ACL_MACOSX
|
||||
if ((fdtype & ACL_VSTREAM_TYPE_LISTEN_INET)
|
||||
@ -2135,26 +2140,12 @@ ACL_VSTREAM *acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fd != ACL_SOCKET_INVALID && acl_is_listening_socket(fd)) {
|
||||
int ret = acl_getsocktype(fd);
|
||||
if (ret == AF_INET)
|
||||
fdtype |= ACL_VSTREAM_TYPE_LISTEN_INET;
|
||||
#ifndef ACL_WINDOWS
|
||||
else if (ret == AF_UNIX)
|
||||
fdtype |= ACL_VSTREAM_TYPE_LISTEN_UNIX;
|
||||
#endif
|
||||
fdtype |= ACL_VSTREAM_TYPE_LISTEN;
|
||||
}
|
||||
|
||||
fp->read_buf = (unsigned char *) acl_mymalloc(buflen + 1);
|
||||
|
||||
if (fdtype == 0) {
|
||||
fdtype = ACL_VSTREAM_TYPE_SOCK;
|
||||
acl_msg_warn("%s(%d): fdtype(0), set to ACL_VSTREAM_TYPE_SOCK",
|
||||
myname, __LINE__);
|
||||
}
|
||||
|
||||
fp->read_buf_len = (int) buflen;
|
||||
fp->type = fdtype;
|
||||
ACL_VSTREAM_SOCK(fp) = fd;
|
||||
#ifdef ACL_WINDOWS
|
||||
@ -2162,6 +2153,8 @@ ACL_VSTREAM *acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
#endif
|
||||
fp->read_ptr = fp->read_buf;
|
||||
fp->oflags = oflags;
|
||||
fp->omode = 0600;
|
||||
fp->close_handle_lnk = acl_array_create(8);
|
||||
ACL_SAFE_STRNCPY(fp->errbuf, "OK", sizeof(fp->errbuf));
|
||||
|
||||
if (rw_timeout > 0)
|
||||
@ -2179,20 +2172,43 @@ ACL_VSTREAM *acl_vstream_fdopen(ACL_SOCKET fd, unsigned int oflags,
|
||||
fp->writev_fn = acl_socket_writev_fn;
|
||||
fp->close_fn = acl_socket_close_fn;
|
||||
|
||||
/**
|
||||
* bugfix: 不应在此处直接设为非阻塞方式,否则会影响上层调用者
|
||||
* 的行为,应该在应用自己来处理此事。---zsx, 2016.11.18
|
||||
*/
|
||||
/* xxx: 对于带有读写超时的流,需要先将 socket 设为非阻塞模式,
|
||||
* 否则在写大数据包时会造成阻塞,超时作用失效
|
||||
*/
|
||||
if (rw_timeout > 0 && acl_getsocktype(fd) >= 0)
|
||||
acl_non_blocking(fd, ACL_NON_BLOCKING);
|
||||
/**
|
||||
* if (rw_timeout > 0 && acl_getsocktype(fd) >= 0)
|
||||
* acl_non_blocking(fd, ACL_NON_BLOCKING);
|
||||
*/
|
||||
}
|
||||
|
||||
fp->addr_local = __empty_string;
|
||||
fp->addr_peer = __empty_string;
|
||||
fp->path = __empty_string;
|
||||
fp->oflags = 0;
|
||||
fp->omode = 0600;
|
||||
if (fd == ACL_SOCKET_INVALID)
|
||||
return fp;
|
||||
|
||||
if ((ret = acl_check_socket(fd)) == 1) {
|
||||
ret = acl_getsocktype(fd);
|
||||
if (ret == AF_INET)
|
||||
fp->type |= ACL_VSTREAM_TYPE_LISTEN_INET;
|
||||
#ifndef ACL_WINDOWS
|
||||
else if (ret == AF_UNIX)
|
||||
fp->type |= ACL_VSTREAM_TYPE_LISTEN_UNIX;
|
||||
#endif
|
||||
fp->type |= ACL_VSTREAM_TYPE_LISTEN;
|
||||
|
||||
if (acl_getsockname(fd, (char *) fp->read_buf, buflen) == 0)
|
||||
acl_vstream_set_local(fp, (char *) fp->read_buf);
|
||||
} else if (ret == 0
|
||||
&& acl_getsockname(fd, (char *) fp->read_buf, buflen) == 0)
|
||||
{
|
||||
acl_vstream_set_local(fp, (char *) fp->read_buf);
|
||||
fp->type |= ACL_VSTREAM_TYPE_SOCK;
|
||||
if (acl_getpeername(fd, (char *) fp->read_buf, buflen) == 0)
|
||||
acl_vstream_set_peer(fp, (char *) fp->read_buf);
|
||||
}
|
||||
|
||||
fp->close_handle_lnk = acl_array_create(8);
|
||||
return fp;
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,9 @@ void acl_ring_init(ACL_RING *ring)
|
||||
int acl_ring_size(const ACL_RING *ring)
|
||||
{
|
||||
if (ring == NULL)
|
||||
return (-1);
|
||||
return -1;
|
||||
|
||||
return (ring->len);
|
||||
return ring->len;
|
||||
}
|
||||
|
||||
/* acl_ring_append - insert entry after ring head */
|
||||
@ -67,7 +67,7 @@ void acl_ring_detach(ACL_RING *entry)
|
||||
ACL_RING *succ;
|
||||
ACL_RING *pred;
|
||||
|
||||
if (entry == NULL)
|
||||
if (entry == NULL || entry->parent == entry)
|
||||
return;
|
||||
succ = entry->succ;
|
||||
pred = entry->pred;
|
||||
@ -90,15 +90,15 @@ ACL_RING *acl_ring_pop_head(ACL_RING *ring)
|
||||
ACL_RING *succ;
|
||||
|
||||
if (ring == NULL)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
|
||||
succ = ring->succ;
|
||||
if (succ == ring)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
|
||||
acl_ring_detach(succ);
|
||||
|
||||
return (succ);
|
||||
return succ;
|
||||
}
|
||||
|
||||
/* acl_ring_pop_tail - pop ring's tail entry out from ring */
|
||||
@ -108,13 +108,13 @@ ACL_RING *acl_ring_pop_tail(ACL_RING *ring)
|
||||
ACL_RING *pred;
|
||||
|
||||
if (ring == NULL)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
|
||||
pred = ring->pred;
|
||||
if (pred == ring)
|
||||
return (NULL);
|
||||
return NULL;
|
||||
|
||||
acl_ring_detach(pred);
|
||||
|
||||
return (pred);
|
||||
return pred;
|
||||
}
|
||||
|
@ -268,10 +268,12 @@ int acl_read_wait(ACL_SOCKET fd, int timeout)
|
||||
acl_last_serror(), (int) fd);
|
||||
return -1;
|
||||
case 0:
|
||||
/*
|
||||
acl_msg_warn("%s(%d), %s: poll timeout: %s, fd: %d, "
|
||||
"delay: %d, spent: %ld", __FILE__, __LINE__,
|
||||
myname, acl_last_serror(), fd, delay,
|
||||
(long) (time(NULL) - begin));
|
||||
*/
|
||||
acl_set_error(ACL_ETIMEDOUT);
|
||||
return -1;
|
||||
default:
|
||||
|
@ -126,6 +126,17 @@ static char empty_string[] = "";
|
||||
} while (0)
|
||||
#endif /* ACL_WINDOWS */
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
static __thread int __nmalloc = 0;
|
||||
static __thread int __ncalloc = 0;
|
||||
static __thread int __nrealloc = 0;
|
||||
static __thread int __nfree = 0;
|
||||
static __thread int __nstrdup = 0;
|
||||
static __thread int __nstrndup = 0;
|
||||
static __thread int __nmemdup = 0;
|
||||
static __thread ssize_t __nsize = 0;
|
||||
#endif
|
||||
|
||||
void acl_default_memstat(const char *filename, int line,
|
||||
void *ptr, size_t *len, size_t *real_len)
|
||||
{
|
||||
@ -145,6 +156,17 @@ void acl_default_memstat(const char *filename, int line,
|
||||
*real_len = SPACE_FOR(*len);
|
||||
}
|
||||
|
||||
void acl_default_meminfo(void)
|
||||
{
|
||||
#ifdef DEBUG_MEM
|
||||
printf("%s(%d): __nmalloc: %d, __ncalloc: %d, __nrealloc: %d, "
|
||||
"__nfree: %d, diff: %d, __nsize: %ld\r\n",
|
||||
__FUNCTION__, __LINE__, __nmalloc, __ncalloc, __nrealloc,
|
||||
__nfree, __nmalloc + __nrealloc - __nfree,
|
||||
(unsigned long) __nsize);
|
||||
#endif
|
||||
}
|
||||
|
||||
void acl_default_set_memlimit(size_t len)
|
||||
{
|
||||
acl_assert(len > 0);
|
||||
@ -163,6 +185,7 @@ void *acl_default_malloc(const char *filename, int line, size_t len)
|
||||
char *ptr;
|
||||
MBLOCK *real_ptr;
|
||||
const char *pname = NULL;
|
||||
|
||||
#if 0
|
||||
printf("%s:%d, len: %d\r\n", filename, line, (int) len);
|
||||
acl_trace_info();
|
||||
@ -190,6 +213,11 @@ void *acl_default_malloc(const char *filename, int line, size_t len)
|
||||
acl_trace_info();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__nmalloc++;
|
||||
__nsize += new_len;
|
||||
#endif
|
||||
|
||||
#ifdef _USE_GLIB
|
||||
if ((real_ptr = (MBLOCK *) g_malloc(new_len)) == 0) {
|
||||
acl_msg_error("%s(%d)->%s: new_len: %d, g_malloc error(%s)",
|
||||
@ -204,11 +232,8 @@ void *acl_default_malloc(const char *filename, int line, size_t len)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
CHECK_OUT_PTR(ptr, real_ptr, len);
|
||||
#if 0
|
||||
memset(ptr, FILLER, len);
|
||||
#endif
|
||||
|
||||
CHECK_OUT_PTR(ptr, real_ptr, len);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -218,6 +243,9 @@ void *acl_default_calloc(const char *filename, int line,
|
||||
void *ptr;
|
||||
int n;
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__ncalloc++;
|
||||
#endif
|
||||
n = (int) (nmemb * size);
|
||||
ptr = acl_default_malloc(filename, line, n);
|
||||
memset(ptr, FILLER, n);
|
||||
@ -266,6 +294,11 @@ void *acl_default_realloc(const char *filename, int line,
|
||||
acl_trace_info();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__nrealloc++;
|
||||
__nsize += new_len - old_len;
|
||||
#endif
|
||||
|
||||
#ifdef _USE_GLIB
|
||||
if ((real_ptr = (MBLOCK *) g_realloc((char *) real_ptr, new_len)) == 0)
|
||||
acl_msg_fatal("%s(%d)->%s: realloc: insufficient memory: %s",
|
||||
@ -310,6 +343,12 @@ void acl_default_free(const char *filename, int line, void *ptr)
|
||||
/*
|
||||
memset((char *) real_ptr, FILLER, SPACE_FOR(len));
|
||||
*/
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__nfree++;
|
||||
__nsize -= len;
|
||||
#endif
|
||||
|
||||
#ifdef _USE_GLIB
|
||||
g_free(real_ptr);
|
||||
#else
|
||||
@ -340,6 +379,11 @@ char *acl_default_strdup(const char *filename, int line, const char *str)
|
||||
if (*str == 0)
|
||||
return (char *) empty_string;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__nstrdup++;
|
||||
#endif
|
||||
|
||||
return strcpy(acl_default_malloc(pname, line, strlen(str) + 1), str);
|
||||
}
|
||||
|
||||
@ -366,8 +410,14 @@ char *acl_default_strndup(const char *filename, int line,
|
||||
if (*str == 0)
|
||||
return (char *) empty_string;
|
||||
#endif
|
||||
|
||||
if ((cp = memchr(str, 0, len)) != 0)
|
||||
len = cp - str;
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__nstrndup++;
|
||||
#endif
|
||||
|
||||
result = memcpy(acl_default_malloc(pname, line, len + 1), str, len);
|
||||
result[len] = 0;
|
||||
return result;
|
||||
@ -389,5 +439,10 @@ void *acl_default_memdup(const char *filename, int line,
|
||||
if (ptr == 0)
|
||||
acl_msg_fatal("%s(%d)->%s: null pointer argument",
|
||||
pname, line, myname);
|
||||
|
||||
#ifdef DEBUG_MEM
|
||||
__nmemdup++;
|
||||
#endif
|
||||
|
||||
return memcpy(acl_default_malloc(pname, line, len), ptr, len);
|
||||
}
|
||||
|
@ -87,44 +87,52 @@ typedef struct {
|
||||
#define FILLER 0x0
|
||||
|
||||
#define CHECK_PTR(_ptr, _real_ptr, _len, _fname, _line) { \
|
||||
if (_ptr == 0) \
|
||||
acl_msg_panic("%s(%d): null pointer input", _fname, _line); \
|
||||
_real_ptr = (MBLOCK *) ((char *) _ptr - offsetof(MBLOCK, u.payload[0])); \
|
||||
if (_real_ptr->signature != SIGNATURE) \
|
||||
acl_msg_panic("%s(%d)(CHECK_PTR): corrupt or unallocated memory block(%d, 0x%x, 0x%x)", \
|
||||
_fname, _line, (int) _real_ptr->length, _real_ptr->signature, SIGNATURE); \
|
||||
if ((_len = _real_ptr->length) < 1) \
|
||||
acl_msg_panic("%s(%d): corrupt memory block length", _fname, _line); \
|
||||
if (_ptr == 0) \
|
||||
acl_msg_panic("%s(%d), %s: in %s(%d), null pointer input", \
|
||||
__FILE__, __LINE__, __FUNCTION__, _fname, _line); \
|
||||
_real_ptr = (MBLOCK *) ((char *) _ptr - offsetof(MBLOCK, u.payload[0])); \
|
||||
if (_real_ptr->signature != SIGNATURE) \
|
||||
acl_msg_panic("%s(%d), %s: in %s(%d), corrupt or unallocated memory block(%d, 0x%x, 0x%x)", \
|
||||
__FILE__, __LINE__, __FUNCTION__, _fname, _line, \
|
||||
(int) _real_ptr->length, _real_ptr->signature, SIGNATURE); \
|
||||
if ((_len = _real_ptr->length) < 1) \
|
||||
acl_msg_panic("%s(%d), %s: in %s(%d), corrupt memory block length", \
|
||||
__FILE__, __LINE__, __FUNCTION__, _fname, _line); \
|
||||
}
|
||||
|
||||
#define CHECK_IN_PTR(_ptr, _real_ptr, _len, _fname, _line) { \
|
||||
if (_ptr == 0) \
|
||||
acl_msg_panic("%s(%d): null pointer input", _fname, _line); \
|
||||
_real_ptr = (MBLOCK *) ((char *) _ptr - offsetof(MBLOCK, u.payload[0])); \
|
||||
if (_real_ptr->signature != SIGNATURE) \
|
||||
acl_msg_panic("%s(%d)(CHECK_IN_PTR): corrupt or unallocated memory block(%d, 0x%x, 0x%x)", \
|
||||
_fname, _line, (int) _real_ptr->length, _real_ptr->signature, SIGNATURE); \
|
||||
_real_ptr->signature = 0; \
|
||||
if ((_len = _real_ptr->length) < 1) \
|
||||
acl_msg_panic("%s(%d): corrupt memory block length", _fname, _line); \
|
||||
if (_ptr == 0) \
|
||||
acl_msg_panic("%s(%d), %s: in %s(%d), null pointer input", \
|
||||
__FILE__, __LINE__, __FUNCTION__, _fname, _line); \
|
||||
_real_ptr = (MBLOCK *) ((char *) _ptr - offsetof(MBLOCK, u.payload[0])); \
|
||||
if (_real_ptr->signature != SIGNATURE) \
|
||||
acl_msg_panic("%s(%d), %s: in %s(%d), corrupt or unallocated memory block(%d, 0x%x, 0x%x)", \
|
||||
__FILE__, __LINE__, __FUNCTION__, _fname, _line, \
|
||||
(int) _real_ptr->length, _real_ptr->signature, SIGNATURE); \
|
||||
_real_ptr->signature = 0; \
|
||||
if ((_len = _real_ptr->length) < 1) \
|
||||
acl_msg_panic("%s(%d), %s: in %s(%d), corrupt memory block length", \
|
||||
__FILE__, __LINE__, __FUNCTION__, _fname, _line); \
|
||||
}
|
||||
|
||||
#define CHECK_IN_PTR2(_ptr, _real_ptr, _len, _fname, _line) { \
|
||||
if (_ptr == 0) \
|
||||
acl_msg_panic("%s(%d): null pointer input", _fname, _line); \
|
||||
_real_ptr = (MBLOCK *) ((char *) _ptr - offsetof(MBLOCK, u.payload[0])); \
|
||||
if (_real_ptr->signature != SIGNATURE) \
|
||||
acl_msg_panic("%s(%d)(CHECK_IN_PTR2): corrupt or unallocated memory block(%d, 0x%x, 0x%x)", \
|
||||
_fname, _line, (int) _real_ptr->length, _real_ptr->signature, SIGNATURE); \
|
||||
if ((_len = _real_ptr->length) < 1) \
|
||||
acl_msg_panic("%s(%d): corrupt memory block length", _fname, _line); \
|
||||
if (_ptr == 0) \
|
||||
acl_msg_panic("%s(%d), %s: in %s(%d), null pointer input", \
|
||||
__FILE__, __LINE__, __FUNCTION__, _fname, _line); \
|
||||
_real_ptr = (MBLOCK *) ((char *) _ptr - offsetof(MBLOCK, u.payload[0])); \
|
||||
if (_real_ptr->signature != SIGNATURE) \
|
||||
acl_msg_panic("%s(%d)(CHECK_IN_PTR2): corrupt or unallocated memory block(%d, 0x%x, 0x%x)", \
|
||||
_fname, _line, (int) _real_ptr->length, _real_ptr->signature, SIGNATURE); \
|
||||
if ((_len = _real_ptr->length) < 1) \
|
||||
acl_msg_panic("%s(%d), %s: in %s(%d) corrupt memory block length", \
|
||||
__FILE__, __LINE__, __FUNCTION__, _fname, _line); \
|
||||
}
|
||||
|
||||
#define CHECK_OUT_PTR(_ptr, _real_ptr, _mem_slice, _len) { \
|
||||
_real_ptr->signature = SIGNATURE; \
|
||||
_real_ptr->mem_slice = _mem_slice; \
|
||||
_real_ptr->length = _len; \
|
||||
_ptr = _real_ptr->u.payload; \
|
||||
_real_ptr->signature = SIGNATURE; \
|
||||
_real_ptr->mem_slice = _mem_slice; \
|
||||
_real_ptr->length = _len; \
|
||||
_ptr = _real_ptr->u.payload; \
|
||||
}
|
||||
|
||||
#define SPACE_FOR(_len) (offsetof(MBLOCK, u.payload[0]) + _len)
|
||||
@ -236,7 +244,7 @@ static ACL_MEM_SLICE *mem_slice_create(void)
|
||||
|
||||
mem_slice = acl_pthread_getspecific(__mem_slice_key);
|
||||
if (mem_slice != NULL)
|
||||
return (mem_slice);
|
||||
return mem_slice;
|
||||
|
||||
mem_slice = (ACL_MEM_SLICE*)
|
||||
acl_default_calloc(__FILE__, __LINE__, 1, sizeof(ACL_MEM_SLICE));
|
||||
@ -261,7 +269,7 @@ static ACL_MEM_SLICE *mem_slice_create(void)
|
||||
acl_msg_info("%s(%d): thread(%ld) set myown mem_slice(%p)",
|
||||
myname, __LINE__, (long) mem_slice->tid, mem_slice);
|
||||
|
||||
return (mem_slice);
|
||||
return mem_slice;
|
||||
}
|
||||
|
||||
static void tls_mem_free(const char *filename, int line, void *ptr)
|
||||
@ -308,7 +316,7 @@ static void *tls_mem_alloc(const char *filename, int line, size_t len)
|
||||
if (real_ptr == 0) {
|
||||
acl_msg_error("%s(%d): malloc: insufficient memory",
|
||||
myname, __LINE__);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
mem_slice->nalloc++;
|
||||
@ -317,7 +325,7 @@ static void *tls_mem_alloc(const char *filename, int line, size_t len)
|
||||
mem_slice_gc(mem_slice);
|
||||
}
|
||||
CHECK_OUT_PTR(ptr, real_ptr, mem_slice, len);
|
||||
return (ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void *tls_mem_calloc(const char *filename, int line, size_t nmemb, size_t size)
|
||||
@ -325,7 +333,7 @@ static void *tls_mem_calloc(const char *filename, int line, size_t nmemb, size_t
|
||||
void *ptr = tls_mem_alloc(filename, line, nmemb * size);
|
||||
|
||||
memset(ptr, 0, nmemb * size);
|
||||
return (ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void *tls_mem_realloc(const char *filename, int line, void *ptr, size_t size)
|
||||
@ -334,6 +342,8 @@ static void *tls_mem_realloc(const char *filename, int line, void *ptr, size_t s
|
||||
MBLOCK *old_real_ptr;
|
||||
size_t old_len;
|
||||
|
||||
if (ptr == NULL)
|
||||
return buf;
|
||||
CHECK_IN_PTR2(ptr, old_real_ptr, old_len, filename, line);
|
||||
memcpy(buf, ptr, old_len > size ? size : old_len);
|
||||
if (old_real_ptr->mem_slice->tid != (unsigned long) acl_pthread_self()) {
|
||||
@ -343,7 +353,7 @@ static void *tls_mem_realloc(const char *filename, int line, void *ptr, size_t s
|
||||
} else
|
||||
acl_slice_pool_free(filename, line, old_real_ptr);
|
||||
|
||||
return (buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void *tls_mem_memdup(const char *filename, int line, const void *ptr, size_t len)
|
||||
@ -351,7 +361,7 @@ static void *tls_mem_memdup(const char *filename, int line, const void *ptr, siz
|
||||
void *buf = tls_mem_alloc(filename, line, len);
|
||||
|
||||
memcpy(buf, ptr, len);
|
||||
return (buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char *tls_mem_strdup(const char *filename, int line, const char *str)
|
||||
@ -360,7 +370,7 @@ static char *tls_mem_strdup(const char *filename, int line, const char *str)
|
||||
void *buf = tls_mem_alloc(filename, line, size);
|
||||
|
||||
memcpy(buf, str, size);
|
||||
return ((char*) buf);
|
||||
return (char*) buf;
|
||||
}
|
||||
|
||||
static char *tls_mem_strndup(const char *filename, int line, const char *str, size_t len)
|
||||
@ -371,7 +381,7 @@ static char *tls_mem_strndup(const char *filename, int line, const char *str, si
|
||||
size = size > len ? len : size;
|
||||
buf = (char*) tls_mem_alloc(filename, line, size + 1);
|
||||
memcpy(buf, str, size);
|
||||
return (buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int mem_slice_gc(ACL_MEM_SLICE *mem_slice)
|
||||
@ -393,7 +403,7 @@ static int mem_slice_gc(ACL_MEM_SLICE *mem_slice)
|
||||
/* ʵʱ½øÐÐÀ¬»ø»ØÊÕ? */
|
||||
if ((mem_slice->slice_flag & ACL_SLICE_FLAG_RTGC_OFF) == 0)
|
||||
acl_slice_pool_gc(mem_slice->slice_pool);
|
||||
return (n);
|
||||
return n;
|
||||
}
|
||||
|
||||
int acl_mem_slice_gc(void)
|
||||
@ -401,8 +411,8 @@ int acl_mem_slice_gc(void)
|
||||
ACL_MEM_SLICE *mem_slice = acl_pthread_getspecific(__mem_slice_key);
|
||||
|
||||
if (!mem_slice)
|
||||
return (-1);
|
||||
return (mem_slice_gc(mem_slice));
|
||||
return -1;
|
||||
return mem_slice_gc(mem_slice);
|
||||
}
|
||||
|
||||
void acl_mem_slice_destroy(void)
|
||||
@ -461,7 +471,7 @@ ACL_MEM_SLICE *acl_mem_slice_init(int base, int nslice,
|
||||
|
||||
if (__mem_slice_key != (acl_pthread_key_t) -1) {
|
||||
acl_msg_error("%s(%d): has been init", myname, __LINE__);
|
||||
return (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__mem_base = base;
|
||||
@ -503,7 +513,7 @@ ACL_MEM_SLICE *acl_mem_slice_init(int base, int nslice,
|
||||
tls_mem_memdup,
|
||||
tls_mem_free);
|
||||
acl_msg_info("%s(%d): use ACL_MEM_SLICE, with tls", myname, __LINE__);
|
||||
return (mem_slice);
|
||||
return mem_slice;
|
||||
}
|
||||
|
||||
void acl_mem_slice_set(ACL_MEM_SLICE *mem_slice)
|
||||
|
@ -22,6 +22,42 @@
|
||||
|
||||
#include "ring.h"
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static void *(*__slice_malloc_fn)(const char*, int, size_t)
|
||||
= acl_default_malloc;
|
||||
static void *(*__slice_calloc_fn)(const char*, int, size_t, size_t)
|
||||
= acl_default_calloc;
|
||||
static void *(*__slice_realloc_fn)(const char*, int, void*, size_t)
|
||||
= acl_default_realloc;
|
||||
static void (*__slice_free_fn)(const char*, int, void*)
|
||||
= acl_default_free;
|
||||
|
||||
void acl_slice_mem_hook(void *(*malloc_hook)(const char*, int, size_t),
|
||||
void *(*calloc_hook)(const char*, int, size_t, size_t),
|
||||
void *(*realloc_hook)(const char*, int, void*, size_t),
|
||||
void (*free_hook)(const char*, int, void*))
|
||||
{
|
||||
if (malloc_hook != NULL)
|
||||
__slice_malloc_fn = malloc_hook;
|
||||
if (calloc_hook != NULL)
|
||||
__slice_calloc_fn = calloc_hook;
|
||||
if (realloc_hook != NULL)
|
||||
__slice_realloc_fn = realloc_hook;
|
||||
if (free_hook != NULL)
|
||||
__slice_free_fn = free_hook;
|
||||
}
|
||||
|
||||
void acl_slice_mem_unhook(void)
|
||||
{
|
||||
__slice_malloc_fn = acl_default_malloc;
|
||||
__slice_calloc_fn = acl_default_calloc;
|
||||
__slice_realloc_fn = acl_default_realloc;
|
||||
__slice_free_fn = acl_default_free;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
typedef struct MBUF_SLOTS {
|
||||
void **slots; /* in which free slice can use */
|
||||
int islots; /* current position of free slots slice */
|
||||
@ -52,26 +88,11 @@ struct ACL_SLICE {
|
||||
void (*slice_stat)(ACL_SLICE *slice, ACL_SLICE_STAT *sbuf);
|
||||
};
|
||||
|
||||
/**
|
||||
* MBUF1: 比较节省内存模式,但该方式在垃圾自动回收时比较费时,
|
||||
* 比较适合于分配但不回收的情形
|
||||
*/
|
||||
#define SLICE_OFF_SIZE 4
|
||||
|
||||
typedef struct MBUF1 {
|
||||
RING entry; /* linked by SLICE1->mbuf_head */
|
||||
void *buf; /* memory buf can be sliced */
|
||||
} MBUF1;
|
||||
|
||||
typedef struct SLICE1 {
|
||||
ACL_SLICE slice; /* the bases class */
|
||||
MBUF_SLOTS mslots; /* slice slots holding all slice of the mbuf */
|
||||
RING mbuf_head; /* link all mbuf's entry */
|
||||
} SLICE1;
|
||||
|
||||
/* MBUF2, MBUF3 的基础类型 */
|
||||
/* MBUF1, MBUF2, MBUF3 的基础类型 */
|
||||
|
||||
#define SIGNATURE 0xdead
|
||||
#define SLICE_OFF_SIZE 4
|
||||
|
||||
typedef struct MBUF {
|
||||
ACL_SLICE *slice;
|
||||
@ -79,12 +100,31 @@ typedef struct MBUF {
|
||||
int nused; /* number of using memory slice in payload */
|
||||
} MBUF;
|
||||
|
||||
/**
|
||||
* MBUF1: 比较节省内存模式,但该方式在垃圾自动回收时比较费时,
|
||||
* 比较适合于分配但不回收的情形
|
||||
*/
|
||||
|
||||
#define SLICE1_HEAD_SIZE SLICE_OFF_SIZE
|
||||
|
||||
typedef struct MBUF1 {
|
||||
MBUF mbuf;
|
||||
RING entry; /* linked by SLICE1->mbuf_head */
|
||||
char payload[1]; /* format: {off}{data}{off}{data}... */
|
||||
} MBUF1;
|
||||
|
||||
typedef struct SLICE1 {
|
||||
ACL_SLICE slice; /* the bases class */
|
||||
MBUF_SLOTS mslots; /* slice slots holding all slice of the mbuf */
|
||||
RING mbuf_head; /* link all mbuf's entry */
|
||||
} SLICE1;
|
||||
|
||||
/**
|
||||
* MBUF2: 内存稍微大点,但实时垃圾的自动回收性能比较好, 但如果某
|
||||
* 个 MBUF2 只要有一个结点被引用, 则该内存便不能被释放给系统
|
||||
*/
|
||||
|
||||
#define SLICE2_HEAD_SIZE 8
|
||||
#define SLICE2_HEAD_SIZE (SLICE_OFF_SIZE + 4)
|
||||
|
||||
typedef struct MBUF2 {
|
||||
MBUF mbuf;
|
||||
@ -106,7 +146,7 @@ typedef struct SLICE2 {
|
||||
* 但如果是随机释放则效率下降非常厉害,尤其当结点比较多时
|
||||
*/
|
||||
|
||||
#define SLICE3_HEAD_SIZE 4
|
||||
#define SLICE3_HEAD_SIZE SLICE_OFF_SIZE
|
||||
|
||||
typedef struct MBUF3 {
|
||||
MBUF mbuf;
|
||||
@ -126,37 +166,37 @@ typedef struct SLICE3 {
|
||||
} SLICE3;
|
||||
|
||||
#define MBUF_SLOTS_SPACE(slice, mslots_in, incr, incr_real) do \
|
||||
{ \
|
||||
MBUF_SLOTS *mslots = mslots_in; \
|
||||
if (mslots->slots == NULL) { \
|
||||
incr_real = incr < slice->page_nslots ? slice->page_nslots : incr; \
|
||||
mslots->slots = (void **) acl_default_malloc(__FILE__, __LINE__, \
|
||||
sizeof(void*) * incr_real); \
|
||||
mslots->nslots = incr_real; \
|
||||
mslots->islots = 0; \
|
||||
} else if (mslots->islots + incr >= mslots->nslots) { \
|
||||
incr_real = incr < slice->page_nslots ? slice->page_nslots : incr; \
|
||||
mslots->nslots += incr_real; \
|
||||
mslots->slots = (void **) acl_default_realloc(__FILE__, __LINE__, \
|
||||
mslots->slots, sizeof(void*) * mslots->nslots); \
|
||||
} \
|
||||
{ \
|
||||
MBUF_SLOTS *mslots = mslots_in; \
|
||||
if (mslots->slots == NULL) { \
|
||||
incr_real = incr < slice->page_nslots ? slice->page_nslots : incr; \
|
||||
mslots->slots = (void **) __slice_malloc_fn(__FILE__, __LINE__, \
|
||||
sizeof(void*) * incr_real); \
|
||||
mslots->nslots = incr_real; \
|
||||
mslots->islots = 0; \
|
||||
} else if (mslots->islots + incr >= mslots->nslots) { \
|
||||
incr_real = incr < slice->page_nslots ? slice->page_nslots : incr; \
|
||||
mslots->nslots += incr_real; \
|
||||
mslots->slots = (void **) __slice_realloc_fn(__FILE__, __LINE__, \
|
||||
mslots->slots, sizeof(void*) * mslots->nslots); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SLICE_MBUF_SPACE(slice_in, incr, incr_real, mbuf_type) do \
|
||||
{ \
|
||||
if (slice_in->mbufs == NULL) { \
|
||||
incr_real = incr > 16 ? incr : 16; \
|
||||
slice_in->mbufs = (mbuf_type**) acl_default_malloc(__FILE__, \
|
||||
__LINE__, sizeof(mbuf_type*) * incr_real); \
|
||||
slice_in->capacity = incr_real; \
|
||||
slice_in->imbuf_avail = 0; \
|
||||
} else if (slice_in->slice.nbuf + incr >= slice_in->capacity) { \
|
||||
incr_real = incr > 16 ? incr : 16; \
|
||||
slice_in->capacity += incr_real; \
|
||||
slice_in->mbufs = (mbuf_type**) \
|
||||
acl_default_realloc(__FILE__, __LINE__, slice_in->mbufs, \
|
||||
sizeof(mbuf_type*) * slice_in->capacity); \
|
||||
} \
|
||||
if (slice_in->mbufs == NULL) { \
|
||||
incr_real = incr > 16 ? incr : 16; \
|
||||
slice_in->mbufs = (mbuf_type**) __slice_malloc_fn(__FILE__, \
|
||||
__LINE__, sizeof(mbuf_type*) * incr_real); \
|
||||
slice_in->capacity = incr_real; \
|
||||
slice_in->imbuf_avail = 0; \
|
||||
} else if (slice_in->slice.nbuf + incr >= slice_in->capacity) { \
|
||||
incr_real = incr > 16 ? incr : 16; \
|
||||
slice_in->capacity += incr_real; \
|
||||
slice_in->mbufs = (mbuf_type**) \
|
||||
__slice_realloc_fn(__FILE__, __LINE__, slice_in->mbufs, \
|
||||
sizeof(mbuf_type*) * slice_in->capacity); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* forward declare */
|
||||
@ -179,8 +219,7 @@ static void slice3_mbuf_alloc(ACL_SLICE *slice)
|
||||
int i, incr_real = 0, n;
|
||||
char *ptr;
|
||||
|
||||
mbuf = (MBUF3*) acl_default_malloc(__FILE__, __LINE__,
|
||||
slice->page_size);
|
||||
mbuf = (MBUF3*) __slice_malloc_fn(__FILE__, __LINE__, slice->page_size);
|
||||
mbuf->mbuf.slice = slice;
|
||||
mbuf->mbuf.nused = 0;
|
||||
mbuf->mbuf.signature = SIGNATURE;
|
||||
@ -273,8 +312,8 @@ static void slice3_mbuf_free(ACL_SLICE *slice, MBUF3 *mbuf)
|
||||
if (slice3->imbuf_avail == -1)
|
||||
slice3->imbuf_avail = 0;
|
||||
|
||||
acl_default_free(__FILE__, __LINE__, mbuf->mslots.slots);
|
||||
acl_default_free(__FILE__, __LINE__, mbuf);
|
||||
__slice_free_fn(__FILE__, __LINE__, mbuf->mslots.slots);
|
||||
__slice_free_fn(__FILE__, __LINE__, mbuf);
|
||||
slice->nbuf--;
|
||||
slice->nfree++;
|
||||
slice->length -= slice->page_size + sizeof(void*) * slice->page_nslots;
|
||||
@ -361,8 +400,8 @@ static void slice3_destroy(ACL_SLICE *slice)
|
||||
mbuf = slice3->mbufs[i];
|
||||
slice3_mbuf_free(slice, mbuf);
|
||||
}
|
||||
acl_default_free(__FILE__, __LINE__, slice3->mbufs);
|
||||
acl_default_free(__FILE__, __LINE__, slice3);
|
||||
__slice_free_fn(__FILE__, __LINE__, slice3->mbufs);
|
||||
__slice_free_fn(__FILE__, __LINE__, slice3);
|
||||
}
|
||||
|
||||
static void slice3_stat(ACL_SLICE *slice, ACL_SLICE_STAT *sbuf)
|
||||
@ -396,7 +435,7 @@ static ACL_SLICE *slice3_create(int page_size,
|
||||
SLICE3 *slice;
|
||||
int incr_real;
|
||||
|
||||
slice = (SLICE3 *) acl_default_calloc(__FILE__, __LINE__,
|
||||
slice = (SLICE3 *) __slice_calloc_fn(__FILE__, __LINE__,
|
||||
1, sizeof(SLICE3));
|
||||
|
||||
/* call the base ACL_SLICE's init function */
|
||||
@ -453,7 +492,7 @@ static void slice2_mbuf_alloc(ACL_SLICE *slice)
|
||||
int i, incr_real = 0, n;
|
||||
char *ptr;
|
||||
|
||||
mbuf = (MBUF2*) acl_default_malloc(__FILE__, __LINE__, slice->page_size);
|
||||
mbuf = (MBUF2*) __slice_malloc_fn(__FILE__, __LINE__, slice->page_size);
|
||||
mbuf->mbuf.slice = slice;
|
||||
mbuf->mbuf.nused = 0;
|
||||
mbuf->mbuf.signature = SIGNATURE;
|
||||
@ -496,9 +535,8 @@ static void *slice2_alloc(ACL_SLICE *slice)
|
||||
MBUF2 *mbuf;
|
||||
int off, pos;
|
||||
|
||||
if (slice2->mslots.islots == 0) {
|
||||
if (slice2->mslots.islots == 0)
|
||||
slice2_mbuf_alloc(slice);
|
||||
}
|
||||
|
||||
ptr = (char*) slice2->mslots.slots[--slice2->mslots.islots];
|
||||
slice->used_length += slice->slice_size;
|
||||
@ -629,7 +667,7 @@ static void slice2_mbuf_free(SLICE2 *slice2, MBUF2 *mbuf)
|
||||
}
|
||||
#endif
|
||||
ring_detach(&mbuf->entry);
|
||||
acl_default_free(__FILE__, __LINE__, mbuf);
|
||||
__slice_free_fn(__FILE__, __LINE__, mbuf);
|
||||
slice2->slice.nbuf--;
|
||||
slice2->slice.nfree++;
|
||||
}
|
||||
@ -725,13 +763,13 @@ static void slice2_destroy(ACL_SLICE *slice)
|
||||
for (iter = ring_succ(&slice2->mbuf_head); iter != &slice2->mbuf_head;) {
|
||||
tmp = ring_succ(iter);
|
||||
mbuf = RING_TO_APPL(iter, MBUF2, entry);
|
||||
acl_default_free(__FILE__, __LINE__, mbuf);
|
||||
__slice_free_fn(__FILE__, __LINE__, mbuf);
|
||||
iter = tmp;
|
||||
}
|
||||
|
||||
if (slice2->mslots.slots)
|
||||
acl_default_free(__FILE__, __LINE__, slice2->mslots.slots);
|
||||
acl_default_free(__FILE__, __LINE__, slice2);
|
||||
__slice_free_fn(__FILE__, __LINE__, slice2->mslots.slots);
|
||||
__slice_free_fn(__FILE__, __LINE__, slice2);
|
||||
}
|
||||
|
||||
static void slice2_stat(ACL_SLICE *slice, ACL_SLICE_STAT *sbuf)
|
||||
@ -754,10 +792,8 @@ static void slice2_stat(ACL_SLICE *slice, ACL_SLICE_STAT *sbuf)
|
||||
static ACL_SLICE *slice2_create(int page_size,
|
||||
int slice_length, unsigned int flag)
|
||||
{
|
||||
SLICE2 *slice;
|
||||
|
||||
slice = (SLICE2 *) acl_default_calloc(__FILE__, __LINE__,
|
||||
1, sizeof(SLICE2));
|
||||
SLICE2 *slice = (SLICE2 *) __slice_calloc_fn(
|
||||
__FILE__, __LINE__, 1, sizeof(SLICE2));
|
||||
|
||||
/* call the base ACL_SLICE's init function */
|
||||
|
||||
@ -808,23 +844,26 @@ static ACL_SLICE *slice2_create(int page_size,
|
||||
static void slice1_mbuf_alloc(ACL_SLICE *slice)
|
||||
{
|
||||
SLICE1 *slice1 = (SLICE1*) slice;
|
||||
MBUF1 *mbuf = (MBUF1*) acl_default_malloc(__FILE__, __LINE__,
|
||||
sizeof(MBUF1));
|
||||
MBUF1 *mbuf;
|
||||
int i, incr_real = 0, n;
|
||||
char *ptr;
|
||||
|
||||
mbuf->buf = (void*) acl_default_malloc(__FILE__, __LINE__,
|
||||
slice->page_size);
|
||||
mbuf = (MBUF1*) __slice_malloc_fn(__FILE__, __LINE__, slice->page_size);
|
||||
mbuf->mbuf.slice = slice;
|
||||
mbuf->mbuf.nused = 0;
|
||||
mbuf->mbuf.signature = SIGNATURE;
|
||||
ring_append(&slice1->mbuf_head, &mbuf->entry);
|
||||
ptr = (char*) mbuf->buf;
|
||||
ptr = mbuf->payload;
|
||||
|
||||
slice->nalloc++;
|
||||
n = slice->page_nslots;
|
||||
MBUF_SLOTS_SPACE(slice, &slice1->mslots, n, incr_real);
|
||||
|
||||
for (i = 0; i < slice->page_nslots; i++) {
|
||||
ptr += SLICE1_HEAD_SIZE;
|
||||
*((int*) (ptr - SLICE_OFF_SIZE)) = (int) (ptr - (char*) mbuf);
|
||||
slice1->mslots.slots[slice1->mslots.islots++] = ptr;
|
||||
ptr += slice->slice_size;
|
||||
ptr += slice->slice_length;
|
||||
}
|
||||
for (i = slice->page_nslots; i < incr_real; i++)
|
||||
slice1->mslots.slots[i] = NULL;
|
||||
@ -870,18 +909,16 @@ static void slice1_mbuf_free(ACL_SLICE *slice, void *buf)
|
||||
FOREACH_RING_BACKWARD(iter, &slice1->mbuf_head) {
|
||||
#endif
|
||||
mbuf = RING_TO_APPL(iter, MBUF1, entry);
|
||||
if (buf == mbuf->buf) {
|
||||
if (buf == mbuf->payload) {
|
||||
ring_detach(&mbuf->entry);
|
||||
acl_default_free(__FILE__, __LINE__, mbuf->buf);
|
||||
acl_default_free(__FILE__, __LINE__, mbuf);
|
||||
__slice_free_fn(__FILE__, __LINE__, mbuf);
|
||||
slice->nbuf--;
|
||||
slice->nfree++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
acl_msg_fatal("%s: unknown buf addr: 0x%p",
|
||||
myname, buf ? buf : 0);
|
||||
acl_msg_fatal("%s: unknown buf addr: 0x%p", myname, buf ? buf : 0);
|
||||
}
|
||||
|
||||
static int cmp_fn(const void *p1, const void *p2)
|
||||
@ -949,13 +986,12 @@ static void slice1_destroy(ACL_SLICE *slice)
|
||||
for (iter = ring_succ(&slice1->mbuf_head); iter != &slice1->mbuf_head;) {
|
||||
tmp = ring_succ(iter);
|
||||
mbuf = RING_TO_APPL(iter, MBUF1, entry);
|
||||
acl_default_free(__FILE__, __LINE__, mbuf->buf);
|
||||
acl_default_free(__FILE__, __LINE__, mbuf);
|
||||
__slice_free_fn(__FILE__, __LINE__, mbuf);
|
||||
iter = tmp;
|
||||
}
|
||||
if (slice1->mslots.slots)
|
||||
acl_default_free(__FILE__, __LINE__, slice1->mslots.slots);
|
||||
acl_default_free(__FILE__, __LINE__, slice1);
|
||||
__slice_free_fn(__FILE__, __LINE__, slice1->mslots.slots);
|
||||
__slice_free_fn(__FILE__, __LINE__, slice1);
|
||||
}
|
||||
|
||||
static int slice1_used(ACL_SLICE *slice acl_unused)
|
||||
@ -987,7 +1023,7 @@ static ACL_SLICE *slice1_create(int page_size, int slice_length, unsigned int fl
|
||||
{
|
||||
SLICE1 *slice;
|
||||
|
||||
slice = (SLICE1 *) acl_default_calloc(__FILE__, __LINE__,
|
||||
slice = (SLICE1 *) __slice_calloc_fn(__FILE__, __LINE__,
|
||||
1, sizeof(SLICE1));
|
||||
|
||||
/* call the base ACL_SLICE's init function */
|
||||
@ -1002,9 +1038,10 @@ static ACL_SLICE *slice1_create(int page_size, int slice_length, unsigned int fl
|
||||
|
||||
/* reset the base ACL_SLICE's params */
|
||||
slice->slice.slice_length = slice_length;
|
||||
slice->slice.slice_size = slice_length;
|
||||
slice->slice.slice_size = slice_length + SLICE1_HEAD_SIZE;
|
||||
slice->slice.page_size = page_size;
|
||||
slice->slice.page_nslots = page_size / slice->slice.slice_size;
|
||||
slice->slice.page_nslots = (page_size - sizeof(MBUF2))
|
||||
/ slice->slice.slice_size;
|
||||
slice->slice.gap_size = page_size - slice->slice.page_nslots
|
||||
* slice->slice.slice_size;
|
||||
|
||||
@ -1190,12 +1227,12 @@ ACL_SLICE_POOL *acl_slice_pool_create(int base, int nslice,
|
||||
unsigned int slice_flag)
|
||||
{
|
||||
ACL_SLICE_POOL *asp = (ACL_SLICE_POOL*)
|
||||
acl_default_calloc(__FILE__, __LINE__, 1, sizeof(*asp));
|
||||
__slice_calloc_fn(__FILE__, __LINE__, 1, sizeof(*asp));
|
||||
|
||||
asp->base = base;
|
||||
asp->nslice = nslice;
|
||||
asp->slice_flag = slice_flag;
|
||||
asp->slices = (ACL_SLICE**) acl_default_calloc(__FILE__, __LINE__,
|
||||
asp->slices = (ACL_SLICE**) __slice_calloc_fn(__FILE__, __LINE__,
|
||||
nslice, sizeof(ACL_SLICE*));
|
||||
acl_slice_pool_init(asp);
|
||||
return asp;
|
||||
@ -1209,8 +1246,8 @@ void acl_slice_pool_destroy(ACL_SLICE_POOL *asp)
|
||||
acl_slice_destroy(asp->slices[i]);
|
||||
}
|
||||
|
||||
acl_default_free(__FILE__, __LINE__, asp->slices);
|
||||
acl_default_free(__FILE__, __LINE__, asp);
|
||||
__slice_free_fn(__FILE__, __LINE__, asp->slices);
|
||||
__slice_free_fn(__FILE__, __LINE__, asp);
|
||||
}
|
||||
|
||||
int acl_slice_pool_used(ACL_SLICE_POOL *asp)
|
||||
@ -1254,9 +1291,10 @@ void acl_slice_pool_free(const char *filename, int line, void *buf)
|
||||
char *ptr = (char*) buf;
|
||||
|
||||
ptr -= sizeof(size_t); /* 移至内存头的标志位 */
|
||||
if (*((size_t*) ptr) == 0)
|
||||
acl_default_free(filename, line, ptr);
|
||||
else {
|
||||
if (*((size_t*) ptr) == 0) {
|
||||
ptr -= sizeof(size_t);
|
||||
__slice_free_fn(filename, line, ptr);
|
||||
} else {
|
||||
acl_slice_free(ptr);
|
||||
}
|
||||
}
|
||||
@ -1269,10 +1307,12 @@ void *acl_slice_pool_alloc(const char *filename, int line,
|
||||
|
||||
size += sizeof(size_t); /* 头部留出空间做为标志位 */
|
||||
if (asp == NULL || (int) size >= asp->base * asp->nslice) {
|
||||
ptr = (char*) acl_default_malloc(filename, line, size);
|
||||
size += sizeof(size_t);
|
||||
ptr = (char*) __slice_malloc_fn(filename, line, size);
|
||||
if (ptr) {
|
||||
*((size_t*) ptr) = 0;
|
||||
ptr += sizeof(size_t);
|
||||
*((size_t*) ptr) = size - sizeof(size_t) * 2;
|
||||
*(((size_t*) ptr) + 1) = 0;
|
||||
ptr += sizeof(size_t) * 2;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
@ -1282,7 +1322,7 @@ void *acl_slice_pool_alloc(const char *filename, int line,
|
||||
|
||||
ptr = (char*) acl_slice_alloc(asp->slices[n - 1]);
|
||||
if (ptr) {
|
||||
*((size_t*) ptr) = 1;
|
||||
*((size_t*) ptr) = size - sizeof(size_t);
|
||||
ptr += sizeof(size_t);
|
||||
}
|
||||
return ptr;
|
||||
@ -1304,7 +1344,15 @@ void *acl_slice_pool_realloc(const char *filename, int line,
|
||||
void *buf;
|
||||
|
||||
buf = acl_slice_pool_alloc(filename, line, asp, size);
|
||||
memcpy(buf, ptr, size);
|
||||
if (ptr != NULL) {
|
||||
size_t old_size = *(((size_t*) ptr) - 1);
|
||||
if (old_size == 0) {
|
||||
old_size = *(((size_t*) ptr) - 2);
|
||||
if (old_size == 0)
|
||||
abort();
|
||||
}
|
||||
memcpy(buf, ptr, old_size);
|
||||
}
|
||||
acl_slice_pool_free(filename, line, ptr);
|
||||
return buf;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ CFLAGS = -c -g -W \
|
||||
-Wno-long-long \
|
||||
-Wformat \
|
||||
-DHAS_MYSQL_DLL \
|
||||
-DHAS_SQLITE_DLL \
|
||||
-Winvalid-pch \
|
||||
-DACL_PREPARE_COMPILE
|
||||
#-DHAS_POLARSSL
|
||||
|
@ -1,6 +1,57 @@
|
||||
修改历史列表:
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
459) 2016.12.22
|
||||
459.1) feature: json.cpp 中 json 类及 json_node 类中的 to_string 方法允许复用
|
||||
用户传入的缓冲区
|
||||
|
||||
458) 2016.12.21
|
||||
458.1) compile: gsoner.cpp, http_header.cpp 用 VC x64 编译时有警告
|
||||
458.2) bugfix: master_threads.cpp 中 thread_on_handshake 被调用了两次
|
||||
|
||||
457) 2016.12.19
|
||||
457.1) bugfix: redis_command::run 中当遇到 ASK 命令执行重定向成功,但紧接着执行
|
||||
命令时如果失败,则应该将该连接归还给连接池
|
||||
|
||||
456) 2016.12.15
|
||||
456.1) feature: redis_command/redis_client 增加连接 IP 地址校验检测功能,主要
|
||||
用于调试情况
|
||||
456.2) bugfix: redis_pubsub 类中如果通过 psubcribe 订阅消息时,get_message 则
|
||||
会出错,需要 get_message 使其同时支持 subcribe 及 psubscribe
|
||||
|
||||
455) 2016.12.14
|
||||
455.1) bugfix: redis_client.cpp 中的 run 方法在进行连接重试时,如果请求数据为空,则不
|
||||
应进行重试,而是应直接给上层应用返回失败,由应用层处理,比如对于 redis_pubsub 类中的方法
|
||||
get_message 是没有请求命令的,针对此情况的连接重试,并不会重新获得订阅信息
|
||||
455.2) bugfix: redis_script 类中的参数顺序有误
|
||||
|
||||
454) 2016.12.1
|
||||
454.1) freature: master_proc.cpp/master_threads.cpp/master_aio.cpp 的类中增加
|
||||
虚方法 (proc_)on_listen,以便将监听对象传递给应用
|
||||
|
||||
453) 2016.11.24
|
||||
453.1) bugfix: istream.cpp 中的 gets 函数不应当读超时时设置 eof_ 标志位
|
||||
|
||||
452) 2016.11.18
|
||||
452.1) bugfix: redis_list::bpop 及 redis_pubsub::get_message 的超时时间应
|
||||
不受 socket_stream 里的超时时间影响
|
||||
|
||||
451) 2016.11.8
|
||||
451.1) bugfix: redis_command::run() 中当循环次数超过阀值后应该将连接归还给连接池
|
||||
|
||||
450) 2016.11.7
|
||||
450.1) bugfix: redis_result::argv_to_string 返回值应该 >= 0
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
449) 2016.11.2
|
||||
449.1) bugfix: db_pool.cpp 中的方法 peek_open 禁止动态设置字符集,因为可能会引起
|
||||
线程冲突问题,如果想要设置字符集,必须在 db_mysql/db_sqlite 的构造中指定;对于 db_mysql
|
||||
类,当使用 mysql_conf 类进行初始化 db_mysql 构造时,在 mysql_conf 提前设定字符集
|
||||
|
||||
448) 2016.11.2
|
||||
448.1) bugfix: db_mysql.cpp 中类 db_mysql 的构造函数没有针对 charset_ 初始化
|
||||
有可能会造成崩溃
|
||||
|
||||
447) 2016.10.31
|
||||
447.1) bugfix: redis_string::incrbyfloat 及 redis_hash::hincrbyfloat 中在
|
||||
调用 get_string 后判断是否出错的方式有问题,应该使用长度做为判定条件而不是 bool 值
|
||||
|
@ -26,10 +26,9 @@ public:
|
||||
* 显式地再调用 db_handle::open 过程;
|
||||
* 用完后必须调用 db_pool->put(db_handle*) 将连接归还至数据库连接池,
|
||||
* 由该函数获得的连接句柄不能 delete,否则会造成连接池的内部计数器出错
|
||||
* @param charset {const char*} 打开数据库时采用的字符集
|
||||
* @return {db_handle*} 数据库连接对象,返回空表示出错
|
||||
*/
|
||||
db_handle* peek_open(const char* charset = NULL);
|
||||
db_handle* peek_open();
|
||||
|
||||
/**
|
||||
* 获得当前数据库连接池的最大连接数限制
|
||||
@ -57,11 +56,6 @@ public:
|
||||
{
|
||||
set_idle_ttl(ttl);
|
||||
}
|
||||
|
||||
protected:
|
||||
// 虚函数,子类根据需要设置字符集,当 peek_open 被调用时,此函数
|
||||
// 会先被调用用来设置数据库连接的字符集
|
||||
virtual void set_charset(const char*) {}
|
||||
};
|
||||
|
||||
class ACL_CPP_API db_guard : public connect_guard
|
||||
|
@ -41,9 +41,6 @@ protected:
|
||||
// 基类 connect_pool 纯虚函数:创建数据库连接句柄
|
||||
connect_client* create_connect();
|
||||
|
||||
//@override
|
||||
void set_charset(const char* charset);
|
||||
|
||||
private:
|
||||
mysql_conf* conf_;
|
||||
};
|
||||
|
@ -23,9 +23,6 @@ protected:
|
||||
// 基类 connect_pool 纯虚函数:创建数据库连接句柄
|
||||
connect_client* create_connect();
|
||||
|
||||
//@override
|
||||
void set_charset(const char* charset);
|
||||
|
||||
private:
|
||||
// sqlite 数据文件名
|
||||
char* dbfile_;
|
||||
|
@ -136,7 +136,6 @@
|
||||
|
||||
#include "acl_cpp/master/master_base.hpp"
|
||||
#include "acl_cpp/master/master_threads.hpp"
|
||||
#include "acl_cpp/master/master_threads2.hpp"
|
||||
#include "acl_cpp/master/master_aio.hpp"
|
||||
#include "acl_cpp/master/master_proc.hpp"
|
||||
#include "acl_cpp/master/master_udp.hpp"
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "acl_cpp/stream/aio_listen_stream.hpp"
|
||||
#include "acl_cpp/master/master_base.hpp"
|
||||
|
||||
struct ACL_VSTREAM;
|
||||
|
||||
namespace acl {
|
||||
|
||||
class aio_handle;
|
||||
@ -11,8 +13,7 @@ class aio_socket_stream;
|
||||
/**
|
||||
* acl_master 服务器框架中单线程非阻塞方式的模板类,该类对象只能有一个实例运行
|
||||
*/
|
||||
class ACL_CPP_API master_aio : public master_base,
|
||||
public aio_accept_callback
|
||||
class ACL_CPP_API master_aio : public master_base, public aio_accept_callback
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@ -43,6 +44,7 @@ public:
|
||||
* 在 run_alone 模式下,通知服务器框架关闭引擎,退出程序
|
||||
*/
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
master_aio();
|
||||
virtual ~master_aio();
|
||||
@ -54,6 +56,7 @@ protected:
|
||||
* 远程客户端连接,否则继续接收客户端连接
|
||||
*/
|
||||
virtual bool on_accept(aio_socket_stream* stream) = 0;
|
||||
|
||||
private:
|
||||
/**
|
||||
* 基类 aio_accept_callback 的虚函数实现
|
||||
@ -61,6 +64,7 @@ private:
|
||||
* @return {bool} 返回 true 以通知监听流继续监听
|
||||
*/
|
||||
virtual bool accept_callback(aio_socket_stream* client);
|
||||
|
||||
private:
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
// 当接收到一个客户端连接时回调此函数
|
||||
@ -69,6 +73,9 @@ private:
|
||||
static void service_main(int, void*);
|
||||
#endif
|
||||
|
||||
// 当监听一个服务地址时回调此函数
|
||||
static void service_on_listen(ACL_VSTREAM*);
|
||||
|
||||
// 当进程切换用户身份后调用的回调函数
|
||||
static void service_pre_jail(void*);
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
#include "acl_cpp/acl_cpp_define.hpp"
|
||||
#include "acl_cpp/master/master_conf.hpp"
|
||||
#include <vector>
|
||||
|
||||
struct ACL_EVENT;
|
||||
|
||||
namespace acl
|
||||
{
|
||||
|
||||
class server_socket;
|
||||
class event_timer;
|
||||
|
||||
class ACL_CPP_API master_base
|
||||
@ -62,10 +64,17 @@ public:
|
||||
protected:
|
||||
bool daemon_mode_;
|
||||
bool proc_inited_;
|
||||
std::vector<server_socket*> servers_;
|
||||
|
||||
master_base();
|
||||
virtual ~master_base();
|
||||
|
||||
/**
|
||||
* 在进程启动时,服务进程每成功监听一个本地地址,便调用本函数
|
||||
* @param ss {const server_socket&} 监听对象
|
||||
*/
|
||||
virtual void proc_on_listen(server_socket& ss) { (void) ss; }
|
||||
|
||||
/**
|
||||
* 当进程切换用户身份前调用的回调函数,可以在此函数中做一些
|
||||
* 用户身份为 root 的权限操作
|
||||
|
@ -47,6 +47,9 @@ private:
|
||||
// 当接收到一个客户端连接时回调此函数
|
||||
static void service_main(ACL_VSTREAM *stream, char *service, char **argv);
|
||||
|
||||
// 当监听一个服务地址时回调此函数
|
||||
static void service_on_listen(ACL_VSTREAM*);
|
||||
|
||||
// 当进程切换用户身份后调用的回调函数
|
||||
static void service_pre_jail(char* service, char** argv);
|
||||
|
||||
|
@ -173,6 +173,9 @@ private:
|
||||
// 当接收到一个客户端连接时回调此函数
|
||||
static int service_main(ACL_VSTREAM*, void*);
|
||||
|
||||
// 当监听一个服务地址时回调此函数
|
||||
static void service_on_listen(ACL_VSTREAM*);
|
||||
|
||||
// 当接收到一个客户连接时的回调函数,可以进行一些初始化
|
||||
static int service_on_accept(ACL_VSTREAM*);
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
#include "acl_cpp/master/master_threads.hpp"
|
||||
|
||||
namespace acl {
|
||||
|
||||
typedef class master_threads master_threads2;
|
||||
|
||||
} // namespace acl
|
@ -53,6 +53,14 @@ public:
|
||||
return addr_;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在进行每个命令处理前,是否要求检查 socket 句柄与地址的匹配情况,当
|
||||
* 打开该选项时,将会严格检查匹配情况,但会影响一定性能,因此该设置仅
|
||||
* 用在 DEBUG 时的运行场景
|
||||
* @param on {bool}
|
||||
*/
|
||||
void set_check_addr(bool on);
|
||||
|
||||
/**
|
||||
* 判断该网络连接对象是否已经关闭
|
||||
* check if the connection has been finish
|
||||
@ -96,8 +104,8 @@ public:
|
||||
void set_slice_respond(bool on);
|
||||
|
||||
/**
|
||||
* 用于非分片发送方式,向 redis-server 发送请求数据,同时读取并分析服务端
|
||||
* 返回的响应数据
|
||||
* 用于非分片发送方式,向 redis-server 发送请求数据,同时读取并分析
|
||||
* 服务端返回的响应数据
|
||||
* send request to redis-server, and read/anlyse response from server,
|
||||
* this function will be used for no-slice request mode.
|
||||
* @param pool {dbuf_pool*} 内存池管理器对象
|
||||
@ -107,8 +115,8 @@ public:
|
||||
* @param nchildren {size_t} 响应数据有几个数据对象
|
||||
* the data object number in the server's response data
|
||||
* @return {const redis_result*} 读到的服务器响应对象,返回 NULL 则出错,
|
||||
* 该对象不必手工释放,因为其是在 pool 内存池对象上动态分配的,所以当释放 pool
|
||||
* 时该结果对象一同被释放
|
||||
* 该对象不必手工释放,因为其是在 pool 内存池对象上动态分配的,所以当
|
||||
* 释放 pool 时该结果对象一同被释放
|
||||
* the result object from server's response, NULL will be returned
|
||||
* when some error happens; the result object needn't be freed
|
||||
* manually, which was created in the pool object, and will be freed
|
||||
@ -116,7 +124,7 @@ public:
|
||||
*
|
||||
*/
|
||||
const redis_result* run(dbuf_pool* pool, const string& req,
|
||||
size_t nchildren);
|
||||
size_t nchildren, int* rw_timeout = NULL);
|
||||
|
||||
/**
|
||||
* 用于分片发送请求方式
|
||||
@ -125,7 +133,7 @@ public:
|
||||
* request object
|
||||
*/
|
||||
const redis_result* run(dbuf_pool* pool, const redis_request& req,
|
||||
size_t nchildren);
|
||||
size_t nchildren, int* rw_timeout = NULL);
|
||||
|
||||
protected:
|
||||
// 基类虚函数
|
||||
@ -133,6 +141,7 @@ protected:
|
||||
|
||||
private:
|
||||
socket_stream conn_;
|
||||
bool check_addr_;
|
||||
char* addr_;
|
||||
char* pass_;
|
||||
bool retry_;
|
||||
@ -150,6 +159,7 @@ private:
|
||||
|
||||
void put_data(dbuf_pool* pool, redis_result* rr,
|
||||
const char* data, size_t len);
|
||||
bool check_connection(socket_stream& conn);
|
||||
};
|
||||
|
||||
} // end namespace acl
|
||||
|
@ -53,6 +53,14 @@ public:
|
||||
|
||||
virtual ~redis_command(void);
|
||||
|
||||
/**
|
||||
* 在进行每个命令处理前,是否要求检查 socket 句柄与地址的匹配情况,当
|
||||
* 打开该选项时,将会严格检查匹配情况,但会影响一定性能,因此该设置仅
|
||||
* 用在 DEBUG 时的运行场景
|
||||
* @param on {bool}
|
||||
*/
|
||||
void set_check_addr(bool on);
|
||||
|
||||
/**
|
||||
* 在重复使用一个继承于 redis_command 的子类操作 redis 时,需要在
|
||||
* 下一次调用前调用本方法以释放上次操作的临时对象;
|
||||
@ -306,8 +314,9 @@ public:
|
||||
size_t nchind = 0);
|
||||
|
||||
protected:
|
||||
const redis_result* run(size_t nchild = 0);
|
||||
const redis_result* run(redis_client_cluster* cluster, size_t nchild);
|
||||
const redis_result* run(size_t nchild = 0, int* timeout = NULL);
|
||||
const redis_result* run(redis_client_cluster* cluster,
|
||||
size_t nchild, int* timeout = NULL);
|
||||
|
||||
void build_request(size_t argc, const char* argv[], size_t lens[]);
|
||||
void clear_request();
|
||||
@ -385,14 +394,15 @@ protected:
|
||||
void hash_slot(const char* key, size_t len);
|
||||
|
||||
private:
|
||||
char addr_[32];
|
||||
bool check_addr_;
|
||||
char addr_[32];
|
||||
redis_client* conn_;
|
||||
redis_client_cluster* cluster_;
|
||||
size_t max_conns_;
|
||||
unsigned long long used_;
|
||||
int slot_;
|
||||
int redirect_max_;
|
||||
int redirect_sleep_;
|
||||
int slot_;
|
||||
int redirect_max_;
|
||||
int redirect_sleep_;
|
||||
|
||||
redis_client* peek_conn(redis_client_cluster* cluster, int slot);
|
||||
redis_client* redirect(redis_client_cluster* cluster, const char* addr);
|
||||
|
@ -168,8 +168,9 @@ public:
|
||||
* @param result {acl::string&} 存储查询结果值(内部对该 string 进行内容追加)
|
||||
* store the value result of the given field
|
||||
* @return {bool} 返回值含义:
|
||||
* true -- 成功获得对象的域字段值
|
||||
* get the value associated with field
|
||||
* true -- 操作成功,当result为空时表示 KEY 或字段域不存在
|
||||
* get the value associated with field; if result is empty then
|
||||
* the key or the name field doesn't exist
|
||||
* false -- 域字段不存在或操作失败或该 key 对象非哈希对象
|
||||
* the field not exists, or error happened,
|
||||
* or the key isn't a hash key
|
||||
|
@ -121,10 +121,13 @@ public:
|
||||
* buffer for storing the channel associate with the msg
|
||||
* @param msg {string&} 存放当前获得的消息内容
|
||||
* store the message posted to the channel
|
||||
* @param message_type {string*} will store messsage or pmessage
|
||||
* @param pattern {string*} will store pattern set by psubscribe
|
||||
* @return {bool} 是否成功,如果返回 false 则表示出错
|
||||
* true on success, false on error
|
||||
*/
|
||||
bool get_message(string& channel, string& msg);
|
||||
bool get_message(string& channel, string& msg,
|
||||
string* message_type = NULL, string* pattern = NULL);
|
||||
|
||||
/**
|
||||
* 列出当前的活跃频道:活跃频道指的是那些至少有一个订阅者的频道, 订阅模式的
|
||||
|
@ -152,8 +152,8 @@ public:
|
||||
* compose a continus data for the slicing chunk data internal
|
||||
* @param buf {string&} 存储结果数据,内部会先调用 buf.clear()
|
||||
* store the result
|
||||
* @return {int} 数据的总长度,返回值 -1 表示内部数组为空
|
||||
* return the total length of data, -1 if data array has no elements
|
||||
* @return {int} 数据的总长度,返回值 0 表示内部数组为空
|
||||
* return the total length of data, 0 if data array has no elements
|
||||
*/
|
||||
int argv_to_string(string& buf) const;
|
||||
int argv_to_string(char* buf, size_t size) const;
|
||||
|
@ -130,8 +130,10 @@ public:
|
||||
* get the value of a key
|
||||
* @param key {const char*} 字符串对象的 key
|
||||
* the key of a string
|
||||
* @param buf {string&} 操作成功后存储字符串对象的值
|
||||
* store the value of a key after GET executed correctly
|
||||
* @param buf {string&} 操作成功后存储字符串对象的值,如果返回 true 且
|
||||
* 该缓冲区为空则表示对应 key 不存在
|
||||
* store the value of a key after GET executed correctly, key not
|
||||
* exist if the buf is empty when return true
|
||||
* @return {bool} 操作是否成功,返回 false 表示出错或 key 非字符串对象
|
||||
* if the GET was executed correctly, false if error happened or
|
||||
* is is not a string of the key
|
||||
|
@ -140,9 +140,10 @@ public:
|
||||
|
||||
/**
|
||||
* 将当前 json 节点转换成 json 字符串(包含本 json 节点及其子节点)
|
||||
* @param out {string*} 非空时,则使用此缓冲区,否则使用内部缓冲区
|
||||
* @return {const char*}
|
||||
*/
|
||||
const string& to_string(void);
|
||||
const string& to_string(string* out = NULL) const;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -746,9 +747,10 @@ public:
|
||||
|
||||
/**
|
||||
* 将 json 对象树转换成 json 字符串
|
||||
* @param out {string*} 非空时,则使用此缓冲区,否则使用内部缓冲区
|
||||
* @return {const string&}
|
||||
*/
|
||||
const string& to_string(void);
|
||||
const string& to_string(string* out = NULL) const;
|
||||
|
||||
// pipe_stream 虚函数重载
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
#include "acl_cpp/acl_cpp_define.hpp"
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <WinSock2.h>
|
||||
#endif
|
||||
|
||||
namespace acl {
|
||||
|
||||
@ -12,11 +15,30 @@ class ACL_CPP_API server_socket
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* 构造函数
|
||||
* 构造函数,调用本构造函数后需调用类方法 open 来监听指定服务地址
|
||||
* @param backlog {int} 监听套接口队列长度
|
||||
* @param block {bool} 是阻塞模式还是非阻塞模式
|
||||
*/
|
||||
server_socket(int backlog = 128, bool block = true);
|
||||
|
||||
/**
|
||||
* 构造函数,调用本构造函数后禁止再调用 open 方法
|
||||
* @param sstream {ACL_VSTREAM*} 外部创建的监听流对象,本类仅使用
|
||||
* 但并不释放,由应用自行关闭该监听对象
|
||||
*/
|
||||
server_socket(ACL_VSTREAM* sstream);
|
||||
|
||||
/**
|
||||
* 构造函数,调用本构造函数后禁止再调用 open 方法
|
||||
* @param fd {ACL_SOCKET} 外部创建的监听句柄,本类仅使用但并不释放,
|
||||
* 由应用自行关闭该监听句柄
|
||||
*/
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
server_socket(SOCKET fd);
|
||||
#else
|
||||
server_socket(int fd);
|
||||
#endif
|
||||
|
||||
~server_socket();
|
||||
|
||||
/**
|
||||
@ -80,8 +102,10 @@ private:
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
SOCKET fd_;
|
||||
SOCKET fd_local_;
|
||||
#else
|
||||
int fd_;
|
||||
int fd_local_;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\lib_protocol\include;..\lib_acl\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;USE_WIN_ICONV;HAS_ZLIB_DLL;HAS_MYSQL_DLL"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;USE_WIN_ICONV;HAS_ZLIB_DLL;HAS_MYSQL_DLL;HAS_SQLITE_DLL"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
@ -69,7 +69,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=".\include;..\lib_protocol\include;..\lib_acl\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_WIN_ICONV;HAS_ZLIB_DLL;HAS_MYSQL_DLL"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_WIN_ICONV;HAS_ZLIB_DLL;HAS_MYSQL_DLL;HAS_SQLITE_DLL"
|
||||
RuntimeLibrary="0"
|
||||
UsePrecompiledHeader="3"
|
||||
PrecompiledHeaderThrough="acl_stdafx.hpp"
|
||||
@ -589,9 +589,6 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<File
|
||||
RelativePath=".\src\master\master_threads.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\master\master_threads2.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\master\master_trigger.cpp">
|
||||
</File>
|
||||
@ -1166,9 +1163,6 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\master\master_threads.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\master\master_threads2.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\master\master_trigger.hpp">
|
||||
</File>
|
||||
|
@ -42,7 +42,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
@ -111,7 +111,7 @@
|
||||
EnableIntrinsicFunctions="true"
|
||||
WholeProgramOptimization="false"
|
||||
AdditionalIncludeDirectories=".\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="2"
|
||||
@ -176,7 +176,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
@ -255,7 +255,7 @@
|
||||
EnableIntrinsicFunctions="true"
|
||||
WholeProgramOptimization="false"
|
||||
AdditionalIncludeDirectories=".\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_WIN_ICONV;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;HAS_MYSQL_DLL;HAS_ZLIB_DLL"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_WIN_ICONV;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="2"
|
||||
@ -613,10 +613,6 @@
|
||||
RelativePath=".\src\master\master_threads.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\master\master_threads2.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\master\master_trigger.cpp"
|
||||
>
|
||||
@ -1443,10 +1439,6 @@
|
||||
RelativePath=".\include\acl_cpp\master\master_threads.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\master\master_threads2.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\acl_cpp\master\master_trigger.hpp"
|
||||
>
|
||||
|
@ -89,7 +89,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -113,7 +113,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y</Command>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>acl_stdafx.hpp</PrecompiledHeaderFile>
|
||||
@ -134,7 +134,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y</Command>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@ -167,7 +167,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;.\src;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
@ -260,7 +260,6 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClCompile Include="src\master\master_conf.cpp" />
|
||||
<ClCompile Include="src\master\master_proc.cpp" />
|
||||
<ClCompile Include="src\master\master_threads.cpp" />
|
||||
<ClCompile Include="src\master\master_threads2.cpp" />
|
||||
<ClCompile Include="src\master\master_trigger.cpp" />
|
||||
<ClCompile Include="src\master\master_udp.cpp" />
|
||||
<ClCompile Include="src\memcache\memcache.cpp" />
|
||||
@ -436,7 +435,6 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClInclude Include="include\acl_cpp\master\master_conf.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_proc.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads2.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_trigger.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_udp.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\memcache\memcache.hpp" />
|
||||
@ -566,4 +564,4 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -64,9 +64,6 @@
|
||||
<ClCompile Include="src\master\master_threads.cpp">
|
||||
<Filter>src\master</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\master\master_threads2.cpp">
|
||||
<Filter>src\master</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\master\master_udp.cpp">
|
||||
<Filter>src\master</Filter>
|
||||
</ClCompile>
|
||||
@ -675,9 +672,6 @@
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads.hpp">
|
||||
<Filter>include\master</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads2.hpp">
|
||||
<Filter>include\master</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\master\master_udp.hpp">
|
||||
<Filter>include\master</Filter>
|
||||
</ClInclude>
|
||||
@ -1195,4 +1189,4 @@
|
||||
<UniqueIdentifier>{b11cf93f-d6d7-4940-9406-ef655ebde884}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -174,7 +174,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -199,7 +199,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y</Command>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
@ -222,7 +222,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y</Command>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>acl_stdafx.hpp</PrecompiledHeaderFile>
|
||||
@ -242,7 +242,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y</Command>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>acl_stdafx.hpp</PrecompiledHeaderFile>
|
||||
@ -263,7 +263,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y</Command>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@ -296,7 +296,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
@ -328,7 +328,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;.\src;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
@ -358,7 +358,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;.\src;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
@ -454,7 +454,6 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClCompile Include="src\master\master_conf.cpp" />
|
||||
<ClCompile Include="src\master\master_proc.cpp" />
|
||||
<ClCompile Include="src\master\master_threads.cpp" />
|
||||
<ClCompile Include="src\master\master_threads2.cpp" />
|
||||
<ClCompile Include="src\master\master_trigger.cpp" />
|
||||
<ClCompile Include="src\master\master_udp.cpp" />
|
||||
<ClCompile Include="src\memcache\memcache.cpp" />
|
||||
@ -630,7 +629,6 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClInclude Include="include\acl_cpp\master\master_conf.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_proc.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads2.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_trigger.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_udp.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\memcache\memcache.hpp" />
|
||||
|
@ -64,9 +64,6 @@
|
||||
<ClCompile Include="src\master\master_threads.cpp">
|
||||
<Filter>Source Files\master</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\master\master_threads2.cpp">
|
||||
<Filter>Source Files\master</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ipc\ipc_service.cpp">
|
||||
<Filter>Source Files\ipc</Filter>
|
||||
</ClCompile>
|
||||
@ -672,9 +669,6 @@
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads.hpp">
|
||||
<Filter>Header Files\master</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads2.hpp">
|
||||
<Filter>Header Files\master</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\mime\rfc2047.hpp">
|
||||
<Filter>Header Files\mime</Filter>
|
||||
</ClInclude>
|
||||
|
@ -174,7 +174,7 @@
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;.\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -199,7 +199,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y</Command>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
@ -222,7 +222,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y</Command>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>acl_stdafx.hpp</PrecompiledHeaderFile>
|
||||
@ -242,7 +242,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y</Command>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>acl_stdafx.hpp</PrecompiledHeaderFile>
|
||||
@ -263,7 +263,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y</Command>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
@ -296,7 +296,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
@ -328,7 +328,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;.\src;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
@ -358,7 +358,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>.\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\zlib;..\include\mysql;.\src;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
@ -454,7 +454,6 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClCompile Include="src\master\master_conf.cpp" />
|
||||
<ClCompile Include="src\master\master_proc.cpp" />
|
||||
<ClCompile Include="src\master\master_threads.cpp" />
|
||||
<ClCompile Include="src\master\master_threads2.cpp" />
|
||||
<ClCompile Include="src\master\master_trigger.cpp" />
|
||||
<ClCompile Include="src\master\master_udp.cpp" />
|
||||
<ClCompile Include="src\memcache\memcache.cpp" />
|
||||
@ -630,7 +629,6 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<ClInclude Include="include\acl_cpp\master\master_conf.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_proc.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads2.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_trigger.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\master\master_udp.hpp" />
|
||||
<ClInclude Include="include\acl_cpp\memcache\memcache.hpp" />
|
||||
@ -763,4 +761,4 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -64,9 +64,6 @@
|
||||
<ClCompile Include="src\master\master_threads.cpp">
|
||||
<Filter>Source Files\master</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\master\master_threads2.cpp">
|
||||
<Filter>Source Files\master</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ipc\ipc_service.cpp">
|
||||
<Filter>Source Files\ipc</Filter>
|
||||
</ClCompile>
|
||||
@ -672,9 +669,6 @@
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads.hpp">
|
||||
<Filter>Header Files\master</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\master\master_threads2.hpp">
|
||||
<Filter>Header Files\master</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\acl_cpp\mime\rfc2047.hpp">
|
||||
<Filter>Header Files\mime</Filter>
|
||||
</ClInclude>
|
||||
@ -1203,4 +1197,4 @@
|
||||
<Filter>doc</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "acl_cpp/master/master_threads2.hpp"
|
||||
#include "acl_cpp/master/master_threads.hpp"
|
||||
#include "acl_cpp/master/master_conf.hpp"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -21,7 +21,7 @@ extern acl::master_int64_tbl var_conf_int64_tab[];
|
||||
|
||||
//class acl::socket_stream;
|
||||
|
||||
class master_service : public acl::master_threads2
|
||||
class master_service : public acl::master_threads
|
||||
{
|
||||
public:
|
||||
master_service();
|
||||
|
@ -80,9 +80,8 @@ endif
|
||||
|
||||
CFLAGS += $(INC_COMPILE)
|
||||
|
||||
INC_COMPILE = -I../../include -I../../../lib_acl/include -I../../../include/mysql
|
||||
LIB_COMPILE = -L../../lib -l_acl_cpp -L../../../lib_acl/lib -l_acl \
|
||||
-L../../../lib/$(LINUX) -lmysqlclient_r -ldl
|
||||
INC_COMPILE = -I../../include -I../../../lib_acl/include
|
||||
LIB_COMPILE = -L../../lib -l_acl_cpp -L../../../lib_acl/lib -l_acl -ldl
|
||||
|
||||
###########################################################
|
||||
OUT_PATH = .
|
||||
|
@ -3,8 +3,7 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "lib_acl.h"
|
||||
#include "acl_cpp/stdlib/string.hpp"
|
||||
#include "acl_cpp/db/db_mysql.hpp"
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
|
||||
const char* CREATE_TBL =
|
||||
"create table group_tbl\r\n"
|
||||
@ -173,6 +172,38 @@ static bool tbl_delete(acl::db_handle& db, int n)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// WIN32 下需要调用此函数进行有关 SOCKET 的初始化
|
||||
acl::acl_cpp_init();
|
||||
|
||||
// 允许将错误日志输出至屏幕
|
||||
acl::log::stdout_open(true);
|
||||
|
||||
acl::string line;
|
||||
acl::stdin_stream in;
|
||||
acl::stdout_stream out;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
const char* libname = "libmysql.dll";
|
||||
#else
|
||||
const char* libname = "libmysqlclient_r.so";
|
||||
#endif
|
||||
|
||||
acl::string path;
|
||||
|
||||
// 因为采用动态加载的方式,所以需要应用给出 mysql 客户端库所在的路径
|
||||
out.format("Enter %s load path: ", libname);
|
||||
if (in.gets(line) && !line.empty())
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
path.format("%s\\%s", line.c_str(), libname);
|
||||
#else
|
||||
path.format("%s/%s", line.c_str(), libname);
|
||||
#endif
|
||||
else
|
||||
path = libname;
|
||||
|
||||
out.format("%s path: %s\r\n", libname, path.c_str());
|
||||
// 设置动态库加载的全路径
|
||||
acl::db_handle::set_loadpath(path);
|
||||
|
||||
#ifdef WIN32
|
||||
const char* dbaddr = "192.168.1.251:3306";
|
||||
|
@ -71,8 +71,7 @@ endif
|
||||
CFLAGS += $(INC_COMPILE)
|
||||
|
||||
INC_COMPILE = -I../../include -I../../../lib_acl/include
|
||||
LIB_COMPILE = -L../../lib -l_acl_cpp -L../../../lib_acl/lib -l_acl \
|
||||
-Wl,-rpath,./ -L. -lmysqlclient_r -ldl
|
||||
LIB_COMPILE = -L../../lib -l_acl_cpp -L../../../lib_acl/lib -l_acl -ldl
|
||||
|
||||
###########################################################
|
||||
OUT_PATH = .
|
||||
|
@ -38,16 +38,46 @@ static int tbl_select(acl::db_handle& db)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// WIN32 下需要调用此函数进行有关 SOCKET 的初始化
|
||||
acl::acl_cpp_init();
|
||||
|
||||
// 允许将错误日志输出至屏幕
|
||||
acl::log::stdout_open(true);
|
||||
|
||||
acl::string line;
|
||||
acl::stdin_stream in;
|
||||
acl::stdout_stream out;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
const char* libname = "libmysql.dll";
|
||||
#else
|
||||
const char* libname = "libmysqlclient_r.so";
|
||||
#endif
|
||||
|
||||
acl::string path;
|
||||
|
||||
// 因为采用动态加载的方式,所以需要应用给出 mysql 客户端库所在的路径
|
||||
out.format("Enter %s load path: ", libname);
|
||||
if (in.gets(line) && !line.empty())
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
path.format("%s\\%s", line.c_str(), libname);
|
||||
#else
|
||||
path.format("%s/%s", line.c_str(), libname);
|
||||
#endif
|
||||
else
|
||||
path = libname;
|
||||
|
||||
out.format("%s path: %s\r\n", libname, path.c_str());
|
||||
// 设置动态库加载的全路径
|
||||
acl::db_handle::set_loadpath(path);
|
||||
|
||||
const char* dbaddr = "127.0.0.1:16811";
|
||||
const char* dbname = "inc365_antispam_db";
|
||||
const char* dbuser = "root", *dbpass = "";
|
||||
acl::db_mysql db(dbaddr, dbname, dbuser, dbpass);
|
||||
|
||||
// 允许将错误日志输出至屏幕
|
||||
acl_msg_stdout_enable(1);
|
||||
|
||||
if (db.open(NULL) == false)
|
||||
if (db.dbopen(NULL) == false)
|
||||
{
|
||||
printf("open db(%s) error\r\n", dbname);
|
||||
getchar();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
static bool __check_addr = false;
|
||||
static acl::string __keypre("test_key");
|
||||
|
||||
static bool test_set(acl::redis_string& redis, int n)
|
||||
@ -13,6 +14,7 @@ static bool test_set(acl::redis_string& redis, int n)
|
||||
value.format("value_%s", key.c_str());
|
||||
|
||||
redis.clear();
|
||||
redis.set_check_addr(__check_addr);
|
||||
if (redis.set(key.c_str(), value.c_str()) == false)
|
||||
{
|
||||
printf("set key: %s error: %s\r\n",
|
||||
@ -648,11 +650,12 @@ static void usage(const char* procname)
|
||||
{
|
||||
printf("usage: %s -h[help]\r\n"
|
||||
"-s redis_addr[127.0.0.1:6379]\r\n"
|
||||
"-n count\r\n"
|
||||
"-n count[default: 1]\r\n"
|
||||
"-C connect_timeout[default: 10]\r\n"
|
||||
"-I rw_timeout[default: 10]\r\n"
|
||||
"-t object timeout[default: 10]\r\n"
|
||||
"-c [use cluster mode]\r\n"
|
||||
"-M [if check connection addr first]\r\n"
|
||||
"-a cmd[set|setex|setnx|append|get|getset|strlen|mset|mget|msetnx|setrange|getrange|setbit|getbit|bitcount|bitop_and|bitop_or|bitop_xor|incr|incrby|incrbyfloat|decr|decrby]\r\n",
|
||||
procname);
|
||||
}
|
||||
@ -663,7 +666,7 @@ int main(int argc, char* argv[])
|
||||
acl::string addr("127.0.0.1:6379"), cmd;
|
||||
bool cluster_mode = false;
|
||||
|
||||
while ((ch = getopt(argc, argv, "hs:n:C:I:a:t:c")) > 0)
|
||||
while ((ch = getopt(argc, argv, "hs:n:C:I:a:t:cM")) > 0)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
@ -691,6 +694,9 @@ int main(int argc, char* argv[])
|
||||
case 'c':
|
||||
cluster_mode = true;
|
||||
break;
|
||||
case 'M':
|
||||
__check_addr = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
include ../Makefile.in
|
||||
PROG = sqlite
|
||||
EXTLIBS += -lsqlite3 -lmysqlclient
|
||||
ifneq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
|
||||
EXTLIBS += -ldl
|
||||
endif
|
||||
#EXTLIBS += -lsqlite3 -lmysqlclient
|
||||
|
@ -2,9 +2,7 @@
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "acl_cpp/stdlib/string.hpp"
|
||||
#include "acl_cpp/stdlib/util.hpp"
|
||||
#include "acl_cpp/db/db_sqlite.hpp"
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
|
||||
const char* CREATE_TBL =
|
||||
"create table group_tbl\r\n"
|
||||
@ -155,7 +153,37 @@ static bool tbl_delete(acl::db_handle& db, int n)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
acl::string dbfile("²âÊÔ.db");
|
||||
acl::acl_cpp_init();
|
||||
|
||||
acl::stdin_stream in;
|
||||
acl::stdout_stream out;
|
||||
acl::string line;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
const char* libname = "sqlite3.dll";
|
||||
#else
|
||||
const char* libname = "libsqlite3.so";
|
||||
#endif
|
||||
|
||||
acl::string path;
|
||||
out.format("Enter %s load path: ", libname);
|
||||
if (in.gets(line) && !line.empty())
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
path.format("%s\\%s", line.c_str(), libname);
|
||||
#else
|
||||
path.format("%s/%s", line.c_str(), libname);
|
||||
#endif
|
||||
else
|
||||
path = libname;
|
||||
|
||||
out.format("%s path: %s\r\n", libname, path.c_str());
|
||||
// 设置动态库加载的全路径
|
||||
acl::db_handle::set_loadpath(path);
|
||||
|
||||
acl::string dbfile("test.db");
|
||||
|
||||
// db_sqlite 类对象的声明需在 set_loadpath 之后,因为在 db_sqlite 的
|
||||
// 构造函数中需要运行加载 libsqlite3.so
|
||||
acl::db_sqlite db(dbfile);
|
||||
int max = 100;
|
||||
|
||||
|
@ -13,11 +13,8 @@ db_pool::db_pool(const char* dbaddr, size_t count, size_t idx /* = 0 */)
|
||||
{
|
||||
}
|
||||
|
||||
db_handle* db_pool::peek_open(const char* charset /* = NULL */)
|
||||
db_handle* db_pool::peek_open(void)
|
||||
{
|
||||
if (charset)
|
||||
set_charset(charset);
|
||||
|
||||
db_handle* conn = (db_handle*) peek();
|
||||
if (conn == NULL)
|
||||
logger_error("peek NULL");
|
||||
|
@ -220,7 +220,7 @@ db_sqlite::db_sqlite(const char* dbfile, const char* charset /* ="utf-8" */)
|
||||
conv_ = NULL;
|
||||
|
||||
acl_assert(dbfile && *dbfile);
|
||||
#if defined(ACL_WINDOWS) || defined(USE_DYNAMIC)
|
||||
#if defined(ACL_CPP_DLL) || defined(HAS_SQLITE_DLL)
|
||||
acl_pthread_once(&__sqlite_once, __sqlite_dll_load);
|
||||
#endif
|
||||
}
|
||||
|
@ -51,10 +51,4 @@ connect_client* mysql_pool::create_connect()
|
||||
return NEW db_mysql(*conf_);
|
||||
}
|
||||
|
||||
void mysql_pool::set_charset(const char* charset)
|
||||
{
|
||||
if (charset)
|
||||
conf_->set_charset(charset);
|
||||
}
|
||||
|
||||
} // namespace acl
|
||||
|
@ -33,14 +33,4 @@ connect_client* sqlite_pool::create_connect()
|
||||
return NEW db_sqlite(dbfile_, charset_);
|
||||
}
|
||||
|
||||
void sqlite_pool::set_charset(const char* charset)
|
||||
{
|
||||
if (charset == NULL || *charset == 0)
|
||||
return;
|
||||
|
||||
if (charset_)
|
||||
acl_myfree(charset_);
|
||||
charset_ = acl_mystrdup(charset);
|
||||
}
|
||||
|
||||
} // namespace acl
|
||||
|
@ -873,7 +873,7 @@ void http_header::append_accept_key(const char* sec_key, string& out) const
|
||||
tmp += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||
|
||||
sha1 sha;
|
||||
sha.input(tmp.c_str(), tmp.size());
|
||||
sha.input(tmp.c_str(), (unsigned int) tmp.size());
|
||||
unsigned char digest[20];
|
||||
sha.result((unsigned *) digest);
|
||||
|
||||
|
@ -302,7 +302,9 @@ bool websocket::read_frame_head(void)
|
||||
|
||||
if (client_.read(buf, 2) == -1)
|
||||
{
|
||||
logger_error("read first two char error: %s", last_serror());
|
||||
if (last_error() != ACL_ETIMEDOUT)
|
||||
logger_error("read first two char error: %d, %s",
|
||||
last_error(), last_serror());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -320,7 +322,9 @@ bool websocket::read_frame_head(void)
|
||||
// payload_len == 126 | 127
|
||||
else if ((ret = client_.read(buf, payload_len == 126 ? 2 : 8)) == -1)
|
||||
{
|
||||
logger_error("read ext_payload_len error %s", last_serror());
|
||||
if (last_error() != ACL_ETIMEDOUT)
|
||||
logger_error("read ext_payload_len error: %d, %s",
|
||||
last_error(), last_serror());
|
||||
return false;
|
||||
}
|
||||
else if (ret == 2)
|
||||
@ -340,7 +344,9 @@ bool websocket::read_frame_head(void)
|
||||
|
||||
if (client_.read(&header_.masking_key, sizeof(unsigned int)) == -1)
|
||||
{
|
||||
logger_error("read masking_key error %s", last_serror());
|
||||
if (last_error() != ACL_ETIMEDOUT)
|
||||
logger_error("read masking_key error: %d, %s",
|
||||
last_error(), last_serror());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -358,7 +364,9 @@ int websocket::read_frame_data(char* buf, size_t size)
|
||||
int ret = client_.read(buf, size, false);
|
||||
if (ret == -1)
|
||||
{
|
||||
logger_error("read frame data error %s", last_serror());
|
||||
if (last_error() != ACL_ETIMEDOUT)
|
||||
logger_error("read frame data error: %d, %s",
|
||||
last_error(), last_serror());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#ifndef ACL_PREPARE_COMPILE
|
||||
#include "acl_cpp/stdlib/log.hpp"
|
||||
#include "acl_cpp/stdlib/util.hpp"
|
||||
#include "acl_cpp/stream/server_socket.hpp"
|
||||
#include "acl_cpp/stream/aio_handle.hpp"
|
||||
#include "acl_cpp/stream/aio_socket_stream.hpp"
|
||||
#include "acl_cpp/master/master_aio.hpp"
|
||||
@ -45,6 +46,7 @@ void master_aio::run_daemon(int argc, char** argv)
|
||||
|
||||
// 调用 acl 服务器框架的单线程非阻塞模板
|
||||
acl_aio_server2_main(argc, argv, service_main,
|
||||
ACL_MASTER_SERVER_ON_LISTEN, service_on_listen,
|
||||
ACL_MASTER_SERVER_PRE_INIT, service_pre_jail,
|
||||
ACL_MASTER_SERVER_POST_INIT, service_init,
|
||||
ACL_MASTER_SERVER_EXIT, service_exit,
|
||||
@ -103,6 +105,8 @@ bool master_aio::run_alone(const char* addrs, const char* path /* = NULL */,
|
||||
acl_argv_free(tokens);
|
||||
return (false);
|
||||
}
|
||||
|
||||
service_on_listen(sstream->get_vstream());
|
||||
sstream->add_accept_callback(this);
|
||||
}
|
||||
acl_argv_free(tokens);
|
||||
@ -212,4 +216,12 @@ void master_aio::service_main(ACL_SOCKET fd, void*)
|
||||
__ma->on_accept(stream);
|
||||
}
|
||||
|
||||
void master_aio::service_on_listen(ACL_VSTREAM *sstream)
|
||||
{
|
||||
acl_assert(__ma);
|
||||
server_socket* ss = new server_socket(sstream);
|
||||
__ma->servers_.push_back(ss);
|
||||
__ma->proc_on_listen(*ss);
|
||||
}
|
||||
|
||||
} // namespace acl
|
||||
|
@ -2,6 +2,7 @@
|
||||
#ifndef ACL_PREPARE_COMPILE
|
||||
#include "acl_cpp/stdlib/log.hpp"
|
||||
#include "acl_cpp/event/event_timer.hpp"
|
||||
#include "acl_cpp/stream/server_socket.hpp"
|
||||
#include "acl_cpp/master/master_base.hpp"
|
||||
#endif
|
||||
|
||||
@ -17,7 +18,11 @@ master_base::master_base()
|
||||
|
||||
master_base::~master_base()
|
||||
{
|
||||
|
||||
for (std::vector<server_socket*>::iterator it = servers_.begin();
|
||||
it != servers_.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
void master_base::set_cfg_bool(master_bool_tbl* table)
|
||||
|
@ -2,6 +2,7 @@
|
||||
#ifndef ACL_PREPARE_COMPILE
|
||||
#include "acl_cpp/stdlib/log.hpp"
|
||||
#include "acl_cpp/stdlib/util.hpp"
|
||||
#include "acl_cpp/stream/server_socket.hpp"
|
||||
#include "acl_cpp/stream/socket_stream.hpp"
|
||||
#include "acl_cpp/master/master_proc.hpp"
|
||||
#endif
|
||||
@ -34,6 +35,7 @@ void master_proc::run_daemon(int argc, char** argv)
|
||||
daemon_mode_ = true;
|
||||
|
||||
acl_single_server_main(argc, argv, service_main,
|
||||
ACL_MASTER_SERVER_ON_LISTEN, service_on_listen,
|
||||
ACL_MASTER_SERVER_PRE_INIT, service_pre_jail,
|
||||
ACL_MASTER_SERVER_POST_INIT, service_init,
|
||||
ACL_MASTER_SERVER_EXIT, service_exit,
|
||||
@ -109,6 +111,8 @@ bool master_proc::run_alone(const char* addrs, const char* path /* = NULL */,
|
||||
acl_argv_free(tokens);
|
||||
return false;
|
||||
}
|
||||
|
||||
service_on_listen(sstream);
|
||||
acl_event_enable_listen(eventp, sstream, 0,
|
||||
listen_callback, sstream);
|
||||
sstreams.push_back(sstream);
|
||||
@ -177,4 +181,13 @@ void master_proc::service_exit(char*, char**)
|
||||
__mp->proc_on_exit();
|
||||
}
|
||||
|
||||
void master_proc::service_on_listen(ACL_VSTREAM* sstream)
|
||||
{
|
||||
acl_assert(__mp != NULL);
|
||||
server_socket* ss = new server_socket(sstream);
|
||||
__mp->servers_.push_back(ss);
|
||||
server_socket m(sstream);
|
||||
__mp->proc_on_listen(*ss);
|
||||
}
|
||||
|
||||
} // namespace acl
|
||||
|
@ -2,6 +2,7 @@
|
||||
#ifndef ACL_PREPARE_COMPILE
|
||||
#include "acl_cpp/stdlib/log.hpp"
|
||||
#include "acl_cpp/stream/socket_stream.hpp"
|
||||
#include "acl_cpp/stream/server_socket.hpp"
|
||||
#include "acl_cpp/master/master_threads.hpp"
|
||||
#endif
|
||||
|
||||
@ -35,6 +36,7 @@ void master_threads::run_daemon(int argc, char** argv)
|
||||
|
||||
// 调用 acl 服务器框架的多线程模板
|
||||
acl_threads_server_main(argc, argv, service_main, NULL,
|
||||
ACL_MASTER_SERVER_ON_LISTEN, service_on_listen,
|
||||
ACL_MASTER_SERVER_ON_ACCEPT, service_on_accept,
|
||||
ACL_MASTER_SERVER_ON_HANDSHAKE, service_on_handshake,
|
||||
ACL_MASTER_SERVER_ON_TIMEOUT, service_on_timeout,
|
||||
@ -79,6 +81,7 @@ bool master_threads::run_alone(const char* addrs, const char* path /* = NULL */,
|
||||
|
||||
// 调用 acl 服务器框架的多线程模板
|
||||
acl_threads_server_main(argc, (char**) argv, service_main, NULL,
|
||||
ACL_MASTER_SERVER_ON_LISTEN, service_on_listen,
|
||||
ACL_MASTER_SERVER_ON_ACCEPT, service_on_accept,
|
||||
ACL_MASTER_SERVER_ON_HANDSHAKE, service_on_handshake,
|
||||
ACL_MASTER_SERVER_ON_TIMEOUT, service_on_timeout,
|
||||
@ -203,8 +206,8 @@ int master_threads::service_on_accept(ACL_VSTREAM* client)
|
||||
// 如果子类的 thread_on_handshake 方法返回 false,则直接返回给上层
|
||||
// 框架 -1,由上层框架再调用 service_on_close 过程,从而在该过程
|
||||
// 中将 stream 对象释放
|
||||
if (__mt->thread_on_handshake(stream) == false)
|
||||
return -1;
|
||||
//if (__mt->thread_on_handshake(stream) == false)
|
||||
// return -1;
|
||||
|
||||
// 返回 0 表示可以继续处理该客户端连接,从而由上层框架将其置入
|
||||
// 读监控集合中
|
||||
@ -220,6 +223,9 @@ int master_threads::service_on_handshake(ACL_VSTREAM *client)
|
||||
if (stream == NULL)
|
||||
logger_fatal("client->context is null!");
|
||||
|
||||
// 如果子类的 thread_on_handshake 方法返回 false,则直接返回给上层
|
||||
// 框架 -1,由上层框架再调用 service_on_close 过程,从而在该过程
|
||||
// 中将 stream 对象释放
|
||||
if (__mt->thread_on_handshake(stream) == true)
|
||||
return 0;
|
||||
return -1;
|
||||
@ -265,6 +271,14 @@ int master_threads::service_main(ACL_VSTREAM *client, void*)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void master_threads::service_on_listen(ACL_VSTREAM* sstream)
|
||||
{
|
||||
acl_assert(__mt != NULL);
|
||||
server_socket* ss = new server_socket(sstream);
|
||||
__mt->servers_.push_back(ss);
|
||||
__mt->proc_on_listen(*ss);
|
||||
}
|
||||
|
||||
int master_threads::service_on_timeout(ACL_VSTREAM* client, void*)
|
||||
{
|
||||
socket_stream* stream = (socket_stream*) client->context;
|
||||
|
@ -1,4 +0,0 @@
|
||||
#include "acl_stdafx.hpp"
|
||||
#ifndef ACL_PREPARE_COMPILE
|
||||
#include "acl_cpp/master/master_threads2.hpp"
|
||||
#endif
|
@ -18,7 +18,8 @@ namespace acl
|
||||
|
||||
redis_client::redis_client(const char* addr, int conn_timeout /* = 60 */,
|
||||
int rw_timeout /* = 30 */, bool retry /* = true */)
|
||||
: retry_(retry)
|
||||
: check_addr_(false)
|
||||
, retry_(retry)
|
||||
, slice_req_(false)
|
||||
, slice_res_(false)
|
||||
{
|
||||
@ -37,6 +38,11 @@ redis_client::~redis_client()
|
||||
conn_.close();
|
||||
}
|
||||
|
||||
void redis_client::set_check_addr(bool on)
|
||||
{
|
||||
check_addr_ = on;
|
||||
}
|
||||
|
||||
void redis_client::set_password(const char* pass)
|
||||
{
|
||||
if (pass_)
|
||||
@ -57,6 +63,28 @@ socket_stream* redis_client::get_stream()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool redis_client::check_connection(socket_stream& conn)
|
||||
{
|
||||
char peer[64];
|
||||
ACL_SOCKET fd = conn.sock_handle();
|
||||
|
||||
if (acl_getpeername(fd, peer, sizeof(peer) - 1) == -1)
|
||||
{
|
||||
logger_error("getpeername failed: %s, fd: %d, addr: %s",
|
||||
last_serror(), (int) fd, addr_);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(peer, addr_) != 0)
|
||||
{
|
||||
logger_error("addr no matched, peer: %s, addr: %s, fd: %d",
|
||||
peer, addr_, (int) fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool redis_client::open()
|
||||
{
|
||||
if (conn_.opened())
|
||||
@ -313,7 +341,7 @@ redis_result* redis_client::get_redis_objects(dbuf_pool* pool, size_t nobjs)
|
||||
}
|
||||
|
||||
const redis_result* redis_client::run(dbuf_pool* pool, const string& req,
|
||||
size_t nchildren)
|
||||
size_t nchildren, int* rw_timeout /* = NULL */)
|
||||
{
|
||||
// 重置协议处理状态
|
||||
bool retried = false;
|
||||
@ -328,6 +356,16 @@ const redis_result* redis_client::run(dbuf_pool* pool, const string& req,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rw_timeout != NULL)
|
||||
conn_.set_rw_timeout(*rw_timeout);
|
||||
|
||||
if (check_addr_ && check_connection(conn_) == false)
|
||||
{
|
||||
logger_error("CHECK_CONNECTION FAILED!");
|
||||
close();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!req.empty() && conn_.write(req) == -1)
|
||||
{
|
||||
close();
|
||||
@ -349,10 +387,20 @@ const redis_result* redis_client::run(dbuf_pool* pool, const string& req,
|
||||
result = get_redis_object(pool);
|
||||
|
||||
if (result != NULL)
|
||||
{
|
||||
if (rw_timeout != NULL)
|
||||
conn_.set_rw_timeout(rw_timeout_);
|
||||
return result;
|
||||
}
|
||||
|
||||
close();
|
||||
|
||||
if (req.empty())
|
||||
{
|
||||
logger_error("no retry for request is empty");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!retry_ || retried)
|
||||
{
|
||||
logger_error("result NULL, addr: %s, retry: %s, "
|
||||
@ -375,7 +423,7 @@ const redis_result* redis_client::run(dbuf_pool* pool, const string& req,
|
||||
}
|
||||
|
||||
const redis_result* redis_client::run(dbuf_pool* pool, const redis_request& req,
|
||||
size_t nchildren)
|
||||
size_t nchildren, int* rw_timeout /* = NULL */)
|
||||
{
|
||||
// 重置协议处理状态
|
||||
bool retried = false;
|
||||
@ -390,6 +438,16 @@ const redis_result* redis_client::run(dbuf_pool* pool, const redis_request& req,
|
||||
if (open() == false)
|
||||
return NULL;
|
||||
|
||||
if (rw_timeout != NULL)
|
||||
conn_.set_rw_timeout(*rw_timeout);
|
||||
|
||||
if (check_addr_ && check_connection(conn_) == false)
|
||||
{
|
||||
logger_error("CHECK_CONNECTION FAILED!");
|
||||
close();
|
||||
break;
|
||||
}
|
||||
|
||||
if (size > 0 && conn_.writev(iov, (int) size) == -1)
|
||||
{
|
||||
close();
|
||||
@ -411,12 +469,21 @@ const redis_result* redis_client::run(dbuf_pool* pool, const redis_request& req,
|
||||
result = get_redis_object(pool);
|
||||
|
||||
if (result != NULL)
|
||||
{
|
||||
if (rw_timeout != NULL)
|
||||
conn_.set_rw_timeout(rw_timeout_);
|
||||
return result;
|
||||
}
|
||||
|
||||
close();
|
||||
|
||||
if (!retry_ || retried)
|
||||
if (!retry_ || retried || size == 0)
|
||||
{
|
||||
logger_error("retry_: %s, retried: %s, size: %d",
|
||||
retry_ ? "yes" : "no", retried ? "yes" : "no",
|
||||
(int) size);
|
||||
break;
|
||||
}
|
||||
|
||||
retried = true;
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ namespace acl
|
||||
#define LONG_LEN 21
|
||||
|
||||
redis_command::redis_command()
|
||||
: conn_(NULL)
|
||||
: check_addr_(false)
|
||||
, conn_(NULL)
|
||||
, cluster_(NULL)
|
||||
, max_conns_(0)
|
||||
, used_(0)
|
||||
@ -40,7 +41,8 @@ redis_command::redis_command()
|
||||
|
||||
|
||||
redis_command::redis_command(redis_client* conn)
|
||||
: conn_(conn)
|
||||
: check_addr_(false)
|
||||
, conn_(conn)
|
||||
, cluster_(NULL)
|
||||
, max_conns_(0)
|
||||
, used_(0)
|
||||
@ -64,7 +66,8 @@ redis_command::redis_command(redis_client* conn)
|
||||
}
|
||||
|
||||
redis_command::redis_command(redis_client_cluster* cluster, size_t max_conns)
|
||||
: conn_(NULL)
|
||||
: check_addr_(false)
|
||||
, conn_(NULL)
|
||||
, cluster_(cluster)
|
||||
, max_conns_(max_conns)
|
||||
, used_(0)
|
||||
@ -106,6 +109,11 @@ redis_command::~redis_command()
|
||||
dbuf_->destroy();
|
||||
}
|
||||
|
||||
void redis_command::set_check_addr(bool on)
|
||||
{
|
||||
check_addr_ = on;
|
||||
}
|
||||
|
||||
void redis_command::reset(bool save_slot /* = false */)
|
||||
{
|
||||
return clear(save_slot);
|
||||
@ -386,7 +394,7 @@ redis_client* redis_command::peek_conn(redis_client_cluster* cluster, int slot)
|
||||
}
|
||||
|
||||
const redis_result* redis_command::run(redis_client_cluster* cluster,
|
||||
size_t nchild)
|
||||
size_t nchild, int* timeout /* = NULL */)
|
||||
{
|
||||
redis_client* conn = peek_conn(cluster, slot_);
|
||||
|
||||
@ -398,6 +406,7 @@ const redis_result* redis_command::run(redis_client_cluster* cluster,
|
||||
}
|
||||
|
||||
set_client_addr(*conn);
|
||||
conn->set_check_addr(check_addr_);
|
||||
|
||||
redis_result_t type;
|
||||
bool last_moved = false;
|
||||
@ -407,9 +416,9 @@ const redis_result* redis_command::run(redis_client_cluster* cluster,
|
||||
{
|
||||
// 根据请求过程是否采用内存分片方式调用不同的请求过程
|
||||
if (slice_req_)
|
||||
result_ = conn->run(dbuf_, *request_obj_, nchild);
|
||||
result_ = conn->run(dbuf_, *request_obj_, nchild, timeout);
|
||||
else
|
||||
result_ = conn->run(dbuf_, *request_buf_, nchild);
|
||||
result_ = conn->run(dbuf_, *request_buf_, nchild, timeout);
|
||||
|
||||
// 如果连接异常断开,则需要进行重试
|
||||
if (conn->eof())
|
||||
@ -417,12 +426,19 @@ const redis_result* redis_command::run(redis_client_cluster* cluster,
|
||||
// 删除哈希槽中的地址映射关系以便下次操作时重新获取
|
||||
cluster->clear_slot(slot_);
|
||||
|
||||
// 将连接池对象置为不可用状态
|
||||
conn->get_pool()->set_alive(false);
|
||||
|
||||
// 将连接对象归还给连接池对象
|
||||
conn->get_pool()->put(conn, false);
|
||||
|
||||
// 如果连接断开且请求数据为空时,则无须重试
|
||||
if (request_obj_->get_size() == 0 && request_buf_->empty())
|
||||
{
|
||||
logger_error("not retry when no request!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 将连接池对象置为不可用状态
|
||||
conn->get_pool()->set_alive(false);
|
||||
|
||||
// 从连接池集群中顺序取得一个连接对象
|
||||
conn = peek_conn(cluster, slot_);
|
||||
if (conn == NULL)
|
||||
@ -565,6 +581,7 @@ const redis_result* redis_command::run(redis_client_cluster* cluster,
|
||||
if (result_ == NULL)
|
||||
{
|
||||
logger_error("ASKING's reply null");
|
||||
conn->get_pool()->put(conn, !conn->eof());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -573,6 +590,7 @@ const redis_result* redis_command::run(redis_client_cluster* cluster,
|
||||
{
|
||||
logger_error("ASKING's reply error: %s",
|
||||
status ? status : "null");
|
||||
conn->get_pool()->put(conn, !conn->eof());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -621,11 +639,15 @@ const redis_result* redis_command::run(redis_client_cluster* cluster,
|
||||
}
|
||||
}
|
||||
|
||||
if (conn != NULL)
|
||||
conn->get_pool()->put(conn, true);
|
||||
|
||||
logger_warn("too many redirect: %d, max: %d", n, redirect_max_);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const redis_result* redis_command::run(size_t nchild /* = 0 */)
|
||||
const redis_result* redis_command::run(size_t nchild /* = 0 */,
|
||||
int* timeout /* = NULL */)
|
||||
{
|
||||
// 如果上次操作时产生的内存分配没有被释放,在此处强制进行释放,以免用户
|
||||
// 在反复使用一个命令对象时忘记了 clear 清理临时内存
|
||||
@ -634,20 +656,20 @@ const redis_result* redis_command::run(size_t nchild /* = 0 */)
|
||||
used_++;
|
||||
|
||||
if (cluster_ != NULL)
|
||||
return run(cluster_, nchild);
|
||||
else if (conn_ != NULL)
|
||||
{
|
||||
if (slice_req_)
|
||||
result_ = conn_->run(dbuf_, *request_obj_, nchild);
|
||||
else
|
||||
result_ = conn_->run(dbuf_, *request_buf_, nchild);
|
||||
return result_;
|
||||
}
|
||||
else
|
||||
return run(cluster_, nchild, timeout);
|
||||
if (conn_ == NULL)
|
||||
{
|
||||
logger_error("ERROR: cluster_ and conn_ are all NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conn_->set_check_addr(check_addr_);
|
||||
|
||||
if (slice_req_)
|
||||
result_ = conn_->run(dbuf_, *request_obj_, nchild, timeout);
|
||||
else
|
||||
result_ = conn_->run(dbuf_, *request_buf_, nchild, timeout);
|
||||
return result_;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -1179,7 +1201,7 @@ const redis_result** redis_command::scan_keys(const char* cmd, const char* key,
|
||||
return NULL;
|
||||
}
|
||||
string tmp(128);
|
||||
if (rr->argv_to_string(tmp) < 0)
|
||||
if (rr->argv_to_string(tmp) <= 0)
|
||||
{
|
||||
cursor = -1;
|
||||
return NULL;
|
||||
|
@ -412,7 +412,8 @@ bool redis_list::bpop(const char* cmd, const std::vector<string>& keys,
|
||||
|
||||
bool redis_list::bpop(std::pair<string, string>& out)
|
||||
{
|
||||
const redis_result* result = run();
|
||||
int rw_timeout = -1;
|
||||
const redis_result* result = run(0, &rw_timeout);
|
||||
if (result == NULL)
|
||||
return false;
|
||||
if (result->get_type() != REDIS_RESULT_ARRAY)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "acl_stdafx.hpp"
|
||||
#ifndef ACL_PREPARE_COMPILE
|
||||
#include "acl_cpp/stdlib/log.hpp"
|
||||
#include "acl_cpp/stdlib/dbuf_pool.hpp"
|
||||
#include "acl_cpp/redis/redis_client.hpp"
|
||||
#include "acl_cpp/redis/redis_result.hpp"
|
||||
@ -40,6 +41,7 @@ int redis_pubsub::publish(const char* channel, const char* msg, size_t len)
|
||||
argv[2] = msg;
|
||||
lens[2] = len;
|
||||
|
||||
hash_slot(channel);
|
||||
build_request(3, argv, lens);
|
||||
return get_number();
|
||||
}
|
||||
@ -157,6 +159,9 @@ int redis_pubsub::subop(const char* cmd, const std::vector<const char*>& channel
|
||||
lens[i] = strlen(argv[i]);
|
||||
}
|
||||
|
||||
if (channels.size() == 1)
|
||||
hash_slot(channels[0]);
|
||||
|
||||
build_request(argc, argv, lens);
|
||||
const redis_result* result = run(channels.size());
|
||||
if (result == NULL || result->get_type() != REDIS_RESULT_ARRAY)
|
||||
@ -194,6 +199,9 @@ int redis_pubsub::subop(const char* cmd, const std::vector<string>& channels)
|
||||
lens[i] = (*cit).length();
|
||||
}
|
||||
|
||||
if (channels.size() == 1)
|
||||
hash_slot(channels[0].c_str());
|
||||
|
||||
build_request(argc, argv, lens);
|
||||
const redis_result* result = run(channels.size());
|
||||
if (result == NULL || result->get_type() != REDIS_RESULT_ARRAY)
|
||||
@ -246,17 +254,19 @@ int redis_pubsub::check_channel(const redis_result* obj, const char* cmd,
|
||||
return rr->get_integer();
|
||||
}
|
||||
|
||||
bool redis_pubsub::get_message(string& channel, string& msg)
|
||||
bool redis_pubsub::get_message(string& channel, string& msg,
|
||||
string* message_type /* = NULL */, string* pattern /* = NULL */)
|
||||
{
|
||||
clear_request();
|
||||
const redis_result* result = run();
|
||||
int rw_timeout = -1;
|
||||
const redis_result* result = run(0, &rw_timeout);
|
||||
if (result == NULL)
|
||||
return false;
|
||||
if (result->get_type() != REDIS_RESULT_ARRAY)
|
||||
return false;
|
||||
|
||||
size_t size = result->get_size();
|
||||
if (size != 3)
|
||||
if (size < 3)
|
||||
return false;
|
||||
|
||||
const redis_result* obj = result->get_child(0);
|
||||
@ -265,18 +275,62 @@ bool redis_pubsub::get_message(string& channel, string& msg)
|
||||
|
||||
string tmp;
|
||||
obj->argv_to_string(tmp);
|
||||
if (strcasecmp(tmp.c_str(), "message") != 0)
|
||||
return false;
|
||||
if (message_type)
|
||||
*message_type = tmp;
|
||||
if (tmp.equal("message", true))
|
||||
{
|
||||
if (pattern)
|
||||
pattern->clear();
|
||||
|
||||
obj = result->get_child(1);
|
||||
if (obj == NULL || obj->get_type() != REDIS_RESULT_STRING)
|
||||
obj = result->get_child(1);
|
||||
if (obj == NULL || obj->get_type() != REDIS_RESULT_STRING)
|
||||
return false;
|
||||
else
|
||||
obj->argv_to_string(channel);
|
||||
|
||||
obj = result->get_child(2);
|
||||
if (obj == NULL || obj->get_type() != REDIS_RESULT_STRING)
|
||||
return false;
|
||||
else
|
||||
obj->argv_to_string(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!tmp.equal("pmessage", false))
|
||||
{
|
||||
logger_error("unknown message type: %s", tmp.c_str());
|
||||
return false;
|
||||
obj->argv_to_string(channel);
|
||||
}
|
||||
|
||||
if (size < 4)
|
||||
{
|
||||
logger_error("invalid size: %d, message type: %s",
|
||||
(int) size, tmp.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pattern)
|
||||
{
|
||||
obj = result->get_child(1);
|
||||
if (obj == NULL || obj->get_type() != REDIS_RESULT_STRING)
|
||||
return false;
|
||||
else
|
||||
obj->argv_to_string(*pattern);
|
||||
}
|
||||
|
||||
obj = result->get_child(2);
|
||||
if (obj == NULL || obj->get_type() != REDIS_RESULT_STRING)
|
||||
return false;
|
||||
obj->argv_to_string(msg);
|
||||
else
|
||||
obj->argv_to_string(channel);
|
||||
|
||||
obj = result->get_child(3);
|
||||
if (obj == NULL || obj->get_type() != REDIS_RESULT_STRING)
|
||||
return false;
|
||||
else
|
||||
obj->argv_to_string(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ int redis_result::argv_to_string(string& buf) const
|
||||
buf.clear();
|
||||
|
||||
if (idx_ == 0)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
int length = 0;
|
||||
for (size_t i = 0; i < idx_; i++)
|
||||
@ -204,7 +204,7 @@ int redis_result::argv_to_string(string& buf) const
|
||||
int redis_result::argv_to_string(char* buf, size_t size) const
|
||||
{
|
||||
if (idx_ == 0 || size == 0)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
size--;
|
||||
if (size == 0)
|
||||
|
@ -36,7 +36,7 @@ bool redis_script::eval_status(const char* script,
|
||||
const std::vector<string>& args,
|
||||
const char* success /* = "OK" */)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, "EVAL", keys, args);
|
||||
const redis_result* result = eval_cmd("EVAL", script, keys, args);
|
||||
if (result == NULL)
|
||||
return false;
|
||||
const char* status = result->get_status();
|
||||
@ -50,7 +50,7 @@ bool redis_script::eval_number(const char* script,
|
||||
const std::vector<string>& args,
|
||||
int& out)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, "EVAL", keys, args);
|
||||
const redis_result* result = eval_cmd("EVAL", script, keys, args);
|
||||
if (result == NULL)
|
||||
return false;
|
||||
|
||||
@ -64,7 +64,7 @@ bool redis_script::eval_number64(const char* script,
|
||||
const std::vector<string>& args,
|
||||
long long int& out)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, "EVAL", keys, args);
|
||||
const redis_result* result = eval_cmd("EVAL", script, keys, args);
|
||||
if (result == NULL)
|
||||
return false;
|
||||
|
||||
@ -78,7 +78,7 @@ int redis_script::eval_string(const char* script,
|
||||
const std::vector<string>& args,
|
||||
string& out)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, "EVAL", keys, args);
|
||||
const redis_result* result = eval_cmd("EVAL", script, keys, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
@ -89,7 +89,7 @@ bool redis_script::evalsha_status(const char* script,
|
||||
const std::vector<string>& keys, const std::vector<string>& args,
|
||||
const char* success /* = "OK" */)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, "EVALSHA", keys, args);
|
||||
const redis_result* result = eval_cmd("EVALSHA", script, keys, args);
|
||||
if (result == NULL)
|
||||
return false;
|
||||
const char* status = result->get_status();
|
||||
@ -103,7 +103,7 @@ bool redis_script::evalsha_number(const char* script,
|
||||
const std::vector<string>& args,
|
||||
int& out)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, "EVALSHA", keys, args);
|
||||
const redis_result* result = eval_cmd("EVALSHA", script, keys, args);
|
||||
if (result == NULL)
|
||||
return false;
|
||||
|
||||
@ -117,7 +117,7 @@ bool redis_script::evalsha_number64(const char* script,
|
||||
const std::vector<string>& args,
|
||||
long long int& out)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, "EVALSHA", keys, args);
|
||||
const redis_result* result = eval_cmd("EVALSHA", script, keys, args);
|
||||
if (result == NULL)
|
||||
return false;
|
||||
|
||||
@ -131,7 +131,7 @@ int redis_script::evalsha_string(const char* script,
|
||||
const std::vector<string>& args,
|
||||
string& out)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, "EVALSHA", keys, args);
|
||||
const redis_result* result = eval_cmd("EVALSHA", script, keys, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
@ -214,7 +214,7 @@ int redis_script::eval_status(const char* cmd, const char* script,
|
||||
std::vector<bool>& out,
|
||||
const char* success /* = "OK" */)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, cmd, keys, args);
|
||||
const redis_result* result = eval_cmd(cmd, script, keys, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
@ -248,7 +248,7 @@ int redis_script::eval_number(const char* cmd, const char* script,
|
||||
std::vector<int>& out,
|
||||
std::vector<bool>& status)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, cmd, keys, args);
|
||||
const redis_result* result = eval_cmd(cmd, script, keys, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
@ -282,7 +282,7 @@ long long int redis_script::eval_number64(const char* cmd, const char* script,
|
||||
std::vector<long long int>& out,
|
||||
std::vector<bool>& status)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, cmd, keys, args);
|
||||
const redis_result* result = eval_cmd(cmd, script, keys, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
@ -315,7 +315,7 @@ int redis_script::eval_strings(const char* cmd, const char* script,
|
||||
const std::vector<string>& args,
|
||||
std::vector<string>& out)
|
||||
{
|
||||
const redis_result* result = eval_cmd(script, cmd, keys, args);
|
||||
const redis_result* result = eval_cmd(cmd, script, keys, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
@ -391,17 +391,16 @@ const redis_result* redis_script::eval_cmd(const char* cmd,
|
||||
lens[2] = strlen(buf);
|
||||
|
||||
size_t i = 3;
|
||||
std::vector<string>::const_iterator cit = keys.begin();
|
||||
std::vector<string>::const_iterator cit;
|
||||
|
||||
for (; cit != keys.end(); ++cit)
|
||||
for (cit = keys.begin(); cit != keys.end(); ++cit)
|
||||
{
|
||||
argv[i] = (*cit).c_str();
|
||||
lens[i] = (*cit).length();
|
||||
i++;
|
||||
}
|
||||
|
||||
cit = args.begin();
|
||||
for (; cit != args.end(); ++cit)
|
||||
for (cit = args.begin(); cit != args.end(); ++cit)
|
||||
{
|
||||
argv[i] = (*cit).c_str();
|
||||
lens[i] = (*cit).length();
|
||||
@ -410,6 +409,9 @@ const redis_result* redis_script::eval_cmd(const char* cmd,
|
||||
|
||||
acl_assert(i == argc);
|
||||
|
||||
if (keys.size() == 1)
|
||||
hash_slot(keys[0].c_str());
|
||||
|
||||
build_request(argc, argv, lens);
|
||||
return run();
|
||||
}
|
||||
@ -436,17 +438,16 @@ const redis_result* redis_script::eval_cmd(const char* cmd,
|
||||
lens[2] = strlen(buf);
|
||||
|
||||
size_t i = 3;
|
||||
std::vector<const char*>::const_iterator cit = keys.begin();
|
||||
std::vector<const char*>::const_iterator cit;
|
||||
|
||||
for (; cit != keys.end(); ++cit)
|
||||
for (cit = keys.begin(); cit != keys.end(); ++cit)
|
||||
{
|
||||
argv[i] = *cit;
|
||||
lens[i] = strlen(argv[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
cit = args.begin();
|
||||
for (; cit != args.end(); ++cit)
|
||||
for (cit = args.begin(); cit != args.end(); ++cit)
|
||||
{
|
||||
argv[i] = *cit;
|
||||
lens[i] = strlen(argv[i]);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user