FC Updates from BitShares and myself #21
3 changed files with 35 additions and 35 deletions
|
|
@ -28,6 +28,9 @@ namespace fc {
|
|||
/// whereas normally the last two arguments must be provided, this template allows them to be omitted.
|
||||
/// Note that this only applies to trailing optional arguments, i.e. given a callable taking
|
||||
/// (fc::optional<int>, int, fc::optional<int>), only the last argument can be omitted.
|
||||
///
|
||||
/// A discussion of how exactly this works is available here:
|
||||
/// https://github.com/bitshares/bitshares-fc/pull/126#issuecomment-490566060
|
||||
template<typename R, typename... Parameters>
|
||||
struct optionals_callable : public std::function<R(Parameters...)> {
|
||||
using std::function<R(Parameters...)>::operator();
|
||||
|
|
|
|||
|
|
@ -207,8 +207,6 @@ namespace fc { namespace http {
|
|||
_server_thread.async( [&](){
|
||||
auto new_con = std::make_shared<websocket_connection_impl<websocket_server_type::connection_ptr>>( _server.get_con_from_hdl(hdl) );
|
||||
_on_connection( _connections[hdl] = new_con );
|
||||
if ( !_closed || _closed->ready() )
|
||||
_closed = new fc::promise<void>();
|
||||
}).wait();
|
||||
});
|
||||
_server.set_message_handler( [&]( connection_hdl hdl, websocket_server_type::message_ptr msg ){
|
||||
|
|
@ -291,6 +289,9 @@ namespace fc { namespace http {
|
|||
if( _server.is_listening() )
|
||||
_server.stop_listening();
|
||||
|
||||
if ( _connections.size() )
|
||||
_closed = new fc::promise<void>();
|
||||
|
||||
auto cpy_con = _connections;
|
||||
for( auto item : cpy_con )
|
||||
_server.close( item.first, 0, "server exit" );
|
||||
|
|
|
|||
|
|
@ -77,24 +77,22 @@ BOOST_AUTO_TEST_CASE(login_test) {
|
|||
auto listen_port = server->get_listening_port();
|
||||
server->start_accept();
|
||||
|
||||
try {
|
||||
auto client = std::make_shared<fc::http::websocket_client>();
|
||||
auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) );
|
||||
server->stop_listening();
|
||||
auto apic = std::make_shared<websocket_api_connection>(con, MAX_DEPTH);
|
||||
auto remote_login_api = apic->get_remote_api<login_api>();
|
||||
auto remote_calc = remote_login_api->get_calc();
|
||||
bool remote_triggered = false;
|
||||
remote_calc->on_result( [&remote_triggered]( uint32_t r ) { remote_triggered = true; } );
|
||||
BOOST_CHECK_EQUAL(remote_calc->add( 4, 5 ), 9);
|
||||
BOOST_CHECK(remote_triggered);
|
||||
auto client = std::make_shared<fc::http::websocket_client>();
|
||||
auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) );
|
||||
server->stop_listening();
|
||||
auto apic = std::make_shared<websocket_api_connection>(con, MAX_DEPTH);
|
||||
auto remote_login_api = apic->get_remote_api<login_api>();
|
||||
auto remote_calc = remote_login_api->get_calc();
|
||||
bool remote_triggered = false;
|
||||
remote_calc->on_result( [&remote_triggered]( uint32_t r ) { remote_triggered = true; } );
|
||||
BOOST_CHECK_EQUAL(remote_calc->add( 4, 5 ), 9);
|
||||
BOOST_CHECK(remote_triggered);
|
||||
|
||||
client->synchronous_close();
|
||||
server->close();
|
||||
fc::usleep(fc::milliseconds(50));
|
||||
client.reset();
|
||||
server.reset();
|
||||
} FC_LOG_AND_RETHROW()
|
||||
client->synchronous_close();
|
||||
server->close();
|
||||
fc::usleep(fc::milliseconds(50));
|
||||
client.reset();
|
||||
server.reset();
|
||||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
|
|
@ -118,24 +116,22 @@ BOOST_AUTO_TEST_CASE(optionals_test) {
|
|||
auto listen_port = server->get_listening_port();
|
||||
server->start_accept();
|
||||
|
||||
try {
|
||||
auto client = std::make_shared<fc::http::websocket_client>();
|
||||
auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) );
|
||||
server->stop_listening();
|
||||
auto apic = std::make_shared<websocket_api_connection>(*con, MAX_DEPTH);
|
||||
auto remote_optionals = apic->get_remote_api<optionals_api>();
|
||||
auto client = std::make_shared<fc::http::websocket_client>();
|
||||
auto con = client->connect( "ws://localhost:" + std::to_string(listen_port) );
|
||||
server->stop_listening();
|
||||
auto apic = std::make_shared<websocket_api_connection>(*con, MAX_DEPTH);
|
||||
auto remote_optionals = apic->get_remote_api<optionals_api>();
|
||||
|
||||
BOOST_CHECK_EQUAL(remote_optionals->foo("a"), "[\"a\",null,null]");
|
||||
BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b"), "[\"a\",\"b\",null]");
|
||||
BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b", "c"), "[\"a\",\"b\",\"c\"]");
|
||||
BOOST_CHECK_EQUAL(remote_optionals->foo("a", {}, "c"), "[\"a\",null,\"c\"]");
|
||||
BOOST_CHECK_EQUAL(remote_optionals->foo("a"), "[\"a\",null,null]");
|
||||
BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b"), "[\"a\",\"b\",null]");
|
||||
BOOST_CHECK_EQUAL(remote_optionals->foo("a", "b", "c"), "[\"a\",\"b\",\"c\"]");
|
||||
BOOST_CHECK_EQUAL(remote_optionals->foo("a", {}, "c"), "[\"a\",null,\"c\"]");
|
||||
|
||||
client->synchronous_close();
|
||||
server->close();
|
||||
fc::usleep(fc::milliseconds(50));
|
||||
client.reset();
|
||||
server.reset();
|
||||
} FC_LOG_AND_RETHROW()
|
||||
client->synchronous_close();
|
||||
server->close();
|
||||
fc::usleep(fc::milliseconds(50));
|
||||
client.reset();
|
||||
server.reset();
|
||||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue