]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] stream_sock: factor out the return path in case of no-writes
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Jan 2009 19:10:39 +0000 (20:10 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Jan 2009 09:15:02 +0000 (10:15 +0100)
Previously, we wrote nothing only if the buffer was empty. Now with
send_max, we can also write nothing because we are not allowed to send
anything due to send_max.

The code starts to look like spaghetti. It needs to be rearranged a
lot before merging the splice patches.

src/stream_sock.c

index d10faa8f1f57f2c215d4581a63ee3360b8071f7f..7b684f4e312a811c9db7d5c8311ddc0de377f9bc 100644 (file)
@@ -358,13 +358,12 @@ int stream_sock_write(int fd) {
                        }
 
                        /* Funny, we were called to write something but there wasn't
-                        * anything. Theorically we cannot get there, but just in case,
-                        * let's disable the write event and pretend we never came there.
+                        * anything. We can get there, for example if we were woken up
+                        * on a write event to finish the splice, but the send_max is 0
+                        * so we cannot write anything from the buffer. Let's disable
+                        * the write event and pretend we never came there.
                         */
-                       si->flags |= SI_FL_WAIT_DATA;
-                       EV_FD_CLR(fd, DIR_WR);
-                       b->wex = TICK_ETERNITY;
-                       goto out_wakeup;
+                       goto write_nothing;
                }
 
 #ifndef MSG_NOSIGNAL
@@ -409,6 +408,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) {
@@ -418,7 +418,11 @@ int stream_sock_write(int fd) {
                                        }
                                }
 
-                               si->flags |= SI_FL_WAIT_DATA;
+                               /* 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;