Skip to content

Commit 9519a9a

Browse files
committed
Add correct bool combiner for net signals
1 parent 84a05b8 commit 9519a9a

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
@@ -76,12 +76,27 @@ void SocketSendData(CNode *pnode);
7676

7777
typedef int NodeId;
7878

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

src/test/main_tests.cpp

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

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

0 commit comments

Comments
 (0)