diff --git a/websocketpp/endpoint.hpp b/websocketpp/endpoint.hpp index 000d44e6b8..e8fd056934 100644 --- a/websocketpp/endpoint.hpp +++ b/websocketpp/endpoint.hpp @@ -251,6 +251,14 @@ public: /* Connection pass through functions */ /*************************************/ + /** + * These functions act as adaptors to their counterparts in connection. They + * can produce one additional type of error, the bad_connection error, that + * indicates that the conversion from connection_hdl to connection_ptr + * failed due to the connection not existing anymore. Each method has a + * default and an exception free varient. + */ + void interrupt(connection_hdl hdl, lib::error_code & ec); void interrupt(connection_hdl hdl); @@ -266,6 +274,11 @@ public: void send(connection_hdl hdl, message_ptr msg, lib::error_code & ec); void send(connection_hdl hdl, message_ptr msg); + + void close(connection_hdl hdl, const close::status::value code, + const std::string & reason, lib::error_code & ec); + void close(connection_hdl hdl, const close::status::value code, + const std::string & reason); protected: // Import appropriate internal types from our policy classes typedef typename concurrency_type::scoped_lock_type scoped_lock_type; diff --git a/websocketpp/impl/endpoint_impl.hpp b/websocketpp/impl/endpoint_impl.hpp index eff4c91757..ceef6527a1 100644 --- a/websocketpp/impl/endpoint_impl.hpp +++ b/websocketpp/impl/endpoint_impl.hpp @@ -160,6 +160,26 @@ void endpoint::send(connection_hdl hdl, message_ptr msg) { if (ec) { throw ec; } } +template +void endpoint::close(connection_hdl hdl, + const close::status::value code, const std::string & reason, + lib::error_code & ec) +{ + connection_ptr con = get_con_from_hdl(hdl,ec); + if (ec) {return;} + + ec = con->close(code,reason); +} + +template +void endpoint::close(connection_hdl hdl, + const close::status::value code, const std::string & reason) +{ + lib::error_code ec; + send(hdl,code,reason,ec); + if (ec) { throw ec; } +} + template void endpoint::remove_connection(connection_ptr con) { std::stringstream s;