preliminary work on various timeouts, adjusts the handler API to be more consistant

This commit is contained in:
Peter Thorson
2011-10-20 08:45:10 -05:00
parent 333fd6101e
commit 41f60162ec
5 changed files with 26 additions and 4 deletions

View File

@@ -48,8 +48,9 @@ public:
// an echo server is stateless.
// The handler has no need to keep track of connected clients.
void on_fail(session_ptr client) {}
void on_open(session_ptr client) {}
void on_close(session_ptr client,uint16_t status,const std::string &reason) {}
void on_close(session_ptr client) {}
// both text and binary messages are echoed back to the sending client.
void on_message(session_ptr client,const std::string &msg);

View File

@@ -96,8 +96,8 @@ void server_session::read_handshake() {
m_timer.async_wait(
boost::bind(
&session::handle_timer_expired,
this,
&session::handle_handshake_expired,
shared_from_this(),
boost::asio::placeholders::error
)
);
@@ -342,6 +342,9 @@ void server_session::handle_write_handshake(const boost::system::error_code& err
m_state = STATE_OPEN;
// stop the handshake timer
m_timer.cancel();
if (m_local_interface) {
m_local_interface->on_open(shared_from_this());
}

View File

@@ -103,6 +103,7 @@ protected:
std::size_t bytes_transferred);
private:
protected:

View File

@@ -329,7 +329,8 @@ void session::handle_read_frame(const boost::system::error_code& error) {
log_close_result();
if (m_local_interface) {
m_local_interface->on_close(shared_from_this(),m_remote_close_code,m_remote_close_msg);
// TODO: make sure close code/msg are properly set.
m_local_interface->on_close(shared_from_this());
}
} else {
log("handle_read_frame called in invalid state",LOG_ERROR);
@@ -407,6 +408,21 @@ void session::handle_timer_expired (const boost::system::error_code& error) {
}
void session::handle_handshake_expired (const boost::system::error_code& error) {
if (error) {
if (error == boost::asio::error::operation_aborted) {
log("timer was aborted",LOG_DEBUG);
//drop_tcp(false);
} else {
log("Unexpected handshake timer error.",LOG_DEBUG);
drop_tcp(false);
}
return;
}
log("Handshake timed out",LOG_DEBUG);
drop_tcp(false);
}
void session::process_ping() {
access_log("Ping",ALOG_MISC_CONTROL);

View File

@@ -205,6 +205,7 @@ protected:
void handle_write_frame (const boost::system::error_code& error);
void handle_timer_expired(const boost::system::error_code& error);
void handle_handshake_expired(const boost::system::error_code& error);
// helper functions for processing each opcode
void process_frame();