mirror of
https://github.com/skywind3000/kcp.git
synced 2025-03-14 00:30:11 +08:00
fixed: message size of ack/una/winprobe could exceed mtu by 24 bytes
This commit is contained in:
parent
4d9eb2785b
commit
695e44711f
8
ikcp.c
8
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;
|
||||
}
|
||||
|
9
ikcp.h
9
ikcp.h
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user