aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-06-09 20:25:34 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-06-09 20:25:39 +0200
commitdb6b1132f4c92e038a8a80e21dec9a67aecf6a49 (patch)
tree63ee23ba23fabc5c28a213bdba48613c3e645edc /src
parent3c16f782c36348fa3b817d0d0ba779e0d06b442b (diff)
Remove disconnected sockets
Diffstat (limited to 'src')
-rw-r--r--src/DirectConnection.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp
index ce63eaf..e6b5645 100644
--- a/src/DirectConnection.cpp
+++ b/src/DirectConnection.cpp
@@ -158,6 +158,25 @@ namespace sibs
return wasRemoved;
}
+ void DirectConnections::removeDisconnectedPeers()
+ {
+ peersMutex.lock();
+ for(std::unordered_map<int, std::shared_ptr<DirectConnectionPeer>>::iterator it = peers.begin(); it != peers.end(); )
+ {
+ UDTSTATUS peerSocketStatus = UDT::getsockstate(it->first);
+ if(peerSocketStatus == UDTSTATUS::BROKEN || peerSocketStatus == UDTSTATUS::CLOSING || peerSocketStatus == UDTSTATUS::CLOSED || peerSocketStatus == UDTSTATUS::NONEXIST)
+ {
+ int socket = it->first;
+ Log::debug("UDT: Connection was broken to socket %d (peer most likely disconnected), removing peer", socket);
+ it = peers.erase(it);
+ Log::debug("UDT: Removed peer socket %d", socket);
+ }
+ else
+ ++it;
+ }
+ peersMutex.unlock();
+ }
+
void DirectConnections::receiveData()
{
std::vector<char> data;
@@ -167,6 +186,7 @@ namespace sibs
std::set<UDTSOCKET> readfds;
while(alive)
{
+ removeDisconnectedPeers();
int numfsReady = UDT::epoll_wait(eid, &readfds, nullptr, 1000);
if(numfsReady == 0)
{