diff --git a/changelog.md b/changelog.md index 8dc43e2be8..83b03724f4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,5 @@ HEAD +- Add ping and pong endpoint wrapper methods - Add `get_request()` pass through method to connection to allow calling methods specific to the HTTP policy in use. - Fix issue compiling with `WEBSOCKETPP_STRICT_MASKING` diff --git a/websocketpp/endpoint.hpp b/websocketpp/endpoint.hpp index 522bbc4d70..4072b9a999 100644 --- a/websocketpp/endpoint.hpp +++ b/websocketpp/endpoint.hpp @@ -283,6 +283,48 @@ public: const std::string & reason, lib::error_code & ec); void close(connection_hdl hdl, const close::status::value code, const std::string & reason); + + /// Send a ping to a specific connection + /** + * @since 0.3.0-alpha3 + * + * @param [in] hdl The connection_hdl of the connection to send to. + * @param [in] payload The payload string to send. + * @param [out] ec A reference to an error code to fill in + */ + void ping(connection_hdl hdl, std::string const & payload, + lib::error_code & ec); + /// Send a ping to a specific connection + /** + * Exception variant of `ping` + * + * @since 0.3.0-alpha3 + * + * @param [in] hdl The connection_hdl of the connection to send to. + * @param [in] payload The payload string to send. + */ + void ping(connection_hdl hdl, std::string const & payload); + + /// Send a pong to a specific connection + /** + * @since 0.3.0-alpha3 + * + * @param [in] hdl The connection_hdl of the connection to send to. + * @param [in] payload The payload string to send. + * @param [out] ec A reference to an error code to fill in + */ + void pong(connection_hdl hdl, std::string const & payload, + lib::error_code & ec); + /// Send a pong to a specific connection + /** + * Exception variant of `pong` + * + * @since 0.3.0-alpha3 + * + * @param [in] hdl The connection_hdl of the connection to send to. + * @param [in] payload The payload string to send. + */ + void pong(connection_hdl hdl, std::string const & payload); /// Retrieves a connection_ptr from a connection_hdl (exception free) /** diff --git a/websocketpp/impl/endpoint_impl.hpp b/websocketpp/impl/endpoint_impl.hpp index 55a521713e..d4604fd8ce 100644 --- a/websocketpp/impl/endpoint_impl.hpp +++ b/websocketpp/impl/endpoint_impl.hpp @@ -180,6 +180,42 @@ void endpoint::close(connection_hdl hdl, if (ec) { throw ec; } } +template +void endpoint::ping(connection_hdl hdl, std::string const & + payload, lib::error_code & ec) +{ + connection_ptr con = get_con_from_hdl(hdl,ec); + if (ec) {return;} + con->ping(code,payload,ec); +} + +template +void endpoint::ping(connection_hdl hdl, std::string const & + payload) +{ + lib::error_code ec; + ping(hdl,code,payload,ec); + if (ec) { throw ec; } +} + +template +void endpoint::pong(connection_hdl hdl, std::string const & + payload, lib::error_code & ec) +{ + connection_ptr con = get_con_from_hdl(hdl,ec); + if (ec) {return;} + con->pong(code,payload,ec); +} + +template +void endpoint::pong(connection_hdl hdl, std::string const & + payload) +{ + lib::error_code ec; + pong(hdl,code,payload,ec); + if (ec) { throw ec; } +} + template void endpoint::remove_connection(connection_ptr con) { std::stringstream s;