diff --git a/websocketpp/connection.hpp b/websocketpp/connection.hpp index 6f517e5388..1d7db65d1b 100644 --- a/websocketpp/connection.hpp +++ b/websocketpp/connection.hpp @@ -46,6 +46,8 @@ typedef lib::function open_handler; typedef lib::function close_handler; typedef lib::function fail_handler; +typedef lib::function interrupt_handler; + typedef lib::function handshake_init_handler; typedef lib::function ping_handler; @@ -215,6 +217,10 @@ public: void set_open_handler(open_handler h) { m_open_handler = h; } + + void set_interrupt_handler(interrupt_handler h) { + m_interrupt_handler = h; + } /// Set new connection handler /** @@ -699,6 +705,7 @@ private: connection_hdl m_connection_hdl; handler_ptr m_handler; open_handler m_open_handler; + interrupt_handler m_interrupt_handler; /// External connection state /** diff --git a/websocketpp/endpoint.hpp b/websocketpp/endpoint.hpp index 24636004e7..401221edf3 100644 --- a/websocketpp/endpoint.hpp +++ b/websocketpp/endpoint.hpp @@ -101,30 +101,21 @@ public: void set_open_handler(open_handler h) { m_open_handler = h; } + void set_interrupt_handler(interrupt_handler h) { + m_interrupt_handler = h; + } void interrupt(connection_hdl hdl, lib::error_code & ec) { - - std::cout << "Interrupting connection " << &hdl << std::endl; - - /*lib::shared_ptr s(hdl->lock()); - - if (!s) { - std::cout << "bad weak pointer in interrupt" << std::endl; - return; - } - - connection_ptr con = lib::static_pointer_cast(hdl)->lock();*/ - connection_ptr con = lib::static_pointer_cast(hdl.lock()); + connection_ptr con = get_con_from_hdl(hdl); if (!con) { ec = error::make_error_code(error::bad_connection); return; } - std::cout << "CALL con->interrupt() HERE!!" << std::endl; - ec = con->interrupt(); + std::cout << "Interrupting connection " << con.get() << std::endl; - //ec = lib::error_code(); + ec = con->interrupt(); } void interrupt(connection_hdl hdl) { @@ -160,6 +151,7 @@ private: std::string m_user_agent; open_handler m_open_handler; + interrupt_handler m_interrupt_handler; // endpoint resources std::set m_connections; diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index 778f345086..70407ec1de 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -256,19 +256,21 @@ void connection::close(const close::status::value code, template lib::error_code connection::interrupt() { std::cout << "connection::interrupt" << std::endl; - /*return transport_type::inturrupt( + return transport_type::interrupt( lib::bind( - &type::handle_inturrupt, + &type::handle_interrupt, type::shared_from_this() ) - );*/ + ); return lib::error_code(); } template void connection::handle_interrupt() { - m_handler->on_interrupt(type::shared_from_this()); + if (m_interrupt_handler) { + m_interrupt_handler(m_connection_hdl); + } } diff --git a/websocketpp/impl/endpoint_impl.hpp b/websocketpp/impl/endpoint_impl.hpp index b0ab5e0e76..7af041b9c4 100644 --- a/websocketpp/impl/endpoint_impl.hpp +++ b/websocketpp/impl/endpoint_impl.hpp @@ -54,9 +54,14 @@ endpoint::create_connection() { // con->set_handle(w); - con->set_handler(m_default_handler); + + con->set_handler(m_default_handler); + + // Copy default handlers from the endpoint con->set_open_handler(m_open_handler); - con->set_termination_handler( + con->set_interrupt_handler(m_interrupt_handler); + + con->set_termination_handler( lib::bind( &type::remove_connection, this, diff --git a/websocketpp/transport/asio/connection.hpp b/websocketpp/transport/asio/connection.hpp index 84c72a154e..7c9b1f045d 100644 --- a/websocketpp/transport/asio/connection.hpp +++ b/websocketpp/transport/asio/connection.hpp @@ -237,7 +237,7 @@ protected: m_connection_hdl = hdl; } - lib::error_code inturrupt(inturrupt_handler handler) { + lib::error_code interrupt(inturrupt_handler handler) { // strand post handle_inturrupt /*m_strand->post(lib::bind( &type::handle_inturrupt, @@ -255,9 +255,9 @@ protected: return lib::error_code(); } - void handle_inturrupt(inturrupt_handler handler) { + /*void handle_inturrupt(inturrupt_handler handler) { handler(); - } + }*/ /// close and clean up the underlying socket void shutdown() {