From fdbbf63f42c8bee7a5afc43e96271d573487dd76 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 9 Jun 2018 20:25:34 +0200 Subject: Remove disconnected sockets --- src/DirectConnection.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') 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>::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 data; @@ -167,6 +186,7 @@ namespace sibs std::set readfds; while(alive) { + removeDisconnectedPeers(); int numfsReady = UDT::epoll_wait(eid, &readfds, nullptr, 1000); if(numfsReady == 0) { -- cgit v1.2.3