diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index 4edfcc1707..778f345086 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -256,14 +256,13 @@ 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::inturrupt( lib::bind( &type::handle_inturrupt, - type::shared_from_this(), - lib::placeholders::_1 + type::shared_from_this() ) - ); - //return lib::error_code(); + );*/ + return lib::error_code(); } diff --git a/websocketpp/roles/server_endpoint.hpp b/websocketpp/roles/server_endpoint.hpp index f0262b7c5b..5b08866ffc 100644 --- a/websocketpp/roles/server_endpoint.hpp +++ b/websocketpp/roles/server_endpoint.hpp @@ -72,7 +72,9 @@ public: typedef typename base::handler_ptr handler_ptr; typedef typename base::connection_ptr connection_ptr; - + typedef typename transport_type::con_policy trans_connection_type; + typedef typename transport_type::trans_connection_ptr trans_connection_ptr; + explicit server(typename base::handler_ptr default_handler) : base(default_handler,true) { @@ -92,20 +94,32 @@ public: void start_accept() { connection_ptr con = get_connection(); - transport_type::template async_accept( - con, + transport_type::async_accept( + lib::static_pointer_cast(con), lib::bind( &type::handle_accept, this, - lib::placeholders::_1 + lib::placeholders::_1, + lib::placeholders::_2 ) ); } - void handle_accept(const lib::error_code& ec) { - if (ec) { - std::cout << "handle_accept: error: " << ec << std::endl; - } + void handle_accept(connection_hdl hdl, const lib::error_code& ec) { + connection_ptr con = base::get_con_from_hdl(hdl); + + if (!con) { + // TODO: should this be considered a server fatal error? + std::cout << "handle_accept got an invalid handle back" << std::endl; + } else { + if (ec) { + con->terminate(); + + std::cout << "handle_accept: error: " << ec << std::endl; + } else { + con->start(); + } + } start_accept(); } diff --git a/websocketpp/transport/asio/endpoint.hpp b/websocketpp/transport/asio/endpoint.hpp index 53f038fd57..735c5a16cf 100644 --- a/websocketpp/transport/asio/endpoint.hpp +++ b/websocketpp/transport/asio/endpoint.hpp @@ -65,7 +65,9 @@ public: //typedef lib::shared_ptr io_service_ptr; typedef boost::asio::io_service* io_service_ptr; typedef lib::shared_ptr acceptor_ptr; - + + typedef typename con_policy::ptr trans_connection_ptr; + // generate and manage our own io_service explicit endpoint() : m_external_io_service(false) @@ -186,8 +188,7 @@ public: // Accept the next connection attempt via m_acceptor and assign it to con. // callback is called - template - void async_accept(connection_ptr con, accept_handler callback) { + void async_accept(trans_connection_ptr tcon, accept_handler callback) { if (m_state != LISTENING) { // TODO: throw invalid state std::cout << "asio::async_accept called from the wrong state" << std::endl; @@ -198,11 +199,11 @@ public: // TEMP m_acceptor->async_accept( - con->get_raw_socket(), + tcon->get_raw_socket(), lib::bind( - &type::handle_accept, + &type::handle_accept, this, - con, + tcon->get_handle(), callback, lib::placeholders::_1 ) @@ -251,16 +252,17 @@ public: listen(*endpoint_iterator); } protected: - template - void handle_accept(connection_ptr con, accept_handler callback, const boost::system::error_code& error) { + void handle_accept(connection_hdl hdl, accept_handler callback, + const boost::system::error_code& error) + { if (error) { - con->terminate(); + //con->terminate(); // TODO: Better translation of errors at this point - callback(make_error_code(error::pass_through)); + callback(hdl,make_error_code(error::pass_through)); } - con->start(); - callback(lib::error_code()); + //con->start(); + callback(hdl,lib::error_code()); } bool is_listening() const { diff --git a/websocketpp/transport/base/connection.hpp b/websocketpp/transport/base/connection.hpp index d0214a4b7e..ebcd010a18 100644 --- a/websocketpp/transport/base/connection.hpp +++ b/websocketpp/transport/base/connection.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace websocketpp { namespace transport { @@ -57,7 +58,7 @@ namespace transport { */ // Endpoint callbacks -typedef lib::function accept_handler; +typedef lib::function accept_handler; typedef lib::function endpoint_lock; diff --git a/websocketpp/transport/iostream/endpoint.hpp b/websocketpp/transport/iostream/endpoint.hpp index 56d29dde87..ca9804d4bf 100644 --- a/websocketpp/transport/iostream/endpoint.hpp +++ b/websocketpp/transport/iostream/endpoint.hpp @@ -40,7 +40,8 @@ template class endpoint { public: typedef iostream::connection con_policy; - + typedef typename con_policy::ptr trans_connection_ptr; + // generate and manage our own io_service explicit endpoint() {