Merge branch 'issue-13-fix-websocket' into 'latest-fc'
Issue-13-fix (websocket shutdown) See merge request PBSA/PeerplaysIO/tools-libs/peerplays-fc!17
This commit is contained in:
commit
8dd2fbe1b6
2 changed files with 27 additions and 19 deletions
|
|
@ -70,6 +70,9 @@ namespace fc { namespace http {
|
|||
void listen( uint16_t port );
|
||||
void listen( const fc::ip::endpoint& ep );
|
||||
void start_accept();
|
||||
uint16_t get_listening_port();
|
||||
void stop_listening();
|
||||
void close();
|
||||
|
||||
private:
|
||||
friend class detail::websocket_tls_server_impl;
|
||||
|
|
|
|||
|
|
@ -132,14 +132,10 @@ namespace fc { namespace http {
|
|||
typedef websocketpp::transport::asio::tls_socket::endpoint socket_type;
|
||||
};
|
||||
|
||||
typedef websocketpp::transport::asio::endpoint<transport_config>
|
||||
transport_type;
|
||||
typedef websocketpp::transport::asio::endpoint<transport_config> transport_type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
using websocketpp::connection_hdl;
|
||||
typedef websocketpp::server<asio_with_stub_log> websocket_server_type;
|
||||
typedef websocketpp::server<asio_tls_stub_log> websocket_tls_server_type;
|
||||
|
|
@ -399,17 +395,6 @@ namespace fc { namespace http {
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef websocketpp::client<asio_with_stub_log> websocket_client_type;
|
||||
typedef websocketpp::client<asio_tls_stub_log> websocket_tls_client_type;
|
||||
|
||||
|
|
@ -462,6 +447,8 @@ namespace fc { namespace http {
|
|||
_closed->wait();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fc::promise<void>::ptr _connected;
|
||||
fc::promise<void>::ptr _closed;
|
||||
fc::thread& _client_thread;
|
||||
|
|
@ -471,7 +458,6 @@ namespace fc { namespace http {
|
|||
};
|
||||
|
||||
|
||||
|
||||
class websocket_tls_client_impl
|
||||
{
|
||||
public:
|
||||
|
|
@ -646,6 +632,24 @@ namespace fc { namespace http {
|
|||
my->_server.start_accept();
|
||||
}
|
||||
|
||||
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::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_tls_client::websocket_tls_client( const std::string& ca_filename ):my( new detail::websocket_tls_client_impl( ca_filename ) ) {}
|
||||
websocket_tls_client::~websocket_tls_client(){ }
|
||||
|
|
@ -659,7 +663,7 @@ namespace fc { namespace http {
|
|||
{ try {
|
||||
if( uri.substr(0,4) == "wss:" )
|
||||
return secure_connect(uri);
|
||||
FC_ASSERT( uri.substr(0,3) == "ws:" );
|
||||
FC_ASSERT( uri.substr(0,4) == "wss:" || uri.substr(0,3) == "ws:", "Unsupported protocol" );
|
||||
|
||||
// wlog( "connecting to ${uri}", ("uri",uri));
|
||||
websocketpp::lib::error_code ec;
|
||||
|
|
@ -687,7 +691,8 @@ namespace fc { namespace http {
|
|||
{ try {
|
||||
if( uri.substr(0,3) == "ws:" )
|
||||
return connect(uri);
|
||||
FC_ASSERT( uri.substr(0,4) == "wss:" );
|
||||
FC_ASSERT( uri.substr(0,4) == "wss:" || uri.substr(0,3) == "ws:", "Unsupported protocol" );
|
||||
|
||||
// wlog( "connecting to ${uri}", ("uri",uri));
|
||||
websocketpp::lib::error_code ec;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue