Skip to content

Commit 8b73dbc

Browse files
committed
[core] Fixed the RCV buff nonread position update
condition in case of dropping upto a sequence number.
1 parent 4c443d6 commit 8b73dbc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

srtcore/buffer_rcv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ int CRcvBuffer::dropUpTo(int32_t seqno)
239239

240240
// If the nonread position is now behind the starting position, set it to the starting position and update.
241241
// Preceding packets were likely missing, and the non read position can probably be moved further now.
242-
if (CSeqNo::seqcmp(m_iFirstNonreadPos, m_iStartPos) < 0)
242+
if (!isInRange(m_iStartPos, m_iMaxPosOff, m_szSize, m_iFirstNonreadPos))
243243
{
244244
m_iFirstNonreadPos = m_iStartPos;
245245
updateNonreadPos();

srtcore/buffer_rcv.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,15 @@ class CRcvBuffer
239239
inline int incPos(int pos, int inc = 1) const { return (pos + inc) % m_szSize; }
240240
inline int decPos(int pos) const { return (pos - 1) >= 0 ? (pos - 1) : int(m_szSize - 1); }
241241
inline int offPos(int pos1, int pos2) const { return (pos2 >= pos1) ? (pos2 - pos1) : int(m_szSize + pos2 - pos1); }
242+
243+
/// @brief Compares the two positions in the receiver buffer relative to the starting position.
244+
/// @param pos2 a position in the receiver buffer.
245+
/// @param pos1 a position in the receiver buffer.
246+
/// @return a positive value if pos2 is ahead of pos1; a negative value, if pos2 is behind pos1; otherwise returns 0.
242247
inline int cmpPos(int pos2, int pos1) const
243248
{
244-
// XXX maybe not the best implementation, but this keeps up to the rule
249+
// XXX maybe not the best implementation, but this keeps up to the rule.
250+
// Maybe use m_iMaxPosOff to ensure a position is not behind the m_iStartPos.
245251
const int off1 = pos1 >= m_iStartPos ? pos1 - m_iStartPos : pos1 + (int)m_szSize - m_iStartPos;
246252
const int off2 = pos2 >= m_iStartPos ? pos2 - m_iStartPos : pos2 + (int)m_szSize - m_iStartPos;
247253

0 commit comments

Comments
 (0)