fixed: message size of ack/una/winprobe could exceed mtu by 24 bytes

This commit is contained in:
skywind3000 2015-02-21 02:33:46 +08:00
parent 4d9eb2785b
commit 695e44711f
2 changed files with 12 additions and 5 deletions

8
ikcp.c
View File

@ -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;
}

9
ikcp.h
View File

@ -12,7 +12,7 @@
#ifndef __IKCP_H__
#define __IKCP_H__
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <assert.h>
@ -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