statically bind frame read and write handlers

This commit is contained in:
Peter Thorson
2013-10-16 08:25:10 -05:00
parent 8b9fa5db72
commit 71e6babd93
2 changed files with 32 additions and 9 deletions

View File

@@ -149,6 +149,10 @@ typedef lib::function<bool(connection_hdl)> validate_handler;
*/
typedef lib::function<void(connection_hdl)> http_handler;
//
typedef lib::function<void(lib::error_code const & ec, size_t bytes_transferred)> read_handler;
typedef lib::function<void(lib::error_code const & ec)> write_frame_handler;
// constants related to the default WebSocket protocol versions available
#ifdef _WEBSOCKETPP_INITIALIZER_LISTS_ // simplified C++11 version
/// Container that stores the list of protocol versions supported
@@ -278,6 +282,17 @@ public:
explicit connection(bool is_server, std::string const & ua, alog_type& alog,
elog_type& elog, rng_type & rng)
: transport_con_type(is_server,alog,elog)
, m_handle_read_frame(lib::bind(
&type::handle_read_frame,
this,
lib::placeholders::_1,
lib::placeholders::_2
))
, m_write_frame_handler(lib::bind(
&type::handle_write_frame,
this,
lib::placeholders::_1
))
, m_user_agent(ua)
, m_state(session::state::connecting)
, m_internal_state(session::internal_state::USER_INIT)
@@ -1034,7 +1049,7 @@ public:
* @param ec A status code from the transport layer, zero on success,
* non-zero otherwise.
*/
void handle_write_frame(bool terminate, lib::error_code const & ec);
void handle_write_frame(lib::error_code const & ec);
protected:
void handle_transport_init(lib::error_code const & ec);
@@ -1190,6 +1205,10 @@ private:
*/
void log_fail_result();
// internal handler functions
read_handler m_handle_read_frame;
write_frame_handler m_write_frame_handler;
// static settings
const std::string m_user_agent;

View File

@@ -942,12 +942,13 @@ void connection<config>::handle_read_frame(const lib::error_code& ec,
1,
m_buf,
config::connection_read_buffer_size,
lib::bind(
/*lib::bind(
&type::handle_read_frame,
type::get_shared(),
lib::placeholders::_1,
lib::placeholders::_2
)
)*/
m_handle_read_frame
);
}
@@ -1540,8 +1541,8 @@ void connection<config>::write_frame() {
m_write_flag = true;
}
const std::string& header = m_current_msg->get_header();
const std::string& payload = m_current_msg->get_payload();
std::string const & header = m_current_msg->get_header();
std::string const & payload = m_current_msg->get_payload();
m_send_buffer.push_back(transport::buffer(header.c_str(),header.size()));
m_send_buffer.push_back(transport::buffer(payload.c_str(),payload.size()));
@@ -1563,25 +1564,28 @@ void connection<config>::write_frame() {
}
}
transport_con_type::async_write(
m_send_buffer,
lib::bind(
/*lib::bind(
&type::handle_write_frame,
type::get_shared(),
m_current_msg->get_terminal(),
lib::placeholders::_1
)
)*/
m_write_frame_handler
);
}
template <typename config>
void connection<config>::handle_write_frame(bool terminate,
const lib::error_code& ec)
void connection<config>::handle_write_frame(lib::error_code const & ec)
{
if (m_alog.static_test(log::alevel::devel)) {
m_alog.write(log::alevel::devel,"connection handle_write_frame");
}
bool terminate = m_current_msg->get_terminal();
m_send_buffer.clear();
m_current_msg.reset();