diff --git a/srtcore/buffer_snd.cpp b/srtcore/buffer_snd.cpp index 26f885dd6..1fc90eb40 100644 --- a/srtcore/buffer_snd.cpp +++ b/srtcore/buffer_snd.cpp @@ -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; diff --git a/srtcore/buffer_snd.h b/srtcore/buffer_snd.h index 4440b9bfd..13446258b 100644 --- a/srtcore/buffer_snd.h +++ b/srtcore/buffer_snd.h @@ -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); diff --git a/srtcore/core.cpp b/srtcore/core.cpp index 0e3cce0ee..df30b7fc9 100644 --- a/srtcore/core.cpp +++ b/srtcore/core.cpp @@ -9784,7 +9784,15 @@ bool srt::CUDT::overrideSndSeqNo(int32_t seq) return false; } - // + int dbytes; + const int dpkts SRT_ATR_UNUSED = 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. @@ -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; } diff --git a/srtcore/group.cpp b/srtcore/group.cpp index f4dfba1ba..3986aa1d5 100644 --- a/srtcore/group.cpp +++ b/srtcore/group.cpp @@ -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; @@ -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 { @@ -3840,11 +3841,11 @@ 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 bool su SRT_ATR_UNUSED = core.overrideSndSeqNo(curseq); - HLOGC(gslog.Debug, - log << "sendBackupRexmit: OVERRIDING seq %" << old << " with %" << curseq - << (su ? " - succeeded" : " - FAILED!")); + const int32_t old SRT_ATR_UNUSED = core.schedSeqNo(); + const bool success SRT_ATR_UNUSED = core.overrideSndSeqNo(curseq); + LOGC(gslog.Debug, + log << core.CONID() << "sendBackupRexmit: OVERRIDING seq %" << old << " with %" << curseq + << (success ? " - succeeded" : " - FAILED!")); } } @@ -3852,8 +3853,8 @@ int CUDTGroup::sendBackupRexmit(CUDT& core, SRT_MSGCTRL& w_mc) 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 } @@ -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; }