summaryrefslogtreecommitdiff
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
parent38571167247be5cef4f869f1e6cdeb9a82724ca1 (diff)
downloadinfinitytier-a75a7547b4ea104208e222e521f44471ba7669e5.tar.gz
infinitytier-a75a7547b4ea104208e222e521f44471ba7669e5.zip
Deadlock fix...
-rw-r--r--testnet/SimNetSocketManager.cpp20
-rw-r--r--testnet/SimNetSocketManager.hpp6
2 files changed, 15 insertions, 11 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()
diff --git a/testnet/SimNetSocketManager.hpp b/testnet/SimNetSocketManager.hpp
index 69f49556..82092b78 100644
--- a/testnet/SimNetSocketManager.hpp
+++ b/testnet/SimNetSocketManager.hpp
@@ -30,7 +30,7 @@
#include <map>
#include <utility>
-#include <queue>
+#include <vector>
#include "../node/Constants.hpp"
#include "../node/SocketManager.hpp"
@@ -98,7 +98,7 @@ public:
{
{
Mutex::Lock _l(_inbox_m);
- _inbox.push(std::pair< InetAddress,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> >(from,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN>(data,len)));
+ _inbox.push_back(std::pair< InetAddress,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> >(from,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN>(data,len)));
}
_waitCond.signal();
}
@@ -116,7 +116,7 @@ private:
SharedPtr<Socket> _mySocket;
TransferStats _totals;
- std::queue< std::pair< InetAddress,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> > > _inbox;
+ std::vector< std::pair< InetAddress,Buffer<ZT_SOCKET_MAX_MESSAGE_LEN> > > _inbox;
Mutex _inbox_m;
std::map< InetAddress,TransferStats > _stats;