From beb77d28bc26b60caeddfad734abe4c8de9ce115 Mon Sep 17 00:00:00 2001 From: Dengfeng Liu Date: Wed, 19 Apr 2017 11:22:11 +0800 Subject: [PATCH] Update xkcp_util.c --- xkcp_util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xkcp_util.c b/xkcp_util.c index 15928a4..bbf4cd5 100644 --- a/xkcp_util.c +++ b/xkcp_util.c @@ -169,6 +169,14 @@ void xkcp_set_config_param(ikcpcb *kcp) param->sndwnd, param->rcvwnd, param->nodelay, param->interval, param->resend, param->nc); } +static void set_tcp_no_delay(evutil_socket_t fd) +{ + int one = 1; + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, + &one, sizeof one); +} + + void xkcp_tcp_event_cb(struct bufferevent *bev, short what, struct xkcp_task *task) { if (what & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) { @@ -184,6 +192,8 @@ void xkcp_tcp_event_cb(struct bufferevent *bev, short what, struct xkcp_task *ta free(task); } bufferevent_free(bev); + } else if (what & BEV_EVENT_CONNECTED) { + set_tcp_no_delay(bufferevent_getfd(bev)); } }