FC Updates from BitShares and myself #21
2 changed files with 27 additions and 0 deletions
|
|
@ -48,6 +48,8 @@ namespace fc { namespace http {
|
|||
|
||||
typedef std::function<void(const websocket_connection_ptr&)> 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<detail::websocket_tls_server_impl> my;
|
||||
|
|
|
|||
|
|
@ -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() ),
|
||||
|
|
|
|||
Loading…
Reference in a new issue