Compare commits

...

6 Commits

Author SHA1 Message Date
Peter Thorson d4930319f1 add debug printing of basic headers 2014-04-23 08:25:54 -05:00
Peter Thorson ba805fc0c8 update unit tests for new processor config api 2014-04-23 07:54:26 -05:00
Peter Thorson 3730452c47 add processor logging of incoming frame headers 2014-04-23 07:54:15 -05:00
Peter Thorson dd67b92118 update connection to initialize processor logging
allows the processor to log directly to the connection’s log
2014-04-23 07:53:59 -05:00
Peter Thorson f980adebaa add logging hooks to processor base class 2014-04-23 07:53:24 -05:00
Peter Thorson 4d9a6741c9 fix log wording 2014-04-23 07:03:55 -05:00
7 changed files with 74 additions and 2 deletions
+7 -1
View File
@@ -36,6 +36,7 @@
#include <websocketpp/http/response.hpp>
#include <websocketpp/message_buffer/message.hpp>
#include <websocketpp/message_buffer/alloc.hpp>
#include <websocketpp/logger/stub.hpp>
struct stub_config {
typedef websocketpp::http::parser::request request_type;
@@ -45,8 +46,13 @@ struct stub_config {
<websocketpp::message_buffer::alloc::con_msg_manager> message_type;
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::log::stub alog_type;
typedef websocketpp::log::stub elog_type;
static const size_t max_message_size = 16000000;
};
struct processor_setup {
+4
View File
@@ -38,6 +38,7 @@
#include <websocketpp/message_buffer/alloc.hpp>
#include <websocketpp/extensions/permessage_deflate/disabled.hpp>
#include <websocketpp/random/none.hpp>
#include <websocketpp/logger/stub.hpp>
struct stub_config {
typedef websocketpp::http::parser::request request_type;
@@ -48,6 +49,9 @@ struct stub_config {
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::log::stub alog_type;
typedef websocketpp::log::stub elog_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
static const size_t max_message_size = 16000000;
+4
View File
@@ -38,6 +38,7 @@
#include <websocketpp/message_buffer/alloc.hpp>
#include <websocketpp/extensions/permessage_deflate/disabled.hpp>
#include <websocketpp/random/none.hpp>
#include <websocketpp/logger/stub.hpp>
struct stub_config {
typedef websocketpp::http::parser::request request_type;
@@ -48,6 +49,9 @@ struct stub_config {
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::log::stub alog_type;
typedef websocketpp::log::stub elog_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
static const size_t max_message_size = 16000000;
+7
View File
@@ -38,6 +38,7 @@
#include <websocketpp/message_buffer/message.hpp>
#include <websocketpp/message_buffer/alloc.hpp>
#include <websocketpp/random/none.hpp>
#include <websocketpp/logger/stub.hpp>
#include <websocketpp/extensions/permessage_deflate/disabled.hpp>
#include <websocketpp/extensions/permessage_deflate/enabled.hpp>
@@ -51,6 +52,9 @@ struct stub_config {
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::log::stub alog_type;
typedef websocketpp::log::stub elog_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
struct permessage_deflate_config {
@@ -73,6 +77,9 @@ struct stub_config_ext {
typedef websocketpp::message_buffer::alloc::con_msg_manager<message_type>
con_msg_manager_type;
typedef websocketpp::log::stub alog_type;
typedef websocketpp::log::stub elog_type;
typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
struct permessage_deflate_config {
+2 -1
View File
@@ -965,7 +965,7 @@ void connection<config>::handle_read_frame(lib::error_code const & ec,
if (m_processor->ready()) {
if (m_alog.static_test(log::alevel::devel)) {
std::stringstream s;
s << "Complete frame received. Dispatching";
s << "Complete message received. Dispatching";
m_alog.write(log::alevel::devel,s.str());
}
@@ -2005,6 +2005,7 @@ connection<config>::get_processor(int version) const {
}
// Settings not configured by the constructor
p->init_logging(&m_alog,&m_elog);
p->set_max_message_size(m_max_message_size);
return p;
+19
View File
@@ -331,6 +331,14 @@ public:
continue;
}
if (base::m_alog->static_test(log::alevel::devel)) {
std::stringstream s;
s << "Received frame basic header: "
<< utility::to_hex(&m_basic_header.b0,1)
<< utility::to_hex(&m_basic_header.b1,1);
base::m_alog->write(log::alevel::devel,s.str());
}
ec = this->validate_incoming_basic_header(
m_basic_header, base::m_server, !m_data_msg.msg_ptr
);
@@ -348,6 +356,17 @@ public:
continue;
}
if (base::m_alog->static_test(log::alevel::devel)) {
std::stringstream s;
s << "Received frame full header: "
<< utility::to_hex(&m_basic_header.b0,1)
<< utility::to_hex(&m_basic_header.b1,1)
<< utility::to_hex(m_extended_header.bytes,
frame::get_header_len(m_basic_header) -
frame::BASIC_HEADER_LENGTH);
base::m_alog->write(log::alevel::devel,s.str());
}
ec = validate_incoming_extended_header(m_basic_header,m_extended_header);
if (ec){break;}
+31
View File
@@ -31,9 +31,12 @@
#include <websocketpp/processors/base.hpp>
#include <websocketpp/common/system_error.hpp>
#include <websocketpp/close.hpp>
#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/utilities.hpp>
#include <websocketpp/uri.hpp>
#include <websocketpp/logger/levels.hpp>
#include <map>
#include <string>
@@ -159,10 +162,17 @@ public:
typedef typename config::message_type::ptr message_ptr;
typedef std::pair<lib::error_code,std::string> err_str_pair;
/// Type of this processor's error logging policy
typedef typename config::elog_type elog_type;
/// Type of this processor's access logging policy
typedef typename config::alog_type alog_type;
explicit processor(bool secure, bool p_is_server)
: m_secure(secure)
, m_server(p_is_server)
, m_max_message_size(config::max_message_size)
, m_elog(_WEBSOCKETPP_NULLPTR_TOKEN_)
, m_alog(_WEBSOCKETPP_NULLPTR_TOKEN_)
{}
virtual ~processor() {}
@@ -170,6 +180,25 @@ public:
/// Get the protocol version of this processor
virtual int get_version() const = 0;
/// Initialize logging
/**
* The loggers are managed by the owner of the processor. As such, the
* processor doesn't have direct access to them. This method is called by
* the owner to allow shared logging from the processor component. These are
* raw pointers to the logging types specified in the config. It is the
* responsibility of the owning object to ensure that they remain in scope
* until the processor goes out of scope.
*
* TODO: better way of handling non-initialized logging?
*
* @param a A pointer to the access logger to use.
* @param e A pointer to the error logger to use.
*/
void init_logging(alog_type * a, elog_type * e) {
m_elog = e;
m_alog = a;
}
/// Get maximum message size
/**
* Get maximum message size. Maximum message size determines the point at which the
@@ -389,6 +418,8 @@ protected:
bool const m_secure;
bool const m_server;
size_t m_max_message_size;
elog_type* m_elog;
alog_type* m_alog;
};
} // namespace processor