fix cores: don't use promise in websocket when failure, use FC_CAPTURE_AND_LOG...
This commit is contained in:
parent
6171e973c7
commit
07eaa68334
7 changed files with 31 additions and 22 deletions
|
|
@ -434,8 +434,9 @@ namespace fc { namespace http {
|
||||||
_client_thread.async( [&](){ if( _connection ) _connection->closed(); _connection.reset(); } ).wait();
|
_client_thread.async( [&](){ if( _connection ) _connection->closed(); _connection.reset(); } ).wait();
|
||||||
if( _connected && !_connected->ready() )
|
if( _connected && !_connected->ready() )
|
||||||
_connected->set_exception( exception_ptr( new FC_EXCEPTION( exception, "${message}", ("message",message)) ) );
|
_connected->set_exception( exception_ptr( new FC_EXCEPTION( exception, "${message}", ("message",message)) ) );
|
||||||
if( _closed )
|
//if( _closed && !_closed->ready() )
|
||||||
_closed->set_value();
|
// _closed->set_value();
|
||||||
|
_failed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
_client.init_asio( &fc::asio::default_io_service() );
|
_client.init_asio( &fc::asio::default_io_service() );
|
||||||
|
|
@ -447,11 +448,11 @@ namespace fc { namespace http {
|
||||||
_connection->close(0, "client closed");
|
_connection->close(0, "client closed");
|
||||||
_connection.reset();
|
_connection.reset();
|
||||||
}
|
}
|
||||||
if( _closed )
|
if( _closed && !_failed)
|
||||||
_closed->wait();
|
_closed->wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _failed = false;
|
||||||
fc::promise<void>::ptr _connected;
|
fc::promise<void>::ptr _connected;
|
||||||
fc::promise<void>::ptr _closed;
|
fc::promise<void>::ptr _closed;
|
||||||
fc::thread& _client_thread;
|
fc::thread& _client_thread;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ namespace fc {
|
||||||
}
|
}
|
||||||
|
|
||||||
void promise_base::cancel(const char* reason /* = nullptr */){
|
void promise_base::cancel(const char* reason /* = nullptr */){
|
||||||
|
synchronized(_spin_yield)
|
||||||
// wlog("${desc} canceled!", ("desc", _desc? _desc : ""));
|
// wlog("${desc} canceled!", ("desc", _desc? _desc : ""));
|
||||||
_canceled = true;
|
_canceled = true;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
|
||||||
|
|
@ -596,7 +596,12 @@ namespace fc {
|
||||||
else if( timeout_time != time_point::min() )
|
else if( timeout_time != time_point::min() )
|
||||||
{
|
{
|
||||||
// there may be tasks that have been canceled we should filter them out now
|
// there may be tasks that have been canceled we should filter them out now
|
||||||
// rather than waiting...
|
// rather than waiting...
|
||||||
|
//
|
||||||
|
|
||||||
|
if (current->canceled){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This bit is kind of sloppy -- this wait was originally implemented as a wait
|
/* This bit is kind of sloppy -- this wait was originally implemented as a wait
|
||||||
|
|
|
||||||
|
|
@ -139,31 +139,36 @@ BOOST_AUTO_TEST_CASE(blowfish_chain_test)
|
||||||
BOOST_CHECK_EQUAL( 32, fc::from_hex( chain_test_cbc.c_str(), (char*) cipher, sizeof(cipher) ) );
|
BOOST_CHECK_EQUAL( 32, fc::from_hex( chain_test_cbc.c_str(), (char*) cipher, sizeof(cipher) ) );
|
||||||
fc::blowfish fish;
|
fc::blowfish fish;
|
||||||
fish.start( key, sizeof(key), fc::sblock( from_bytes( iv ), from_bytes( iv + 4 ) ) );
|
fish.start( key, sizeof(key), fc::sblock( from_bytes( iv ), from_bytes( iv + 4 ) ) );
|
||||||
fish.encrypt( (unsigned char*) chain_test_plain.c_str(), out, sizeof(out), fc::blowfish::CBC );
|
|
||||||
|
char buffer[32];
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
memcpy(buffer, chain_test_plain.c_str(), std::min(sizeof(buffer), chain_test_plain.size()));
|
||||||
|
|
||||||
|
fish.encrypt( (unsigned char*) buffer, out, sizeof(out), fc::blowfish::CBC );
|
||||||
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
|
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
|
||||||
fish.reset_chain();
|
fish.reset_chain();
|
||||||
fish.decrypt( out, sizeof(out), fc::blowfish::CBC );
|
fish.decrypt( out, sizeof(out), fc::blowfish::CBC );
|
||||||
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
|
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
|
||||||
fish.reset_chain();
|
fish.reset_chain();
|
||||||
fish.encrypt( out, sizeof(out), fc::blowfish::CBC );
|
fish.encrypt( out, sizeof(out), fc::blowfish::CBC );
|
||||||
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
|
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
|
||||||
fish.reset_chain();
|
fish.reset_chain();
|
||||||
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CBC );
|
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CBC );
|
||||||
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
|
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL( 29, fc::from_hex( chain_test_cfb.c_str(), (char*) cipher, sizeof(cipher) ) );
|
BOOST_CHECK_EQUAL( 29, fc::from_hex( chain_test_cfb.c_str(), (char*) cipher, sizeof(cipher) ) );
|
||||||
fish.reset_chain();
|
fish.reset_chain();
|
||||||
fish.encrypt( (unsigned char*) chain_test_plain.c_str(), out, sizeof(out), fc::blowfish::CFB );
|
fish.encrypt( (unsigned char*) buffer, out, sizeof(out), fc::blowfish::CFB );
|
||||||
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
|
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
|
||||||
fish.reset_chain(); memset( out + 29, 0, 3 );
|
fish.reset_chain(); memset( out + 29, 0, 3 );
|
||||||
fish.decrypt( out, sizeof(out), fc::blowfish::CFB );
|
fish.decrypt( out, sizeof(out), fc::blowfish::CFB );
|
||||||
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
|
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
|
||||||
fish.reset_chain(); memset( out + 29, 0, 3 );
|
fish.reset_chain(); memset( out + 29, 0, 3 );
|
||||||
fish.encrypt( out, sizeof(out), fc::blowfish::CFB );
|
fish.encrypt( out, sizeof(out), fc::blowfish::CFB );
|
||||||
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
|
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
|
||||||
fish.reset_chain(); memset( out + 29, 0, 3 );
|
fish.reset_chain(); memset( out + 29, 0, 3 );
|
||||||
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CFB );
|
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CFB );
|
||||||
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
|
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ BOOST_AUTO_TEST_CASE(real128_test)
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL( real128(uint64_t(-1)).to_uint64(), uint64_t(-1) );
|
BOOST_CHECK_EQUAL( real128(uint64_t(-1)).to_uint64(), uint64_t(-1) );
|
||||||
|
|
||||||
wdump( (ten)(two)(twenty) );
|
//wdump( (ten)(two)(twenty) );
|
||||||
wdump((real128("12345.6789")) );
|
//wdump((real128("12345.6789")) );
|
||||||
wdump( (ten/3*3) );
|
//wdump( (ten/3*3) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,12 @@ BOOST_AUTO_TEST_CASE( nested_objects_test )
|
||||||
|
|
||||||
auto create_nested_object = []( uint32_t level )
|
auto create_nested_object = []( uint32_t level )
|
||||||
{
|
{
|
||||||
ilog( "Creating nested object with ${lv} level(s)", ("lv",level) );
|
//ilog( "Creating nested object with ${lv} level(s)", ("lv",level) );
|
||||||
fc::test::item nested;
|
fc::test::item nested;
|
||||||
for( uint32_t i = 1; i <= level; i++ )
|
for( uint32_t i = 1; i <= level; i++ )
|
||||||
{
|
{
|
||||||
if( i % 100 == 0 )
|
//if( i % 100 == 0 )
|
||||||
ilog( "Creating level ${lv}", ("lv",i) );
|
// ilog( "Creating level ${lv}", ("lv",i) );
|
||||||
fc::test::item_wrapper wp( std::move(nested) );
|
fc::test::item_wrapper wp( std::move(nested) );
|
||||||
nested = fc::test::item( std::move(wp), i );
|
nested = fc::test::item( std::move(wp), i );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,11 +191,8 @@ BOOST_AUTO_TEST_CASE( cleanup_cancelled_task )
|
||||||
{
|
{
|
||||||
fc::usleep(fc::seconds(5));
|
fc::usleep(fc::seconds(5));
|
||||||
BOOST_TEST_MESSAGE("Finsihed usleep in async task, leaving the task's functor");
|
BOOST_TEST_MESSAGE("Finsihed usleep in async task, leaving the task's functor");
|
||||||
}
|
} FC_CAPTURE_AND_LOG( (some_string) );
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
BOOST_TEST_MESSAGE("Caught exception in async task, leaving the task's functor");
|
|
||||||
}
|
|
||||||
}, "test_task");
|
}, "test_task");
|
||||||
std::weak_ptr<std::string> weak_string_ptr(some_string);
|
std::weak_ptr<std::string> weak_string_ptr(some_string);
|
||||||
some_string.reset();
|
some_string.reset();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue