Skip to content

Commit

Permalink
[core] Fixed overrideSndSeqNo() not clear buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
gou4shi1 committed Jun 18, 2023
1 parent 3cefede commit 2a5bb72
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
12 changes: 12 additions & 0 deletions srtcore/buffer_snd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,18 @@ int CSndBuffer::dropLateData(int& w_bytes, int32_t& w_first_msgno, const steady_
return (dpkts);
}

int CSndBuffer::dropAll(int& w_bytes)
{
ScopedLock bufferguard(m_BufLock);
const int dpkts = m_iCount;
w_bytes = m_iBytesCount;
m_pFirstBlock = m_pCurrBlock = m_pLastBlock;
m_iCount = 0;
m_iBytesCount = 0;
updAvgBufSize(steady_clock::now());
return dpkts;
}

void CSndBuffer::increase()
{
int unitsize = m_pBuffer->m_iSize;
Expand Down
1 change: 1 addition & 0 deletions srtcore/buffer_snd.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class CSndBuffer

SRT_ATTR_EXCLUDES(m_BufLock)
int dropLateData(int& bytes, int32_t& w_first_msgno, const time_point& too_late_time);
int dropAll(int& bytes);

void updAvgBufSize(const time_point& time);
int getAvgBufSize(int& bytes, int& timespan);
Expand Down
16 changes: 12 additions & 4 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9784,7 +9784,15 @@ bool srt::CUDT::overrideSndSeqNo(int32_t seq)
return false;
}

//
int dbytes;
const int dpkts = m_pSndBuffer->dropAll((dbytes));

enterCS(m_StatsLock);
m_stats.sndr.dropped.count(dbytes);;
leaveCS(m_StatsLock);

m_pSndLossList->removeUpTo(CSeqNo::decseq(seq));

// The peer will have to do the same, as a reaction on perceived
// packet loss. When it recognizes that this initial screwing up
// has happened, it should simply ignore the loss and go on.
Expand All @@ -9796,9 +9804,9 @@ bool srt::CUDT::overrideSndSeqNo(int32_t seq)
// the latter is ahead with the number of packets already scheduled, but
// not yet sent.

HLOGC(gslog.Debug, log << CONID() << "overrideSndSeqNo: sched-seq=" << m_iSndNextSeqNo << " send-seq=" << m_iSndCurrSeqNo
<< " (unchanged)"
);
HLOGC(gslog.Debug,
log << CONID() << "overrideSndSeqNo: sched-seq=" << m_iSndNextSeqNo << " send-seq=" << m_iSndCurrSeqNo
<< " dropped-pkts=" << dpkts);
return true;
}

Expand Down
25 changes: 14 additions & 11 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3798,7 +3798,7 @@ int CUDTGroup::sendBackupRexmit(CUDT& core, SRT_MSGCTRL& w_mc)
// This should resend all packets
if (m_SenderBuffer.empty())
{
LOGC(gslog.Fatal, log << "IPE: sendBackupRexmit: sender buffer empty");
LOGC(gslog.Fatal, log << core.CONID() << "IPE: sendBackupRexmit: sender buffer empty");

// Although act as if it was successful, otherwise you'll get connection break
return 0;
Expand Down Expand Up @@ -3830,8 +3830,9 @@ int CUDTGroup::sendBackupRexmit(CUDT& core, SRT_MSGCTRL& w_mc)
// packets that are in the past towards the scheduling sequence.
skip_initial = -distance;
LOGC(gslog.Warn,
log << "sendBackupRexmit: OVERRIDE attempt. Link seqno %" << core.schedSeqNo() << ", trying to send from seqno %" << curseq
<< " - DENIED; skip " << skip_initial << " pkts, " << m_SenderBuffer.size() << " pkts in buffer");
log << core.CONID() << "sendBackupRexmit: OVERRIDE attempt. Link seqno %" << core.schedSeqNo()
<< ", trying to send from seqno %" << curseq << " - DENIED; skip " << skip_initial << " pkts, "
<< m_SenderBuffer.size() << " pkts in buffer");
}
else
{
Expand All @@ -3840,20 +3841,20 @@ int CUDTGroup::sendBackupRexmit(CUDT& core, SRT_MSGCTRL& w_mc)
// sequence with it first so that they go hand-in-hand with
// sequences already used by the link from which packets were
// copied to the backup buffer.
IF_HEAVY_LOGGING(int32_t old = core.schedSeqNo());
const int32_t old = core.schedSeqNo();
const bool su SRT_ATR_UNUSED = core.overrideSndSeqNo(curseq);
HLOGC(gslog.Debug,
log << "sendBackupRexmit: OVERRIDING seq %" << old << " with %" << curseq
<< (su ? " - succeeded" : " - FAILED!"));
LOGC(gslog.Debug,
log << core.CONID() << "sendBackupRexmit: OVERRIDING seq %" << old << " with %" << curseq
<< (su ? " - succeeded" : " - FAILED!"));
}
}


if (skip_initial >= m_SenderBuffer.size())
{
LOGC(gslog.Warn,
log << "sendBackupRexmit: All packets were skipped. Nothing to send %" << core.schedSeqNo() << ", trying to send from seqno %" << curseq
<< " - DENIED; skip " << skip_initial << " packets");
log << core.CONID() << "sendBackupRexmit: All packets were skipped. Nothing to send %" << core.schedSeqNo()
<< ", trying to send from seqno %" << curseq << " - DENIED; skip " << skip_initial << " packets");
return 0; // can't return any other state, nothing was sent
}

Expand All @@ -3869,14 +3870,16 @@ int CUDTGroup::sendBackupRexmit(CUDT& core, SRT_MSGCTRL& w_mc)
{
// Stop sending if one sending ended up with error
LOGC(gslog.Warn,
log << "sendBackupRexmit: sending from buffer stopped at %" << core.schedSeqNo() << " and FAILED");
log << core.CONID() << "sendBackupRexmit: sending from buffer stopped at %" << core.schedSeqNo()
<< " and FAILED");
return -1;
}
}

// Copy the contents of the last item being updated.
w_mc = m_SenderBuffer.back().mc;
HLOGC(gslog.Debug, log << "sendBackupRexmit: pre-sent collected %" << curseq << " - %" << w_mc.pktseq);
HLOGC(gslog.Debug,
log << core.CONID() << "sendBackupRexmit: pre-sent collected %" << curseq << " - %" << w_mc.pktseq);
return stat;
}

Expand Down

0 comments on commit 2a5bb72

Please sign in to comment.