Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions event/hloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ typedef struct kcp_setting_s {
int mtu;
// ikcp_update
int update_interval;
// bufsize for ikcp_recv
size_t rcv_bufsize;

#ifdef __cplusplus
kcp_setting_s() {
Expand All @@ -715,6 +717,7 @@ typedef struct kcp_setting_s {
rcvwnd = 0;
mtu = 1400;
update_interval = 10; // ms
rcv_bufsize = 0;
}
#endif
} kcp_setting_t;
Expand Down
6 changes: 5 additions & 1 deletion event/kcp/hkcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ kcp_t* hio_get_kcp(hio_t* io, uint32_t conv, struct sockaddr* addr) {
kcp->update_timer = htimer_add(io->loop, __kcp_update_timer_cb, update_interval, INFINITE);
kcp->update_timer->privdata = rudp;
}
// NOTE: alloc kcp->readbuf when hio_read_kcp
// NOTE: alloc kcp->readbuf now, otherwise hio_read_kcp will use default size (DEFAULT_KCP_READ_BUFSIZE)
if (setting->rcv_bufsize > 0) {
kcp->readbuf.len = setting->rcv_bufsize;
HV_ALLOC(kcp->readbuf.base, kcp->readbuf.len);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you shoud use hio_alloc_readbuf,and hio_free_readbuf is called when hio_done.

Copy link
Author

@Lion-Yu-Bro Lion-Yu-Bro Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you shoud use hio_alloc_readbuf,and hio_free_readbuf is called when hio_done.

HV_FREE already used in kcp_release(which will be called in hio_close -> hio_done ->rudp_cleanup->rudp_entry_free), so I called HV_ALLOC here

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've reviewed it again, and the readbuf here is kcp_s own readbuf, unrelated to hio_s, and can be allocated here.

}
return kcp;
}

Expand Down