From: Willy Tarreau Date: Fri, 9 Jan 2009 12:05:19 +0000 (+0100) Subject: [CLEANUP] stream_sock: move the write-nothing condition out of the loop X-Git-Tag: v1.3.16-rc1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac128fef7379cd53fdda9e80f94911fd873d2a08;p=thirdparty%2Fhaproxy.git [CLEANUP] stream_sock: move the write-nothing condition out of the loop Some tricks to handle situations where we write nothing were in the middle of the main loop in stream_sock_write(). This cleanup provides better source and object code, and slightly shrinks the output code. --- diff --git a/src/stream_sock.c b/src/stream_sock.c index 3d0845ca42..e006797d5b 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -361,7 +361,7 @@ int stream_sock_write(int fd) { * so we cannot write anything from the buffer. Let's disable * the write event and pretend we never came there. */ - goto write_nothing; + goto out_stop_write; } #ifndef MSG_NOSIGNAL @@ -398,25 +398,7 @@ int stream_sock_write(int fd) { if (!b->l && !b->splice_len) { b->flags |= BF_EMPTY; - - write_nothing: - /* Maybe we just wrote the last chunk and need to close ? */ - if ((b->flags & (BF_SHUTW|BF_EMPTY|BF_HIJACK|BF_WRITE_ENA|BF_SHUTR)) == (BF_EMPTY|BF_WRITE_ENA|BF_SHUTR)) { - if (si->state == SI_ST_EST) { - stream_sock_shutw(si); - b->wex = TICK_ETERNITY; - goto out_wakeup; - } - } - - /* we may either get there when the buffer is empty or when - * we refrain from sending due to send_max reached. - */ - if (!b->l && !b->splice_len) - si->flags |= SI_FL_WAIT_DATA; - EV_FD_CLR(fd, DIR_WR); - b->wex = TICK_ETERNITY; - goto out_wakeup; + goto out_stop_write; } /* if the system buffer is full, don't insist */ @@ -479,6 +461,22 @@ int stream_sock_write(int fd) { fdtab[fd].ev &= ~FD_POLL_OUT; return retval; + out_stop_write: + /* We can't write anymore. Either the buffer is empty, or we just + * refrain from sending because send_max is reached. Maybe we just + * wrote the last chunk and need to close. + */ + if ((b->flags & (BF_SHUTW|BF_EMPTY|BF_HIJACK|BF_WRITE_ENA|BF_SHUTR)) == (BF_EMPTY|BF_WRITE_ENA|BF_SHUTR) && + (si->state == SI_ST_EST)) { + stream_sock_shutw(si); + } else { + if (!b->l && !b->splice_len) + si->flags |= SI_FL_WAIT_DATA; + EV_FD_CLR(fd, DIR_WR); + } + b->wex = TICK_ETERNITY; + goto out_wakeup; + out_error: /* Write error on the file descriptor. We mark the FD as STERROR so * that we don't use it anymore. The error is reported to the stream