removes expensive development logging from non-debug builds

This commit is contained in:
Peter Thorson
2013-04-29 13:06:17 -05:00
parent 865da6dba2
commit be07587659
2 changed files with 198 additions and 186 deletions

View File

@@ -729,7 +729,7 @@ template <typename config>
void connection<config>::handle_read_frame(const lib::error_code& ec,
size_t bytes_transferred)
{
m_alog.write(log::alevel::devel,"connection handle_read_frame");
//m_alog.write(log::alevel::devel,"connection handle_read_frame");
this->atomic_state_check(
istate::PROCESS_CONNECTION,
@@ -761,14 +761,18 @@ void connection<config>::handle_read_frame(const lib::error_code& ec,
size_t p = 0;
std::stringstream s;
s << "p = " << p << " bytes transferred = " << bytes_transferred;
m_alog.write(log::alevel::devel,s.str());
if (m_alog.static_test(log::alevel::devel)) {
std::stringstream s;
s << "p = " << p << " bytes transferred = " << bytes_transferred;
m_alog.write(log::alevel::devel,s.str());
}
while (p < bytes_transferred) {
s.str("");
s << "calling consume with " << bytes_transferred-p << " bytes";
m_alog.write(log::alevel::devel,s.str());
if (m_alog.static_test(log::alevel::devel)) {
std::stringstream s;
s << "calling consume with " << bytes_transferred-p << " bytes";
m_alog.write(log::alevel::devel,s.str());
}
lib::error_code ec;
@@ -777,11 +781,12 @@ void connection<config>::handle_read_frame(const lib::error_code& ec,
bytes_transferred-p,
ec
);
s.str("");
s << "bytes left after consume: " << bytes_transferred-p;
m_alog.write(log::alevel::devel,s.str());
if (m_alog.static_test(log::alevel::devel)) {
std::stringstream s;
s << "bytes left after consume: " << bytes_transferred-p;
m_alog.write(log::alevel::devel,s.str());
}
if (ec) {
m_elog.write(log::elevel::rerror,"consume error: "+ec.message());
@@ -804,7 +809,7 @@ void connection<config>::handle_read_frame(const lib::error_code& ec,
}
if (m_processor->ready()) {
m_alog.write(log::alevel::devel,"consume ended in ready");
//m_alog.write(log::alevel::devel,"consume ended in ready");
message_ptr msg = m_processor->get_message();
@@ -1345,7 +1350,7 @@ void connection<config>::terminate() {
template <typename config>
void connection<config>::write_frame() {
m_alog.write(log::alevel::devel,"connection write_frame");
//m_alog.write(log::alevel::devel,"connection write_frame");
{
scoped_lock_type lock(m_write_lock);
@@ -1377,8 +1382,10 @@ void connection<config>::write_frame() {
m_send_buffer.push_back(transport::buffer(header.c_str(),header.size()));
m_send_buffer.push_back(transport::buffer(payload.c_str(),payload.size()));
if (m_alog.static_test(log::alevel::frame_header)) {
if (m_alog.dynamic_test(log::alevel::frame_header)) {
std::stringstream s;
s << "Dispatching write with " << header.size()
<< " header bytes and " << payload.size()
@@ -1386,9 +1393,12 @@ void connection<config>::write_frame() {
m_alog.write(log::alevel::frame_header,s.str());
m_alog.write(log::alevel::frame_header,"Header: "+utility::to_hex(header));
}
}
if (m_alog.static_test(log::alevel::frame_payload)) {
if (m_alog.dynamic_test(log::alevel::frame_payload)) {
m_alog.write(log::alevel::frame_payload,"Payload: "+utility::to_hex(payload));
}
}
transport_con_type::async_write(
m_send_buffer,

View File

@@ -57,7 +57,7 @@ template <typename config>
class connection : public config::socket_type::socket_con_type {
public:
/// Type of this connection transport component
typedef connection<config> type;
typedef connection<config> type;
/// Type of a shared pointer to this connection transport component
typedef lib::shared_ptr<type> ptr;
@@ -69,44 +69,44 @@ public:
typedef typename config::alog_type alog_type;
/// Type of this transport's error logging policy
typedef typename config::elog_type elog_type;
typedef typename config::request_type request_type;
typedef typename request_type::ptr request_ptr;
typedef typename config::request_type request_type;
typedef typename request_type::ptr request_ptr;
typedef typename config::response_type response_type;
typedef typename response_type::ptr response_ptr;
/// Type of a pointer to the ASIO io_service being used
typedef boost::asio::io_service* io_service_ptr;
typedef boost::asio::io_service* io_service_ptr;
// generate and manage our own io_service
explicit connection(bool is_server, alog_type& alog, elog_type& elog)
: m_is_server(is_server)
, m_alog(alog)
, m_elog(elog)
{
// generate and manage our own io_service
explicit connection(bool is_server, alog_type& alog, elog_type& elog)
: m_is_server(is_server)
, m_alog(alog)
, m_elog(elog)
{
m_alog.write(log::alevel::devel,"asio con transport constructor");
}
bool is_secure() const {
return socket_con_type::is_secure();
}
/// Finish constructing the transport
/**
* init_asio is called once immediately after construction to initialize
* boost::asio components to the io_service
*
* TODO: this method is not protected because the endpoint needs to call it.
* need to figure out if there is a way to friend the endpoint safely across
* different compilers.
*/
}
bool is_secure() const {
return socket_con_type::is_secure();
}
/// Finish constructing the transport
/**
* init_asio is called once immediately after construction to initialize
* boost::asio components to the io_service
*
* TODO: this method is not protected because the endpoint needs to call it.
* need to figure out if there is a way to friend the endpoint safely across
* different compilers.
*/
void init_asio (io_service_ptr io_service) {
// do we need to store or use the io_service at this level?
m_io_service = io_service;
// do we need to store or use the io_service at this level?
m_io_service = io_service;
//m_strand.reset(new boost::asio::strand(*io_service));
socket_con_type::init_asio(io_service, m_is_server);
socket_con_type::init_asio(io_service, m_is_server);
}
void set_tcp_init_handler(tcp_init_handler h) {
@@ -122,27 +122,27 @@ public:
}
/// Get the remote endpoint address
/**
* The iostream transport has no information about the ultimate remote
* endpoint. It will return the string "iostream transport". To indicate
* this.
*
* TODO: allow user settable remote endpoint addresses if this seems useful
*
* @return A string identifying the address of the remote endpoint
*/
std::string get_remote_endpoint() const {
lib::error_code ec;
std::string ret = socket_con_type::get_remote_endpoint(ec);
if (ec) {
m_elog.write(log::elevel::info,ret);
return "Unknown";
} else {
return ret;
}
}
/**
* The iostream transport has no information about the ultimate remote
* endpoint. It will return the string "iostream transport". To indicate
* this.
*
* TODO: allow user settable remote endpoint addresses if this seems useful
*
* @return A string identifying the address of the remote endpoint
*/
std::string get_remote_endpoint() const {
lib::error_code ec;
std::string ret = socket_con_type::get_remote_endpoint(ec);
if (ec) {
m_elog.write(log::elevel::info,ret);
return "Unknown";
} else {
return ret;
}
}
/// Get the connection handle
connection_hdl get_handle() const {
@@ -166,40 +166,40 @@ public:
protected:
/// Initialize transport for reading
/**
* init_asio is called once immediately after construction to initialize
* boost::asio components to the io_service
*/
/**
* init_asio is called once immediately after construction to initialize
* boost::asio components to the io_service
*/
void init(init_handler callback) {
m_alog.write(log::alevel::devel,"asio connection init");
socket_con_type::init(
lib::bind(
&type::handle_init,
this,
callback,
lib::placeholders::_1
)
);
}
void handle_init(init_handler callback, const lib::error_code& ec) {
if (m_tcp_init_handler) {
m_tcp_init_handler(m_connection_hdl);
}
if (ec) {
callback(ec);
}
// If no error, and we are an insecure connection with a proxy set
// issue a proxy connect.
if (!m_proxy.empty()) {
proxy_write(callback);
} else {
callback(ec);
}
}
socket_con_type::init(
lib::bind(
&type::handle_init,
this,
callback,
lib::placeholders::_1
)
);
}
void handle_init(init_handler callback, const lib::error_code& ec) {
if (m_tcp_init_handler) {
m_tcp_init_handler(m_connection_hdl);
}
if (ec) {
callback(ec);
}
// If no error, and we are an insecure connection with a proxy set
// issue a proxy connect.
if (!m_proxy.empty()) {
proxy_write(callback);
} else {
callback(ec);
}
}
void proxy_write(init_handler callback) {
if (!m_proxy_data) {
@@ -236,10 +236,10 @@ protected:
if (ec) {
m_elog.write(log::elevel::info,
"asio handle_proxy_write error: "+ec.message());
callback(make_error_code(error::pass_through));
} else {
proxy_read(callback);
}
callback(make_error_code(error::pass_through));
} else {
proxy_read(callback);
}
}
void proxy_read(init_handler callback) {
@@ -251,17 +251,17 @@ protected:
}
boost::asio::async_read_until(
socket_con_type::get_socket(),
m_proxy_data->read_buf,
"\r\n\r\n",
lib::bind(
&type::handle_proxy_read,
this,
callback,
lib::placeholders::_1,
lib::placeholders::_2
)
);
socket_con_type::get_socket(),
m_proxy_data->read_buf,
"\r\n\r\n",
lib::bind(
&type::handle_proxy_read,
this,
callback,
lib::placeholders::_1,
lib::placeholders::_2
)
);
}
void handle_proxy_read(init_handler callback, const
@@ -270,9 +270,9 @@ protected:
if (ec) {
m_elog.write(log::elevel::info,
"asio handle_proxy_read error: "+ec.message());
callback(make_error_code(error::pass_through));
} else {
if (!m_proxy_data) {
callback(make_error_code(error::pass_through));
} else {
if (!m_proxy_data) {
m_elog.write(log::elevel::library,
"assertion failed: !m_proxy_data in asio::connection::handle_proxy_read");
callback(make_error_code(error::general));
@@ -320,55 +320,57 @@ protected:
// call the original init handler back.
callback(lib::error_code());
}
}
}
/// read at least num_bytes bytes into buf and then call handler.
/**
*
*
*/
void async_read_at_least(size_t num_bytes, char *buf, size_t len,
read_handler handler)
{
std::stringstream s;
s << "asio async_read_at_least: " << num_bytes;
m_alog.write(log::alevel::devel,s.str());
if (num_bytes > len) {
/**
*
*
*/
void async_read_at_least(size_t num_bytes, char *buf, size_t len,
read_handler handler)
{
if (m_alog.static_test(log::alevel::devel)) {
std::stringstream s;
s << "asio async_read_at_least: " << num_bytes;
m_alog.write(log::alevel::devel,s.str());
}
if (num_bytes > len) {
m_elog.write(log::elevel::devel,
"asio async_read_at_least error::invalid_num_bytes");
handler(make_error_code(transport::error::invalid_num_bytes),
size_t(0));
return;
}
boost::asio::async_read(
socket_con_type::get_socket(),
boost::asio::buffer(buf,len),
boost::asio::transfer_at_least(num_bytes),
lib::bind(
&type::handle_async_read,
this,
handler,
lib::placeholders::_1,
lib::placeholders::_2
)
);
}
handler(make_error_code(transport::error::invalid_num_bytes),
size_t(0));
return;
}
boost::asio::async_read(
socket_con_type::get_socket(),
boost::asio::buffer(buf,len),
boost::asio::transfer_at_least(num_bytes),
lib::bind(
&type::handle_async_read,
this,
handler,
lib::placeholders::_1,
lib::placeholders::_2
)
);
}
void handle_async_read(read_handler handler, const
boost::system::error_code& ec, size_t bytes_transferred)
{
if (!ec) {
handler(lib::error_code(), bytes_transferred);
return;
}
// translate boost error codes into more lib::error_codes
if (!ec) {
handler(lib::error_code(), bytes_transferred);
return;
}
// translate boost error codes into more lib::error_codes
if (ec == boost::asio::error::eof) {
handler(make_error_code(transport::error::eof),
bytes_transferred);
bytes_transferred);
} else {
// other error that we cannot translate into a WebSocket++
// transport error. Use pass through and print an info warning
@@ -378,23 +380,23 @@ protected:
<< ", Original Error: " << ec << " (" << ec.message() << ")";
m_elog.write(log::elevel::info,s.str());
handler(make_error_code(transport::error::pass_through),
bytes_transferred);
bytes_transferred);
}
}
void async_write(const char* buf, size_t len, write_handler handler) {
m_bufs.push_back(boost::asio::buffer(buf,len));
boost::asio::async_write(
socket_con_type::get_socket(),
socket_con_type::get_socket(),
m_bufs,
lib::bind(
&type::handle_async_write,
this,
handler,
lib::placeholders::_1
)
);
lib::bind(
&type::handle_async_write,
this,
handler,
lib::placeholders::_1
)
);
}
void async_write(const std::vector<buffer>& bufs, write_handler handler) {
@@ -404,28 +406,28 @@ protected:
m_bufs.push_back(boost::asio::buffer((*it).buf,(*it).len));
}
boost::asio::async_write(
socket_con_type::get_socket(),
m_bufs,
lib::bind(
&type::handle_async_write,
this,
handler,
lib::placeholders::_1
)
);
boost::asio::async_write(
socket_con_type::get_socket(),
m_bufs,
lib::bind(
&type::handle_async_write,
this,
handler,
lib::placeholders::_1
)
);
}
void handle_async_write(write_handler handler, const
boost::system::error_code& ec)
boost::system::error_code& ec)
{
m_bufs.clear();
// TODO: translate this better
if (ec) {
handler(make_error_code(error::pass_through));
} else {
handler(lib::error_code());
}
// TODO: translate this better
if (ec) {
handler(make_error_code(error::pass_through));
} else {
handler(lib::error_code());
}
}
/// Set Connection Handle
@@ -488,8 +490,8 @@ protected:
}
}
private:
// static settings
const bool m_is_server;
// static settings
const bool m_is_server;
alog_type& m_alog;
elog_type& m_elog;
@@ -502,8 +504,8 @@ private:
std::string m_proxy;
lib::shared_ptr<proxy_data> m_proxy_data;
// transport resources
// transport resources
io_service_ptr m_io_service;
connection_hdl m_connection_hdl;
std::vector<boost::asio::const_buffer> m_bufs;