From ed7f836f07d36f5b0d096b369e6c0c3604c9dbbe Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 29 Oct 2012 23:27:14 +0100 Subject: [PATCH] BUG/MINOR: stream_interface: don't loop over ->snd_buf() It is stupid to loop over ->snd_buf() because the snd_buf() itself already loops and stops when system buffers are full. But looping again onto it, we lose the information of the full buffers and perform one useless syscall. Furthermore, this causes issues when dealing with large uploads while waiting for a connection to establish, as it can report a server reject of some data as a connection abort, which is wrong. 1.4 does not have this issue as it loops maximum twice (once for each buffer half) and exists as soon as system buffers are full. So no backport is needed. --- include/common/defaults.h | 7 ------- src/stream_interface.c | 7 ++++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/include/common/defaults.h b/include/common/defaults.h index 3a67d3353f..ae49263a18 100644 --- a/include/common/defaults.h +++ b/include/common/defaults.h @@ -83,13 +83,6 @@ #define MIN_RECV_AT_ONCE_ENOUGH (7*1448) #endif -// same, but for writes. Generally, it's enough to write twice: one time for -// first half of the buffer, and a second time for the last half after a -// wrap-around. -#ifndef MAX_WRITE_POLL_LOOPS -#define MAX_WRITE_POLL_LOOPS 2 -#endif - // The minimum number of bytes to be forwarded that is worth trying to splice. // Below 4kB, it's not worth allocating pipes nor pretending to zero-copy. #ifndef MIN_SPLICE_FORWARD diff --git a/src/stream_interface.c b/src/stream_interface.c index cb3e7ea540..deb14b4cf8 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -671,7 +671,6 @@ static int si_conn_send_loop(struct connection *conn) { struct stream_interface *si = conn->owner; struct channel *chn = si->ob; - int write_poll = MAX_WRITE_POLL_LOOPS; int ret; if (chn->pipe && conn->xprt->snd_pipe) { @@ -728,8 +727,10 @@ static int si_conn_send_loop(struct connection *conn) break; } - if (--write_poll <= 0) - break; + /* if some data remain in the buffer, it's only because the + * system bufers are full, so we don't want to loop again. + */ + break; } /* while */ if (conn->flags & CO_FL_ERROR) -- 2.39.5