From d353c1afc2154198ae9e4306c2930b54a67f6a49 Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Mon, 29 Dec 2014 00:43:25 +0800 Subject: [PATCH] new comment --- ikcp.c | 6 +++--- ikcp.h | 17 +++++++++++++++-- test.cpp | 4 ++-- test.h | 1 + 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ikcp.c b/ikcp.c index 33eb18d..37ae851 100644 --- a/ikcp.c +++ b/ikcp.c @@ -340,7 +340,7 @@ void ikcp_release(ikcpcb *kcp) //--------------------------------------------------------------------- -// recv data +// user/upper level recv: returns size, returns below zero for EAGAIN //--------------------------------------------------------------------- int ikcp_recv(ikcpcb *kcp, char *buffer, int len) { @@ -423,7 +423,7 @@ int ikcp_recv(ikcpcb *kcp, char *buffer, int len) //--------------------------------------------------------------------- -// send data +// peek data size //--------------------------------------------------------------------- int ikcp_peeksize(const ikcpcb *kcp) { @@ -451,7 +451,7 @@ int ikcp_peeksize(const ikcpcb *kcp) //--------------------------------------------------------------------- -// send data +// user/upper level send, returns below zero for error //--------------------------------------------------------------------- int ikcp_send(ikcpcb *kcp, const char *buffer, int len) { diff --git a/ikcp.h b/ikcp.h index 54d395c..3f0f77a 100644 --- a/ikcp.h +++ b/ikcp.h @@ -335,12 +335,25 @@ ikcpcb* ikcp_create(IUINT32 conv, void *user); // release kcp control object void ikcp_release(ikcpcb *kcp); +// user/upper level recv: returns size, returns below zero for EAGAIN int ikcp_recv(ikcpcb *kcp, char *buffer, int len); + +// user/upper level send, returns below zero for error int ikcp_send(ikcpcb *kcp, const char *buffer, int len); -// update state (call it repeatedly, every 10ms-100ms) +// update state (call it repeatedly, every 10ms-100ms), or you can ask +// ikcp_check when to call it again (without low level packet input). // 'current' - current timestamp in millisec void ikcp_update(ikcpcb *kcp, IUINT32 current); + +// Determine when should you invoke ikcp_update: +// if there is no incoming low level packet, you can invoke ikcp_update +// after millisecs ikcp_check returns, instead of call update repeatly. +// It is important to reduce unnacessary ikcp_update calling. you can +// just call ikcp_update in a very small interval, or you can use it to +// schedule ikcp_update invoking (eg. when you are implementing an epoll +// like mechanism, or optimize ikcp_update when handling massive kcp +// connections) IUINT32 ikcp_check(const ikcpcb *kcp, IUINT32 current); // when you received a low level packet (eg. UDP packet), call it @@ -349,7 +362,7 @@ void ikcp_flush(ikcpcb *kcp); int ikcp_peeksize(const ikcpcb *kcp); -// change MTU size, default is 14000 +// change MTU size, default is 1400 int ikcp_setmtu(ikcpcb *kcp, int mtu); // set maximum window size: sndwnd=32, rcvwnd=32 by default diff --git a/test.cpp b/test.cpp index 34f009d..4736055 100644 --- a/test.cpp +++ b/test.cpp @@ -137,7 +137,7 @@ void test(int mode) next++; sumrtt += rtt; count++; - if (rtt > maxrtt) maxrtt = rtt; + if (rtt > (IUINT32)maxrtt) maxrtt = rtt; printf("[RECV] mode=%d sn=%d rtt=%d\n", mode, (int)sn, (int)rtt); } @@ -150,7 +150,7 @@ void test(int mode) ikcp_release(kcp2); const char *names[3] = { "default", "normal", "fast" }; - printf("%s mode result (%dms):\n", names[mode], ts1); + printf("%s mode result (%dms):\n", names[mode], (int)ts1); printf("avgrtt=%d maxrtt=%d\n", (int)(sumrtt / count), maxrtt); printf("press enter to next ...\n"); char ch; scanf("%c", &ch); diff --git a/test.h b/test.h index 1c40a9b..7db5f98 100644 --- a/test.h +++ b/test.h @@ -218,6 +218,7 @@ public: } maxsize = pkt->size(); memcpy(data, pkt->ptr(), maxsize); + delete pkt; return maxsize; }