Skip to content

Commit

Permalink
[core] Fixed packet drop when reading from members (#1784)
Browse files Browse the repository at this point in the history
TSBPD thread of a member socket might not yet trigger epoll read-ready
event, while it is potentially ready.
If another member signals read-readiness ahead of the current position
it will result in a packet drop by a group.
  • Loading branch information
maxsharabayko committed Feb 4, 2021
1 parent 44503cd commit 8845473
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions srtcore/group.cpp
Expand Up @@ -2078,21 +2078,27 @@ vector<CUDTSocket*> CUDTGroup::recv_WaitForReadReady(const vector<CUDTSocket*>&
// will be surely empty. This will be checked then same way as when
// reading from every socket resulted in error.
vector<CUDTSocket*> readReady;
readReady.reserve(sready.size());
for (CEPoll::fmap_t::const_iterator i = sready.begin(); i != sready.end(); ++i)
readReady.reserve(aliveMembers.size());
for (vector<CUDTSocket*>::const_iterator sockiter = aliveMembers.begin(); sockiter != aliveMembers.end(); ++sockiter)
{
if (i->second & SRT_EPOLL_ERR)
continue; // broken already
CUDTSocket* sock = *sockiter;
const CEPoll::fmap_t::const_iterator ready_iter = sready.find(sock->m_SocketID);
if (ready_iter != sready.end())
{
if (ready_iter->second & SRT_EPOLL_ERR)
continue; // broken already

if ((i->second & SRT_EPOLL_IN) == 0)
continue; // not ready for reading
if ((ready_iter->second & SRT_EPOLL_IN) == 0)
continue; // not ready for reading

// Check if this socket is in aheads
// If so, don't read from it, wait until the ahead is flushed.
SRTSOCKET id = i->first;
CUDTSocket* ps = m_pGlobal->locateSocket_LOCKED(id);
if (ps)
readReady.push_back(ps);
readReady.push_back(*sockiter);
}
else if (sock->core().m_pRcvBuffer->isRcvDataReady())
{
// No read-readiness reported by epoll, but probably missed or not yet handled
// as the receiver buffer is read-ready.
readReady.push_back(sock);
}
}

leaveCS(CUDT::s_UDTUnited.m_GlobControlLock);
Expand Down

0 comments on commit 8845473

Please sign in to comment.