]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[OPTIM] stream_sock: factor out the buffer full handling out of the loop
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Jan 2009 10:38:52 +0000 (11:38 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Jan 2009 10:38:52 +0000 (11:38 +0100)
Handling the buffer full condition is not trivial and this code was
duplicated inside the loop. Move it out of the loop at a single place.

src/stream_sock.c

index 16d7c5404ee41a03db04168d10af6826c754ae8f..59fc3e626ee85050ee54bbb3f1882a474409f904 100644 (file)
@@ -79,16 +79,8 @@ int stream_sock_read(int fd) {
                                max = b->max_len;
                }
 
-               if (unlikely(max == 0)) {
-                       /* Not anymore room to store data. This should theorically
-                        * never happen, but better safe than sorry !
-                        */
-                       si->flags |= SI_FL_WAIT_ROOM;
-                       b->flags |= BF_FULL;
-                       EV_FD_CLR(fd, DIR_RD);
-                       b->rex = TICK_ETERNITY;
-                       goto out_wakeup;
-               }
+               if (max == 0)
+                       goto out_full;
 
                /*
                 * 2. read the largest possible block
@@ -163,12 +155,7 @@ int stream_sock_read(int fd) {
                                        b->xfer_small = 0;
                                        b->xfer_large = 0;
                                }
-
-                               si->flags |= SI_FL_WAIT_ROOM;
-                               b->flags |= BF_FULL;
-                               EV_FD_CLR(fd, DIR_RD);
-                               b->rex = TICK_ETERNITY;
-                               goto out_wakeup;
+                               goto out_full;
                        }
 
                        /* if too many bytes were missing from last read, it means that
@@ -270,6 +257,13 @@ int stream_sock_read(int fd) {
        fdtab[fd].ev &= ~FD_POLL_IN;
        return retval;
 
+ out_full:
+       si->flags |= SI_FL_WAIT_ROOM;
+       b->flags |= BF_FULL;
+       EV_FD_CLR(fd, DIR_RD);
+       b->rex = TICK_ETERNITY;
+       goto out_wakeup;
+
  out_shutdown_r:
        /* we received a shutdown */
        fdtab[fd].ev &= ~FD_POLL_HUP;