From c5a17fb8b5ea9cd51e0f22b92a96d8884c79d834 Mon Sep 17 00:00:00 2001 From: Chinsyo Date: Thu, 5 Nov 2020 19:12:51 +0800 Subject: [PATCH 1/2] Cleanup --- ikcp.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ikcp.c b/ikcp.c index fd4cf7d8..2626888a 100644 --- a/ikcp.c +++ b/ikcp.c @@ -35,8 +35,8 @@ const IUINT32 IKCP_ASK_TELL = 2; // need to send IKCP_CMD_WINS const IUINT32 IKCP_WND_SND = 32; const IUINT32 IKCP_WND_RCV = 128; // must >= max fragment size const IUINT32 IKCP_MTU_DEF = 1400; -const IUINT32 IKCP_ACK_FAST = 3; -const IUINT32 IKCP_INTERVAL = 100; +const IUINT32 IKCP_ACK_FAST = 3; +const IUINT32 IKCP_INTERVAL = 100; const IUINT32 IKCP_OVERHEAD = 24; const IUINT32 IKCP_DEADLINK = 20; const IUINT32 IKCP_THRESH_INIT = 2; @@ -296,7 +296,7 @@ ikcpcb* ikcp_create(IUINT32 conv, void *user) //--------------------------------------------------------------------- -// release a new kcpcb +// release a kcpcb //--------------------------------------------------------------------- void ikcp_release(ikcpcb *kcp) { @@ -718,7 +718,7 @@ void ikcp_parse_data(ikcpcb *kcp, IKCPSEG *newseg) #endif // move available data from rcv_buf -> rcv_queue - while (! iqueue_is_empty(&kcp->rcv_buf)) { + while (!iqueue_is_empty(&kcp->rcv_buf)) { IKCPSEG *seg = iqueue_entry(kcp->rcv_buf.next, IKCPSEG, node); if (seg->sn == kcp->rcv_nxt && kcp->nrcv_que < kcp->rcv_wnd) { iqueue_del(&seg->node); @@ -1175,7 +1175,7 @@ void ikcp_update(ikcpcb *kcp, IUINT32 current) // Determine when should you invoke ikcp_update: // returns when you should invoke ikcp_update in millisec, if there // is no ikcp_input/_send calling. you can call ikcp_update in that -// time, instead of call update repeatly. +// time, instead of call update repeatedly. // Important to reduce unnacessary ikcp_update invoking. use it to // schedule ikcp_update (eg. implementing an epoll-like mechanism, // or optimize ikcp_update when handling massive kcp connections) @@ -1218,8 +1218,6 @@ IUINT32 ikcp_check(const ikcpcb *kcp, IUINT32 current) return current + minimal; } - - int ikcp_setmtu(ikcpcb *kcp, int mtu) { char *buffer; @@ -1268,7 +1266,6 @@ int ikcp_nodelay(ikcpcb *kcp, int nodelay, int interval, int resend, int nc) return 0; } - int ikcp_wndsize(ikcpcb *kcp, int sndwnd, int rcvwnd) { if (kcp) { From db53bfba08c2d38d47fc6ff2f5c6c866d6367c5e Mon Sep 17 00:00:00 2001 From: Chinsyo Date: Thu, 5 Nov 2020 19:14:03 +0800 Subject: [PATCH 2/2] Move code to match the comments --- ikcp.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/ikcp.c b/ikcp.c index 2626888a..a38c6c1e 100644 --- a/ikcp.c +++ b/ikcp.c @@ -540,6 +540,28 @@ int ikcp_send(ikcpcb *kcp, const char *buffer, int len) //--------------------------------------------------------------------- // parse ack //--------------------------------------------------------------------- +static void ikcp_parse_ack(ikcpcb *kcp, IUINT32 sn) +{ + struct IQUEUEHEAD *p, *next; + + if (_itimediff(sn, kcp->snd_una) < 0 || _itimediff(sn, kcp->snd_nxt) >= 0) + return; + + for (p = kcp->snd_buf.next; p != &kcp->snd_buf; p = next) { + IKCPSEG *seg = iqueue_entry(p, IKCPSEG, node); + next = p->next; + if (sn == seg->sn) { + iqueue_del(p); + ikcp_segment_delete(kcp, seg); + kcp->nsnd_buf--; + break; + } + if (_itimediff(sn, seg->sn) < 0) { + break; + } + } +} + static void ikcp_update_ack(ikcpcb *kcp, IINT32 rtt) { IINT32 rto = 0; @@ -568,28 +590,6 @@ static void ikcp_shrink_buf(ikcpcb *kcp) } } -static void ikcp_parse_ack(ikcpcb *kcp, IUINT32 sn) -{ - struct IQUEUEHEAD *p, *next; - - if (_itimediff(sn, kcp->snd_una) < 0 || _itimediff(sn, kcp->snd_nxt) >= 0) - return; - - for (p = kcp->snd_buf.next; p != &kcp->snd_buf; p = next) { - IKCPSEG *seg = iqueue_entry(p, IKCPSEG, node); - next = p->next; - if (sn == seg->sn) { - iqueue_del(p); - ikcp_segment_delete(kcp, seg); - kcp->nsnd_buf--; - break; - } - if (_itimediff(sn, seg->sn) < 0) { - break; - } - } -} - static void ikcp_parse_una(ikcpcb *kcp, IUINT32 una) { struct IQUEUEHEAD *p, *next;