summaryrefslogtreecommitdiff
path: root/testnet/SimNetSocketManager.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-10-24 17:11:23 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-10-24 17:11:23 -0700
commita75a7547b4ea104208e222e521f44471ba7669e5 (patch)
tree31e850417eddaca20b1e7eea2f18e87a5cdf03bc /testnet/SimNetSocketManager.cpp
parent38571167247be5cef4f869f1e6cdeb9a82724ca1 (diff)
downloadinfinitytier-a75a7547b4ea104208e222e521f44471ba7669e5.tar.gz
infinitytier-a75a7547b4ea104208e222e521f44471ba7669e5.zip
Deadlock fix...
Diffstat (limited to 'testnet/SimNetSocketManager.cpp')
-rw-r--r--testnet/SimNetSocketManager.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/testnet/SimNetSocketManager.cpp b/testnet/SimNetSocketManager.cpp
index c75c864f..a520f5ca 100644
--- a/testnet/SimNetSocketManager.cpp
+++ b/testnet/SimNetSocketManager.cpp
@@ -73,23 +73,27 @@ bool SimNetSocketManager::send(const InetAddress &to,bool tcp,bool autoConnectTc
void SimNetSocketManager::poll(unsigned long timeout,void (*handler)(const SharedPtr<Socket> &,void *,const InetAddress &,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> &),void *arg)
{
+ std::vector< std::pair< InetAddress,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> > > inb;
+
{
Mutex::Lock _l(_inbox_m);
- while (!_inbox.empty()) {
- handler(_mySocket,arg,_inbox.front().first,_inbox.front().second);
- _inbox.pop();
- }
+ inb = _inbox;
+ _inbox.clear();
}
+ for(std::vector< std::pair< InetAddress,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> > >::iterator i(inb.begin());i!=inb.end();++i)
+ handler(_mySocket,arg,i->first,i->second);
+
if (timeout)
_waitCond.wait(timeout);
else _waitCond.wait();
+
{
Mutex::Lock _l(_inbox_m);
- while (!_inbox.empty()) {
- handler(_mySocket,arg,_inbox.front().first,_inbox.front().second);
- _inbox.pop();
- }
+ inb = _inbox;
+ _inbox.clear();
}
+ for(std::vector< std::pair< InetAddress,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> > >::iterator i(inb.begin());i!=inb.end();++i)
+ handler(_mySocket,arg,i->first,i->second);
}
void SimNetSocketManager::whack()