mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 19:25:51 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user