Skip to content

Commit dbc0f0e

Browse files
leonyuliang
authored andcommitted
feat: auto-drop KCP packets on readbuf overflow
1 parent 1211bef commit dbc0f0e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

event/kcp/hkcp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ int hio_read_kcp (hio_t* io, void* buf, int readbytes) {
145145
while (1) {
146146
int nrecv = ikcp_recv(kcp->ikcp, kcp->readbuf.base, kcp->readbuf.len);
147147
// printf("ikcp_recv nrecv=%d\n", nrecv);
148+
if (nrecv == -3) { // drop packet when larger than readbuf.len
149+
int peeksize = ikcp_peeksize(kcp->ikcp);
150+
ikcp_recv(kcp->ikcp, NULL, peeksize);
151+
nrecv = 0;
152+
}
148153
if (nrecv < 0) break;
149154
hio_read_cb(io, kcp->readbuf.base, nrecv);
150155
ret += nrecv;

0 commit comments

Comments
 (0)