From 0d9b127e3420ea1e7828f26fba3d54d23bec0b91 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 20 Jun 2020 13:01:22 -0400 Subject: [PATCH] Add missing functions to websocket_tls_server These functions were in websocket_server class but not in websocket_tls_server class: - get_listening_port - stop_listening - close --- include/fc/network/http/websocket.hpp | 9 +++++++++ src/network/http/websocket.cpp | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/fc/network/http/websocket.hpp b/include/fc/network/http/websocket.hpp index 5816a57..4894055 100644 --- a/include/fc/network/http/websocket.hpp +++ b/include/fc/network/http/websocket.hpp @@ -48,6 +48,8 @@ namespace fc { namespace http { typedef std::function on_connection_handler; + // TODO websocket_tls_server and websocket_server have almost the same interface and implementation, + // better refactor to remove duplicate code and to avoid undesired or unnecessary differences class websocket_server { public: @@ -69,6 +71,8 @@ namespace fc { namespace http { }; + // TODO websocket_tls_server and websocket_server have almost the same interface and implementation, + // better refactor to remove duplicate code and to avoid undesired or unnecessary differences class websocket_tls_server { public: @@ -80,7 +84,12 @@ namespace fc { namespace http { void on_connection( const on_connection_handler& handler); void listen( uint16_t port ); void listen( const fc::ip::endpoint& ep ); + uint16_t get_listening_port(); void start_accept(); + + void stop_listening(); + void close(); + private: friend class detail::websocket_tls_server_impl; std::unique_ptr my; diff --git a/src/network/http/websocket.cpp b/src/network/http/websocket.cpp index 66d0f4a..2819967 100644 --- a/src/network/http/websocket.cpp +++ b/src/network/http/websocket.cpp @@ -692,10 +692,28 @@ namespace fc { namespace http { boost::asio::ip::address_v4(uint32_t(ep.get_address())),ep.port()) ); } + uint16_t websocket_tls_server::get_listening_port() + { + websocketpp::lib::asio::error_code ec; + return my->_server.get_local_endpoint(ec).port(); + } + void websocket_tls_server::start_accept() { my->_server.start_accept(); } + void websocket_tls_server::stop_listening() + { + my->_server.stop_listening(); + } + + void websocket_tls_server::close() + { + websocketpp::lib::error_code ec; + for( auto& connection : my->_connections ) + my->_server.close( connection.first, websocketpp::close::status::normal, "Goodbye", ec ); + } + websocket_client::websocket_client( const std::string& ca_filename ) :my( new detail::websocket_client_impl() ),