From 9519a9a4202cd5fcaaad6d4cf0bf6bad38a27369 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 5 Mar 2015 04:01:01 -0800 Subject: [PATCH] Add correct bool combiner for net signals --- src/net.h | 19 +++++++++++++++++-- src/test/main_tests.cpp | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/net.h b/src/net.h index d2b2d88ddb..e500536cb4 100644 --- a/src/net.h +++ b/src/net.h @@ -76,12 +76,27 @@ void SocketSendData(CNode *pnode); typedef int NodeId; +struct CombinerAll +{ + typedef bool result_type; + + template + bool operator()(I first, I last) const + { + while (first != last) { + if (!(*first)) return false; + ++first; + } + return true; + } +}; + // Signals for message handling struct CNodeSignals { boost::signals2::signal GetHeight; - boost::signals2::signal ProcessMessages; - boost::signals2::signal SendMessages; + boost::signals2::signal ProcessMessages; + boost::signals2::signal SendMessages; boost::signals2::signal InitializeNode; boost::signals2::signal FinalizeNode; }; diff --git a/src/test/main_tests.cpp b/src/test/main_tests.cpp index 2a72a220a4..5e968c26ff 100644 --- a/src/test/main_tests.cpp +++ b/src/test/main_tests.cpp @@ -21,4 +21,21 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) BOOST_CHECK(nSum == 2099999997690000ULL); } +bool ReturnFalse() { return false; } +bool ReturnTrue() { return true; } + +BOOST_AUTO_TEST_CASE(test_combiner_all) +{ + boost::signals2::signal Test; + BOOST_CHECK(Test()); + Test.connect(&ReturnFalse); + BOOST_CHECK(!Test()); + Test.connect(&ReturnTrue); + BOOST_CHECK(!Test()); + Test.disconnect(&ReturnFalse); + BOOST_CHECK(Test()); + Test.disconnect(&ReturnTrue); + BOOST_CHECK(Test()); +} + BOOST_AUTO_TEST_SUITE_END()