Expose a method and add a handler in websocketpp.

* Expose websocketpp::transport::asio::connection::get_strand().
* Add new send_empty_handler to websocketpp::endpoint.
This commit is contained in:
Tom Ritchford
2015-02-04 14:35:50 -05:00
parent 9c3522cb70
commit e5b0b7e9a7
4 changed files with 32 additions and 1 deletions

View File

@@ -150,6 +150,13 @@ typedef lib::function<bool(connection_hdl)> validate_handler;
*/
typedef lib::function<void(connection_hdl)> http_handler;
/// The type and function signature of an send_empty handler
/**
* The send_empty handler is called each time the send queue becomes empty of
* messages.
*/
typedef lib::function<void(connection_hdl)> send_empty_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;
@@ -458,6 +465,16 @@ public:
m_message_handler = h;
}
/// Set send empty handler
/**
* The send empty handler is called when the message queue is empty.
*
* @param h The new message_handler
*/
void set_send_empty_handler(send_empty_handler h) {
m_send_empty_handler = h;
}
//////////////////////////////////////////
// Connection timeouts and other limits //
//////////////////////////////////////////
@@ -1382,6 +1399,7 @@ private:
http_handler m_http_handler;
validate_handler m_validate_handler;
message_handler m_message_handler;
send_empty_handler m_send_empty_handler;
/// constant values
long m_open_handshake_timeout_dur;

View File

@@ -271,6 +271,11 @@ public:
scoped_lock_type guard(m_mutex);
m_message_handler = h;
}
void set_send_empty_handler(send_empty_handler h) {
m_alog.write(log::alevel::devel,"set_send_empty_handler");
scoped_lock_type guard(m_mutex);
m_send_empty_handler = h;
}
//////////////////////////////////////////
// Connection timeouts and other limits //
@@ -560,6 +565,7 @@ private:
http_handler m_http_handler;
validate_handler m_validate_handler;
message_handler m_message_handler;
send_empty_handler m_send_empty_handler;
long m_open_handshake_timeout_dur;
long m_close_handshake_timeout_dur;

View File

@@ -1575,7 +1575,9 @@ void connection<config>::write_frame() {
// pull off all the messages that are ready to write.
// stop if we get a message marked terminal
message_ptr next_message = write_pop();
bool saw_message = false;
while (next_message) {
saw_message = true;
m_current_msgs.push_back(next_message);
if (!next_message->get_terminal()) {
next_message = write_pop();
@@ -1586,6 +1588,10 @@ void connection<config>::write_frame() {
if (m_current_msgs.empty()) {
// there was nothing to send
// If we just made the transition to empty, send out
// "send_empty" callback.
if (saw_message)
m_send_empty_handler(m_connection_hdl);
return;
} else {
// At this point we own the next messages to be sent and are

View File

@@ -339,12 +339,13 @@ public:
callback(lib::error_code());
}
}
protected:
/// Get a pointer to this connection's strand
strand_ptr get_strand() {
return m_strand;
}
protected:
/// Initialize transport for reading
/**
* init_asio is called once immediately after construction to initialize