mirror of
https://github.com/skywind3000/kcp.git
synced 2026-08-19 14:13:28 +08:00
add necessary information to the callbacks
This commit is contained in:
18
ikcp.c
18
ikcp.c
@@ -272,6 +272,7 @@ ikcpcb* ikcp_create(IUINT32 conv, void *user)
|
||||
kcp->acklist = NULL;
|
||||
kcp->ackblock = 0;
|
||||
kcp->ackcount = 0;
|
||||
kcp->ackedlen = 0;
|
||||
kcp->rx_srtt = 0;
|
||||
kcp->rx_rttval = 0;
|
||||
kcp->rx_rto = IKCP_RTO_DEF;
|
||||
@@ -595,6 +596,7 @@ static void ikcp_parse_ack(ikcpcb *kcp, IUINT32 sn)
|
||||
IKCPSEG *seg = iqueue_entry(p, IKCPSEG, node);
|
||||
next = p->next;
|
||||
if (sn == seg->sn) {
|
||||
kcp->ackedlen += seg->len;
|
||||
if (kcp->ccops && kcp->ccops->on_pkt_acked) {
|
||||
pkt_rtt = -1;
|
||||
if (_itimediff(kcp->current, seg->ts) >= 0) {
|
||||
@@ -621,6 +623,7 @@ static void ikcp_parse_una(ikcpcb *kcp, IUINT32 una)
|
||||
IKCPSEG *seg = iqueue_entry(p, IKCPSEG, node);
|
||||
next = p->next;
|
||||
if (_itimediff(una, seg->sn) > 0) {
|
||||
kcp->ackedlen += seg->len;
|
||||
if (kcp->ccops && kcp->ccops->on_pkt_acked) {
|
||||
kcp->ccops->on_pkt_acked(kcp, seg->sn, seg->ts,
|
||||
seg->len, -1, seg->xmit);
|
||||
@@ -782,6 +785,8 @@ int ikcp_input(ikcpcb *kcp, const char *data, long size)
|
||||
IUINT32 maxack = 0, latest_ts = 0;
|
||||
int flag = 0;
|
||||
|
||||
kcp->ackedlen = 0;
|
||||
|
||||
if (ikcp_canlog(kcp, IKCP_LOG_INPUT)) {
|
||||
ikcp_log(kcp, IKCP_LOG_INPUT, "[RI] %d bytes", (int)size);
|
||||
}
|
||||
@@ -906,7 +911,8 @@ int ikcp_input(ikcpcb *kcp, const char *data, long size)
|
||||
acked_segs = kcp->snd_una - prev_una;
|
||||
prior_in_flight = prev_nsnd_buf;
|
||||
if (kcp->ccops && kcp->ccops->on_ack) {
|
||||
kcp->ccops->on_ack(kcp, acked_segs, prior_in_flight);
|
||||
kcp->ccops->on_ack(kcp, acked_segs, kcp->ackedlen,
|
||||
prior_in_flight);
|
||||
}
|
||||
else {
|
||||
if (kcp->cwnd < kcp->rmt_wnd) {
|
||||
@@ -1084,11 +1090,6 @@ void ikcp_flush(ikcpcb *kcp)
|
||||
newseg->rto = kcp->rx_rto;
|
||||
newseg->fastack = 0;
|
||||
newseg->xmit = 0;
|
||||
|
||||
if (kcp->ccops && kcp->ccops->on_pkt_sent) {
|
||||
kcp->ccops->on_pkt_sent(kcp, newseg->sn, current,
|
||||
newseg->len, kcp->nsnd_buf - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// check on_app_limited
|
||||
@@ -1148,6 +1149,11 @@ void ikcp_flush(ikcpcb *kcp)
|
||||
segment->wnd = seg.wnd;
|
||||
segment->una = kcp->rcv_nxt;
|
||||
|
||||
if (kcp->ccops && kcp->ccops->on_pkt_sent) {
|
||||
kcp->ccops->on_pkt_sent(kcp, segment->sn, current,
|
||||
segment->len, kcp->nsnd_buf, segment->xmit);
|
||||
}
|
||||
|
||||
size = (int)(ptr - buffer);
|
||||
need = IKCP_OVERHEAD + segment->len;
|
||||
|
||||
|
||||
6
ikcp.h
6
ikcp.h
@@ -298,7 +298,8 @@ struct IKCPOPS
|
||||
const char *name;
|
||||
int (*init)(ikcpcb *kcp);
|
||||
void (*release)(ikcpcb *kcp);
|
||||
void (*on_ack)(ikcpcb *kcp, IUINT32 acked_segs, IUINT32 prior_in_flight);
|
||||
void (*on_ack)(ikcpcb *kcp, IUINT32 acked_segs, IUINT32 acked_bytes,
|
||||
IUINT32 prior_in_flight);
|
||||
void (*on_fast_retransmit)(ikcpcb *kcp, IUINT32 fast_retrans,
|
||||
IUINT32 inflight, IUINT32 prior_cwnd);
|
||||
void (*on_timeout)(ikcpcb *kcp, IUINT32 prior_cwnd);
|
||||
@@ -306,7 +307,7 @@ struct IKCPOPS
|
||||
void (*on_app_limited)(ikcpcb *kcp, IUINT32 inflight);
|
||||
void (*on_rtt)(ikcpcb *kcp, IINT32 rtt);
|
||||
void (*on_pkt_sent)(ikcpcb *kcp, IUINT32 sn, IUINT32 ts,
|
||||
IUINT32 len, IUINT32 inflight);
|
||||
IUINT32 len, IUINT32 inflight, IUINT32 xmit);
|
||||
void (*on_pkt_acked)(ikcpcb *kcp, IUINT32 sn, IUINT32 ts,
|
||||
IUINT32 len, IINT32 rtt, IUINT32 xmit);
|
||||
IUINT32 (*get_info)(ikcpcb *kcp, void *buf, IUINT32 bufsize);
|
||||
@@ -337,6 +338,7 @@ struct IKCPCB
|
||||
IUINT32 *acklist;
|
||||
IUINT32 ackcount;
|
||||
IUINT32 ackblock;
|
||||
IUINT32 ackedlen;
|
||||
void *user;
|
||||
char *buffer;
|
||||
int fastresend;
|
||||
|
||||
Reference in New Issue
Block a user