]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] http: don't wait for sending requests to the server
authorWilly Tarreau <w@1wt.eu>
Sun, 3 Jan 2010 16:24:51 +0000 (17:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 3 Jan 2010 16:24:51 +0000 (17:24 +0100)
By default we automatically wait for enough data to fill large
packets if buf->to_forward is not null. This causes a problem
with POST/Expect requests which have a data size but no data
immediately available. Instead of causing noticeable delays on
such requests, simply add a flag to disable waiting when sending
requests.

include/types/buffers.h
src/proto_http.c
src/stream_sock.c

index 34189cde0fb4ac3bc2ef61c0ca5bbf7812fafbb0..ba7bcb8ae781a96fa6bde0133ba4c50bbda9fbe1 100644 (file)
 
 #define BF_DONT_READ     0x1000000  /* disable reading for now */
 #define BF_EXPECT_MORE   0x2000000  /* more data expected to be sent very soon (one-shoot) */
+#define BF_SEND_DONTWAIT 0x4000000  /* don't wait for sending data (one-shoot) */
 
 /* Use these masks to clear the flags before going back to lower layers */
 #define BF_CLEAR_READ     (~(BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR|BF_READ_ATTACHED))
index 2cab1989d64044bbc417a26ffdce703889531d40..73f9fd17967f26372f91ecaed5c959fc8547c742 100644 (file)
@@ -2807,6 +2807,15 @@ int http_process_req_common(struct session *s, struct buffer *req, int an_bit, s
        else
                req->flags &= ~BF_DONT_READ;
 
+       /* POST requests may be accompanied with an "Expect: 100-Continue" header.
+        * If this happens, then the data will not come immediately, so we must
+        * send all what we have without waiting. Note that due to the small gain
+        * in waiting for the body of the request, it's easier to simply put the
+        * BF_SEND_DONTWAIT flag any time. It's a one-shot flag so it will remove
+        * itself once used.
+        */
+       req->flags |= BF_SEND_DONTWAIT;
+
        /* that's OK for us now, let's move on to next analysers */
        return 1;
 
index 4a9434c4f8d19bed3ef7d0b151dc3087a3313473..5caac469e7d906d4569530d2ffdbbc8515651016 100644 (file)
@@ -623,7 +623,15 @@ static int stream_sock_write_loop(struct stream_interface *si, struct buffer *b)
                                send_flag |= MSG_MORE;
                        }
 
+                       /* this flag has precedence over the rest */
+                       if (b->flags & BF_SEND_DONTWAIT)
+                               send_flag &= ~MSG_MORE;
+
                        ret = send(si->fd, b->w, max, send_flag);
+
+                       /* disable it only once everything has been sent */
+                       if (ret == max && (b->flags & BF_SEND_DONTWAIT))
+                               b->flags &= ~BF_SEND_DONTWAIT;
                } else {
                        int skerr;
                        socklen_t lskerr = sizeof(skerr);