diff --git a/ikcp.c b/ikcp.c index cb03857..4ec38b0 100644 --- a/ikcp.c +++ b/ikcp.c @@ -865,7 +865,7 @@ void ikcp_flush(ikcpcb *kcp) count = kcp->ackcount; for (i = 0; i < count; i++) { size = (int)(ptr - buffer); - if (size > (int)kcp->mtu) { + if (size + IKCP_OVERHEAD > (int)kcp->mtu) { ikcp_output(kcp, buffer, size); ptr = buffer; } @@ -901,7 +901,7 @@ void ikcp_flush(ikcpcb *kcp) if (kcp->probe & IKCP_ASK_SEND) { seg.cmd = IKCP_CMD_WASK; size = (int)(ptr - buffer); - if (size > (int)kcp->mtu) { + if (size + IKCP_OVERHEAD > (int)kcp->mtu) { ikcp_output(kcp, buffer, size); ptr = buffer; } @@ -912,7 +912,7 @@ void ikcp_flush(ikcpcb *kcp) if (kcp->probe & IKCP_ASK_TELL) { seg.cmd = IKCP_CMD_WINS; size = (int)(ptr - buffer); - if (size > (int)kcp->mtu) { + if (size + IKCP_OVERHEAD > (int)kcp->mtu) { ikcp_output(kcp, buffer, size); ptr = buffer; } @@ -992,7 +992,7 @@ void ikcp_flush(ikcpcb *kcp) size = (int)(ptr - buffer); need = IKCP_OVERHEAD + segment->len; - if (size + need >= (int)kcp->mtu) { + if (size + need > (int)kcp->mtu) { ikcp_output(kcp, buffer, size); ptr = buffer; } diff --git a/ikcp.h b/ikcp.h index 280603a..5626693 100644 --- a/ikcp.h +++ b/ikcp.h @@ -12,7 +12,7 @@ #ifndef __IKCP_H__ #define __IKCP_H__ -#include +#include #include #include @@ -358,8 +358,11 @@ IUINT32 ikcp_check(const ikcpcb *kcp, IUINT32 current); // when you received a low level packet (eg. UDP packet), call it int ikcp_input(ikcpcb *kcp, const char *data, long size); + +// flush pending data void ikcp_flush(ikcpcb *kcp); +// check the size of next message in the recv queue int ikcp_peeksize(const ikcpcb *kcp); // change MTU size, default is 1400 @@ -383,6 +386,10 @@ int ikcp_sndbuf_count(const ikcpcb *kcp); void ikcp_log(ikcpcb *kcp, int mask, const char *fmt, ...); +// setup allocator +void ikcp_allocator(void* (*new_malloc)(size_t), void (*new_free)(void*)); + + #ifdef __cplusplus } #endif