when acl was installed into system by using rpm, the logger's compiling warn wasn't useful.

This commit is contained in:
zhengshuxin 2017-09-01 17:43:12 +08:00
parent 56b2d6115a
commit 25d33da4de
7 changed files with 200 additions and 20 deletions

View File

@ -1,4 +1,9 @@
11) 2017.9.1
11.1) 当将 acl 以 rpm 包方式安装后logger 等宏中的编译警告报警不生效,应是
编译器自动优化了系统中头文件的处理,现将这些宏重新在 stdafx.h 中定义,从而
帮助开发者在编译期间尽早发现问题
10) 2016.11.18
10.1) master_proc.cpp/master_threads.cpp: 在 on_accept 中当 var_cfg_rw_timeout > 0
时,将套接口设为非阻塞模式,以防止写超时

View File

@ -4,16 +4,14 @@
http_servlet::http_servlet(acl::socket_stream* stream, acl::session* session)
: acl::HttpServlet(stream, session)
{
handlers_["/hello"] = &http_servlet::on_hello;
}
http_servlet::~http_servlet(void)
{
}
bool http_servlet::doError(acl::HttpServletRequest&,
acl::HttpServletResponse& res)
bool http_servlet::doError(request_t&, response_t& res)
{
res.setStatus(400);
res.setContentType("text/xml; charset=utf-8");
@ -26,8 +24,7 @@ bool http_servlet::doError(acl::HttpServletRequest&,
return false;
}
bool http_servlet::doOther(acl::HttpServletRequest&,
acl::HttpServletResponse& res, const char* method)
bool http_servlet::doOther(request_t&, response_t& res, const char* method)
{
res.setStatus(400);
res.setContentType("text/xml; charset=utf-8");
@ -39,14 +36,12 @@ bool http_servlet::doOther(acl::HttpServletRequest&,
return false;
}
bool http_servlet::doGet(acl::HttpServletRequest& req,
acl::HttpServletResponse& res)
bool http_servlet::doGet(request_t& req, response_t& res)
{
return doPost(req, res);
}
bool http_servlet::doPost(acl::HttpServletRequest& req,
acl::HttpServletResponse& res)
bool http_servlet::doPost(request_t& req, response_t& res)
{
// 如果需要 http session 控制,请打开下面注释,且需要保证
// 在 master_service.cpp 的函数 thread_on_read 中设置的
@ -63,6 +58,18 @@ bool http_servlet::doPost(acl::HttpServletRequest& req,
$<GET_COOKIES>
*/
const char* path = req.getPathInfo();
handler_t handler = path && *path ? handlers_[path] : NULL;
return handler ? (this->*handler)(req, res) : on_default(req, res);
}
bool http_servlet::on_default(request_t& req, response_t& res)
{
return on_hello(req, res);
}
bool http_servlet::on_hello(request_t& req, response_t& res)
{
res.setContentType("text/xml; charset=utf-8") // 设置响应字符集
.setKeepAlive(req.isKeepAlive()) // 设置是否保持长连接
.setContentEncoding(true) // 自动支持压缩传输

View File

@ -3,16 +3,26 @@
class http_servlet : public acl::HttpServlet
{
public:
http_servlet(acl::socket_stream* stream, acl::session* session);
http_servlet(acl::socket_stream*, acl::session*);
~http_servlet();
protected:
virtual bool doError(acl::HttpServletRequest&,
acl::HttpServletResponse& res);
virtual bool doOther(acl::HttpServletRequest&,
acl::HttpServletResponse& res, const char* method);
virtual bool doGet(acl::HttpServletRequest& req,
acl::HttpServletResponse& res);
virtual bool doPost(acl::HttpServletRequest& req,
acl::HttpServletResponse& res);
// @override
bool doGet(request_t&, response_t&);
// @override
bool doPost(request_t&, response_t&);
// @override
bool doError(request_t&, response_t&);
// @override
bool doOther(request_t&, response_t&, const char* method);
private:
typedef bool (http_servlet::*handler_t)(request_t&,response_t&);
std::map<std::string, handler_t> handlers_;
bool on_default(request_t&, response_t&);
bool on_hello(request_t&, response_t&);
};

View File

@ -10,10 +10,51 @@
// TODO: 在此处引用程序要求的附加头文件
#include "acl_cpp/lib_acl.hpp"
#include "lib_acl.h"
#include "acl_cpp/lib_acl.hpp"
#ifdef WIN32
#define snprintf _snprintf
#endif
typedef acl::HttpServletRequest request_t;
typedef acl::HttpServletResponse response_t;
#undef logger
#undef logger_warn
#undef logger_error
#undef logger_fatal
#undef logger_debug
#if defined(_WIN32) || defined(_WIN64)
# if _MSC_VER >= 1500
# define logger(fmt, ...) \
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_warn(fmt, ...) \
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_error(fmt, ...) \
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_fatal(fmt, ...) \
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_debug(section, level, fmt, ...) \
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# else
# define logger acl::log::msg1
# define logger_warn acl::log::warn1
# define logger_error acl::log::error1
# define logger_fatal acl::log::fatal1
# define logger_debug acl::log::msg3
# endif
#else
# define logger(fmt, args...) \
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_warn(fmt, args...) \
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_error(fmt, args...) \
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_fatal(fmt, args...) \
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_debug(section, level, fmt, args...) \
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, ##args)
#endif // !_WIN32 && !_WIN64

View File

@ -19,3 +19,44 @@
#define snprintf _snprintf
#endif
typedef acl::HttpServletRequest request_t;
typedef acl::HttpServletResponse response_t;
#undef logger
#undef logger_warn
#undef logger_error
#undef logger_fatal
#undef logger_debug
#if defined(_WIN32) || defined(_WIN64)
# if _MSC_VER >= 1500
# define logger(fmt, ...) \
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_warn(fmt, ...) \
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_error(fmt, ...) \
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_fatal(fmt, ...) \
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_debug(section, level, fmt, ...) \
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# else
# define logger acl::log::msg1
# define logger_warn acl::log::warn1
# define logger_error acl::log::error1
# define logger_fatal acl::log::fatal1
# define logger_debug acl::log::msg3
# endif
#else
# define logger(fmt, args...) \
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_warn(fmt, args...) \
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_error(fmt, args...) \
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_fatal(fmt, args...) \
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_debug(section, level, fmt, args...) \
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, ##args)
#endif // !_WIN32 && !_WIN64

View File

@ -17,3 +17,41 @@
#define snprintf _snprintf
#endif
#undef logger
#undef logger_warn
#undef logger_error
#undef logger_fatal
#undef logger_debug
#if defined(_WIN32) || defined(_WIN64)
# if _MSC_VER >= 1500
# define logger(fmt, ...) \
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_warn(fmt, ...) \
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_error(fmt, ...) \
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_fatal(fmt, ...) \
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_debug(section, level, fmt, ...) \
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# else
# define logger acl::log::msg1
# define logger_warn acl::log::warn1
# define logger_error acl::log::error1
# define logger_fatal acl::log::fatal1
# define logger_debug acl::log::msg3
# endif
#else
# define logger(fmt, args...) \
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_warn(fmt, args...) \
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_error(fmt, args...) \
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_fatal(fmt, args...) \
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_debug(section, level, fmt, args...) \
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, ##args)
#endif // !_WIN32 && !_WIN64

View File

@ -19,3 +19,41 @@
#define snprintf _snprintf
#endif
#undef logger
#undef logger_warn
#undef logger_error
#undef logger_fatal
#undef logger_debug
#if defined(_WIN32) || defined(_WIN64)
# if _MSC_VER >= 1500
# define logger(fmt, ...) \
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_warn(fmt, ...) \
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_error(fmt, ...) \
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_fatal(fmt, ...) \
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# define logger_debug(section, level, fmt, ...) \
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
# else
# define logger acl::log::msg1
# define logger_warn acl::log::warn1
# define logger_error acl::log::error1
# define logger_fatal acl::log::fatal1
# define logger_debug acl::log::msg3
# endif
#else
# define logger(fmt, args...) \
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_warn(fmt, args...) \
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_error(fmt, args...) \
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_fatal(fmt, args...) \
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
# define logger_debug(section, level, fmt, args...) \
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, ##args)
#endif // !_WIN32 && !_WIN64