From 32f52dabf99b3307903b25418ecb4c7f4c13c1d2 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Tue, 27 Dec 2016 15:02:02 +0800 Subject: [PATCH] Fix #1008 --- src/local.c | 10 +++++++--- src/redir.c | 10 +++++++--- src/server.c | 10 +++++++--- src/tunnel.c | 12 ++++++++---- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/local.c b/src/local.c index d1bb7337..c3423694 100644 --- a/src/local.c +++ b/src/local.c @@ -856,6 +856,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) ERROR("remote_recv_cb_send"); close_and_free_remote(EV_A_ remote); close_and_free_server(EV_A_ server); + return; } } else if (s < (int)(server->buf->len)) { server->buf->len -= s; @@ -865,9 +866,12 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) } // Disable TCP_NODELAY after the first response are sent - int opt = 0; - setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); - setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + if (!remote->recv_ctx->connected) { + int opt = 0; + setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + remote->recv_ctx->connected = 1; + } } static void diff --git a/src/redir.c b/src/redir.c index eb8cb989..9ec73e31 100644 --- a/src/redir.c +++ b/src/redir.c @@ -392,6 +392,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) ERROR("send"); close_and_free_remote(EV_A_ remote); close_and_free_server(EV_A_ server); + return; } } else if (s < server->buf->len) { server->buf->len -= s; @@ -401,9 +402,12 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) } // Disable TCP_NODELAY after the first response are sent - int opt = 0; - setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); - setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + if (!remote->recv_ctx->connected) { + int opt = 0; + setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + remote->recv_ctx->connected = 1; + } } static void diff --git a/src/server.c b/src/server.c index f9e8e84e..0773552e 100644 --- a/src/server.c +++ b/src/server.c @@ -1200,6 +1200,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) ERROR("remote_recv_send"); close_and_free_remote(EV_A_ remote); close_and_free_server(EV_A_ server); + return; } } else if (s < server->buf->len) { server->buf->len -= s; @@ -1209,9 +1210,12 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) } // Disable TCP_NODELAY after the first response are sent - int opt = 0; - setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); - setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + if (!remote->recv_ctx->connected) { + int opt = 0; + setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + remote->recv_ctx->connected = 1; + } } static void diff --git a/src/tunnel.c b/src/tunnel.c index 4fb07710..1c694ddd 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -350,6 +350,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) ERROR("send"); close_and_free_remote(EV_A_ remote); close_and_free_server(EV_A_ server); + return; } } else if (s < server->buf->len) { server->buf->len -= s; @@ -358,10 +359,13 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) ev_io_start(EV_A_ & server->send_ctx->io); } - // Disable TCP_NODELAY after the first response are sent - int opt = 0; - setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); - setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + if (!remote->recv_ctx->connected) { + // Disable TCP_NODELAY after the first response are sent + int opt = 0; + setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt)); + remote->recv_ctx->connected = 1; + } } static void