From f5d4cbe1432b775e16703fe9d02211c03a5be49f Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sun, 6 Jan 2013 10:10:35 -0600 Subject: [PATCH] updates asio on_tcp_init callback to new api --- examples/echo_server/echo_server.cpp | 5 +++++ websocketpp/transport/asio/connection.hpp | 5 ++--- websocketpp/transport/asio/endpoint.hpp | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/echo_server/echo_server.cpp b/examples/echo_server/echo_server.cpp index 697d85fd1c..3bb900311d 100644 --- a/examples/echo_server/echo_server.cpp +++ b/examples/echo_server/echo_server.cpp @@ -85,6 +85,10 @@ void on_interrupt(server* s, websocketpp::connection_hdl hdl) { std::cout << "on_interrupt called with hdl: " << hdl.lock().get() << std::endl; } +void on_tcp_init(websocketpp::connection_hdl hdl) { + std::cout << "on_tcp_init called with hdl: " << hdl.lock().get() << std::endl; +} + using websocketpp::lib::placeholders::_1; using websocketpp::lib::bind; @@ -101,6 +105,7 @@ int main() { //echo_server.set_open_handler(websocketpp::lib::bind(&test_handler::on_open,t,websocketpp::lib::placeholders::_1)); echo_server.set_open_handler(bind(&on_open,&echo_server,::_1)); echo_server.set_interrupt_handler(bind(&on_interrupt,&echo_server,::_1)); + echo_server.set_tcp_init_handler(&on_tcp_init); // Listen echo_server.listen(9002); diff --git a/websocketpp/transport/asio/connection.hpp b/websocketpp/transport/asio/connection.hpp index 7c9b1f045d..2532363bf1 100644 --- a/websocketpp/transport/asio/connection.hpp +++ b/websocketpp/transport/asio/connection.hpp @@ -57,7 +57,6 @@ public: class handler_interface : public security_type::handler_interface { public: - virtual void on_tcp_init() {}; }; typedef lib::shared_ptr handler_ptr; @@ -120,8 +119,8 @@ protected: } void handle_init(init_handler callback, const lib::error_code& ec) { - if (!ec) { - m_handler->on_tcp_init(); + if (m_tcp_init_handler) { + m_tcp_init_handler(m_connection_hdl); } callback(ec); diff --git a/websocketpp/transport/asio/endpoint.hpp b/websocketpp/transport/asio/endpoint.hpp index 735c5a16cf..6b5efb7283 100644 --- a/websocketpp/transport/asio/endpoint.hpp +++ b/websocketpp/transport/asio/endpoint.hpp @@ -160,6 +160,9 @@ public: * @see WebSocket++ handler documentation for more information about * handlers. */ + void set_tcp_init_handler(tcp_init_handler h) { + m_tcp_init_handler = h; + } // listen manually void listen(const boost::asio::ip::tcp::endpoint& e) {