From af78d0fdb614b3fcc811433a25555e1a5f084543 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 8 Jan 2009 10:09:08 +0100 Subject: [PATCH] [OPTIM] stream_sock: do not ask for polling on EAGAIN if we have read It is not always wise to return 0 in stream_sock_read() upon EAGAIN, because if we have read enough data, we should consider that enough and try again later without polling in between. We still make a difference between small reads and large reads though. Small reads still lead to polling because we're sure that there's nothing left in the system's buffers if we read less than one MSS. --- src/stream_sock.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/stream_sock.c b/src/stream_sock.c index ca2fdee73..dbb60e7d1 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -229,10 +229,13 @@ int stream_sock_read(int fd) { } else if (errno == EAGAIN) { /* Ignore EAGAIN but inform the poller that there is - * nothing to read left. But we may have done some work - * justifying to notify the task. + * nothing to read left if we did not read much, ie + * less than what we were still expecting to read. + * But we may have done some work justifying to notify + * the task. */ - retval = 0; + if (cur_read < MIN_RET_FOR_READ_LOOP) + retval = 0; break; } else {