diff options
author | Eric Lombrozo <elombrozo@gmail.com> | 2013-06-05 20:21:41 -0700 |
---|---|---|
committer | Eric Lombrozo <elombrozo@gmail.com> | 2013-06-05 23:15:20 -0700 |
commit | 501da2503a39dd88470df89ccc923c696fe6b111 (patch) | |
tree | 52bb9f3eb186bc99d1a8a96435fd78ac09532235 /src | |
parent | aabdf9e899e9024927c26c194ad38142495f80bf (diff) |
Using boost::signals2 to message main from net.cpp.
Diffstat (limited to 'src')
-rw-r--r-- | src/init.cpp | 6 | ||||
-rw-r--r-- | src/main.cpp | 15 | ||||
-rw-r--r-- | src/main.h | 5 | ||||
-rw-r--r-- | src/net.cpp | 30 | ||||
-rw-r--r-- | src/net.h | 18 |
5 files changed, 37 insertions, 37 deletions
diff --git a/src/init.cpp b/src/init.cpp index a1dbfd2a5f..f8b2b23fd0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -571,10 +571,8 @@ bool AppInit2(boost::thread_group& threadGroup) // ********************************************************* Step 6: network initialization - SetProcessMessagesHandler(ProcessMessages); - SetSendMessagesHandler(SendMessages); - SetStartShutdownHandler(StartShutdown); - + RegisterNodeSignals(GetNodeSignals()); + int nSocksVersion = GetArg("-socks", 5); if (nSocksVersion != 4 && nSocksVersion != 5) return InitError(strprintf(_("Unknown -socks proxy version requested: %i"), nSocksVersion)); diff --git a/src/main.cpp b/src/main.cpp index bd40476d4c..98921e1423 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -160,7 +160,22 @@ void static ResendWalletTransactions() +////////////////////////////////////////////////////////////////////////////// +// +// Registration of network node signals. +// + +void RegisterNodeSignals(CNodeSignals& nodeSignals) +{ + nodeSignals.ProcessMessages.connect(&ProcessMessages); + nodeSignals.SendMessages.connect(&SendMessages); +} +void UnregisterNodeSignals(CNodeSignals& nodeSignals) +{ + nodeSignals.ProcessMessages.disconnect(&ProcessMessages); + nodeSignals.SendMessages.disconnect(&SendMessages); +} diff --git a/src/main.h b/src/main.h index f4e80c85ce..f62cfbef6d 100644 --- a/src/main.h +++ b/src/main.h @@ -124,6 +124,11 @@ void UnregisterWallet(CWallet* pwalletIn); /** Push an updated transaction to all registered wallets */ void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false); +/** Register with a network node to receive its signals */ +void RegisterNodeSignals(CNodeSignals& nodeSignals); +/** Unregister a network node */ +void UnregisterNodeSignals(CNodeSignals& nodeSignals); + void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd); /** Process an incoming block */ diff --git a/src/net.cpp b/src/net.cpp index 5932f5f8e3..dc9a7e5371 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -68,27 +68,9 @@ CCriticalSection cs_vAddedNodes; static CSemaphore *semOutbound = NULL; -// -// Handlers that need to be registered -// -static ProcessMessagesHandler fnProcessMessages = NULL; -static SendMessagesHandler fnSendMessages = NULL; -static StartShutdownHandler fnStartShutdown = NULL; - -void SetProcessMessagesHandler(ProcessMessagesHandler handler) -{ - fnProcessMessages = handler; -} - -void SetSendMessagesHandler(SendMessagesHandler handler) -{ - fnSendMessages = handler; -} - -void SetStartShutdownHandler(StartShutdownHandler handler) -{ - fnStartShutdown = handler; -} +// Signals for message handling +static CNodeSignals g_signals; +CNodeSignals& GetNodeSignals() { return g_signals; } void AddOneShot(string strDest) { @@ -1646,7 +1628,7 @@ void ThreadMessageHandler() { TRY_LOCK(pnode->cs_vRecvMsg, lockRecv); if (lockRecv) - if (!ProcessMessages(pnode)) + if (!g_signals.ProcessMessages(pnode)) pnode->CloseSocketDisconnect(); } boost::this_thread::interruption_point(); @@ -1654,8 +1636,8 @@ void ThreadMessageHandler() // Send messages { TRY_LOCK(pnode->cs_vSend, lockSend); - if (lockSend && fnSendMessages) - fnSendMessages(pnode, pnode == pnodeTrickle); + if (lockSend) + g_signals.SendMessages(pnode, pnode == pnodeTrickle); } boost::this_thread::interruption_point(); } @@ -8,6 +8,7 @@ #include <deque> #include <boost/array.hpp> #include <boost/foreach.hpp> +#include <boost/signals2/signal.hpp> #include <openssl/rand.h> #ifndef WIN32 @@ -45,16 +46,15 @@ void StartNode(boost::thread_group& threadGroup); bool StopNode(); void SocketSendData(CNode *pnode); -// -// Handlers that require registration -// -typedef bool (*ProcessMessagesHandler)(CNode* pfrom); -typedef bool (*SendMessagesHandler)(CNode* pto, bool fSendTrickle); -typedef void (*StartShutdownHandler)(); +// Signals for message handling +struct CNodeSignals +{ + boost::signals2::signal<bool (CNode*)> ProcessMessages; + boost::signals2::signal<bool (CNode*, bool)> SendMessages; +}; + +CNodeSignals& GetNodeSignals(); -void SetProcessMessagesHandler(ProcessMessagesHandler handler); -void SetSendMessagesHandler(SendMessagesHandler handler); -void SetStartShutdownHandler(StartShutdownHandler handler); enum { |