From 7346e366f1928dd727ecbb53253454fdaecaebb7 Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Sat, 16 May 2026 01:21:36 +0800 Subject: [PATCH] simple pacing --- ikcp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ikcp.c b/ikcp.c index 2575239..1f32039 100644 --- a/ikcp.c +++ b/ikcp.c @@ -981,6 +981,7 @@ void ikcp_flush(ikcpcb *kcp) IUINT32 rtomin; IUINT32 prior_cwnd; IUINT32 eff_cwnd, cur_inflight; + IINT32 pacing_budget = -1; struct IQUEUEHEAD *p; int change = 0; int lost = 0; @@ -993,6 +994,10 @@ void ikcp_flush(ikcpcb *kcp) kcp->ccops->on_tick(kcp); } + if (kcp->ccops && kcp->ccops->pacing_rate) { + pacing_budget = (IINT32)kcp->ccops->pacing_rate(kcp); + } + prior_cwnd = kcp->cwnd; seg.conv = kcp->conv; @@ -1149,6 +1154,10 @@ void ikcp_flush(ikcpcb *kcp) segment->wnd = seg.wnd; segment->una = kcp->rcv_nxt; + if (pacing_budget >= 0 && pacing_budget < (IINT32)segment->len) { + break; + } + if (kcp->ccops && kcp->ccops->on_pkt_sent) { kcp->ccops->on_pkt_sent(kcp, segment->sn, current, segment->len, kcp->nsnd_buf, segment->xmit); @@ -1169,6 +1178,10 @@ void ikcp_flush(ikcpcb *kcp) ptr += segment->len; } + if (pacing_budget >= 0) { + pacing_budget -= (IINT32)segment->len; + } + if (segment->xmit >= kcp->dead_link) { kcp->state = (IUINT32)-1; }