diff --git a/src/network/http/websocket.cpp b/src/network/http/websocket.cpp index 2d446e5..db5ae9b 100755 --- a/src/network/http/websocket.cpp +++ b/src/network/http/websocket.cpp @@ -434,8 +434,9 @@ namespace fc { namespace http { _client_thread.async( [&](){ if( _connection ) _connection->closed(); _connection.reset(); } ).wait(); if( _connected && !_connected->ready() ) _connected->set_exception( exception_ptr( new FC_EXCEPTION( exception, "${message}", ("message",message)) ) ); - if( _closed ) - _closed->set_value(); + //if( _closed && !_closed->ready() ) + // _closed->set_value(); + _failed = true; }); _client.init_asio( &fc::asio::default_io_service() ); @@ -447,11 +448,11 @@ namespace fc { namespace http { _connection->close(0, "client closed"); _connection.reset(); } - if( _closed ) + if( _closed && !_failed) _closed->wait(); } - + bool _failed = false; fc::promise::ptr _connected; fc::promise::ptr _closed; fc::thread& _client_thread; diff --git a/src/thread/future.cpp b/src/thread/future.cpp index 2111584..95485b9 100755 --- a/src/thread/future.cpp +++ b/src/thread/future.cpp @@ -27,6 +27,7 @@ namespace fc { } void promise_base::cancel(const char* reason /* = nullptr */){ + synchronized(_spin_yield) // wlog("${desc} canceled!", ("desc", _desc? _desc : "")); _canceled = true; #ifndef NDEBUG diff --git a/src/thread/thread_d.hpp b/src/thread/thread_d.hpp index 8e36b14..2a6c995 100755 --- a/src/thread/thread_d.hpp +++ b/src/thread/thread_d.hpp @@ -596,7 +596,12 @@ namespace fc { else if( timeout_time != time_point::min() ) { // 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 diff --git a/tests/crypto/blowfish_test.cpp b/tests/crypto/blowfish_test.cpp index ec4ada7..bb474dc 100755 --- a/tests/crypto/blowfish_test.cpp +++ b/tests/crypto/blowfish_test.cpp @@ -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) ) ); fc::blowfish fish; 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) ) ); fish.reset_chain(); 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.encrypt( out, sizeof(out), fc::blowfish::CBC ); BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) ); fish.reset_chain(); 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) ) ); 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 ) ); fish.reset_chain(); memset( out + 29, 0, 3 ); 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.encrypt( out, sizeof(out), fc::blowfish::CFB ); BOOST_CHECK( !memcmp( cipher, out, 29 ) ); fish.reset_chain(); memset( out + 29, 0, 3 ); 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() diff --git a/tests/real128_test.cpp b/tests/real128_test.cpp index beae9b7..3188741 100755 --- a/tests/real128_test.cpp +++ b/tests/real128_test.cpp @@ -47,9 +47,9 @@ BOOST_AUTO_TEST_CASE(real128_test) BOOST_CHECK_EQUAL( real128(uint64_t(-1)).to_uint64(), uint64_t(-1) ); - wdump( (ten)(two)(twenty) ); - wdump((real128("12345.6789")) ); - wdump( (ten/3*3) ); + //wdump( (ten)(two)(twenty) ); + //wdump((real128("12345.6789")) ); + //wdump( (ten/3*3) ); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/serialization_test.cpp b/tests/serialization_test.cpp index 1e35f86..2f3e873 100644 --- a/tests/serialization_test.cpp +++ b/tests/serialization_test.cpp @@ -51,12 +51,12 @@ BOOST_AUTO_TEST_CASE( nested_objects_test ) 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; for( uint32_t i = 1; i <= level; i++ ) { - if( i % 100 == 0 ) - ilog( "Creating level ${lv}", ("lv",i) ); + //if( i % 100 == 0 ) + // ilog( "Creating level ${lv}", ("lv",i) ); fc::test::item_wrapper wp( std::move(nested) ); nested = fc::test::item( std::move(wp), i ); } diff --git a/tests/thread/task_cancel.cpp b/tests/thread/task_cancel.cpp index 3435f39..cc26e4f 100755 --- a/tests/thread/task_cancel.cpp +++ b/tests/thread/task_cancel.cpp @@ -191,11 +191,8 @@ BOOST_AUTO_TEST_CASE( cleanup_cancelled_task ) { fc::usleep(fc::seconds(5)); BOOST_TEST_MESSAGE("Finsihed usleep in async task, leaving the task's functor"); - } - catch (...) - { - BOOST_TEST_MESSAGE("Caught exception in async task, leaving the task's functor"); - } + } FC_CAPTURE_AND_LOG( (some_string) ); + }, "test_task"); std::weak_ptr weak_string_ptr(some_string); some_string.reset();