Skip to content

Commit dd4ffce

Browse files
committed
Merge pull request #5859
9519a9a Add correct bool combiner for net signals (Pieter Wuille)
2 parents 164d7b6 + 9519a9a commit dd4ffce

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/net.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,27 @@ void SocketSendData(CNode *pnode);
7878

7979
typedef int NodeId;
8080

81+
struct CombinerAll
82+
{
83+
typedef bool result_type;
84+
85+
template<typename I>
86+
bool operator()(I first, I last) const
87+
{
88+
while (first != last) {
89+
if (!(*first)) return false;
90+
++first;
91+
}
92+
return true;
93+
}
94+
};
95+
8196
// Signals for message handling
8297
struct CNodeSignals
8398
{
8499
boost::signals2::signal<int ()> GetHeight;
85-
boost::signals2::signal<bool (CNode*)> ProcessMessages;
86-
boost::signals2::signal<bool (CNode*, bool)> SendMessages;
100+
boost::signals2::signal<bool (CNode*), CombinerAll> ProcessMessages;
101+
boost::signals2::signal<bool (CNode*, bool), CombinerAll> SendMessages;
87102
boost::signals2::signal<void (NodeId, const CNode*)> InitializeNode;
88103
boost::signals2::signal<void (NodeId)> FinalizeNode;
89104
};

src/test/main_tests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,21 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test)
2323
BOOST_CHECK(nSum == 2099999997690000ULL);
2424
}
2525

26+
bool ReturnFalse() { return false; }
27+
bool ReturnTrue() { return true; }
28+
29+
BOOST_AUTO_TEST_CASE(test_combiner_all)
30+
{
31+
boost::signals2::signal<bool (), CombinerAll> Test;
32+
BOOST_CHECK(Test());
33+
Test.connect(&ReturnFalse);
34+
BOOST_CHECK(!Test());
35+
Test.connect(&ReturnTrue);
36+
BOOST_CHECK(!Test());
37+
Test.disconnect(&ReturnFalse);
38+
BOOST_CHECK(Test());
39+
Test.disconnect(&ReturnTrue);
40+
BOOST_CHECK(Test());
41+
}
42+
2643
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)