Skip to content

Commit

Permalink
Merge pull request #5859
Browse files Browse the repository at this point in the history
9519a9a Add correct bool combiner for net signals (Pieter Wuille)
  • Loading branch information
laanwj committed Mar 12, 2015
2 parents 164d7b6 + 9519a9a commit dd4ffce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,27 @@ void SocketSendData(CNode *pnode);

typedef int NodeId;

struct CombinerAll
{
typedef bool result_type;

template<typename I>
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<int ()> GetHeight;
boost::signals2::signal<bool (CNode*)> ProcessMessages;
boost::signals2::signal<bool (CNode*, bool)> SendMessages;
boost::signals2::signal<bool (CNode*), CombinerAll> ProcessMessages;
boost::signals2::signal<bool (CNode*, bool), CombinerAll> SendMessages;
boost::signals2::signal<void (NodeId, const CNode*)> InitializeNode;
boost::signals2::signal<void (NodeId)> FinalizeNode;
};
Expand Down
17 changes: 17 additions & 0 deletions src/test/main_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,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<bool (), CombinerAll> 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()

0 comments on commit dd4ffce

Please sign in to comment.