]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: replace http_message_realign() with buffer_slow_realign()
authorWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 18:40:09 +0000 (20:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 19:28:17 +0000 (21:28 +0200)
There is no more reason for the realign function being HTTP specific,
it only operates on a buffer now. Let's move it to buffers.c instead.

It's likely that buffer_bounce_realign is broken (not used), this will
have to be inspected. The function is worth rewriting as it can be
cheaper than buffer_slow_realign() to realign large wrapping buffers.

include/proto/buffers.h
src/buffers.c
src/proto_http.c

index 3b98f178a1d442d79ee8fa45c7ec4558f24891bf..6f8e2c15d430432e68c0eb79dd5875b782970d1d 100644 (file)
@@ -48,6 +48,7 @@ int bo_getblk(struct buffer *buf, char *blk, int len, int offset);
 int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int len);
 int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len);
 void buffer_dump(FILE *o, struct buffer *b, int from, int to);
+void buffer_slow_realign(struct buffer *buf);
 void buffer_bounce_realign(struct buffer *buf);
 unsigned long long buffer_forward(struct buffer *buf, unsigned long long bytes);
 
index e71f8522cd495e9246be25ad50b914b805e78922..7becb4863dbf078b5c9e62c4d1c392eb75b659fa 100644 (file)
@@ -388,6 +388,34 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
 }
 
 
+/* This function realigns input data in a possibly wrapping buffer so that it
+ * becomes contiguous and starts at the beginning of the buffer area. The
+ * function may only be used when the buffer's output is empty.
+ */
+void buffer_slow_realign(struct buffer *buf)
+{
+       /* two possible cases :
+        *   - the buffer is in one contiguous block, we move it in-place
+        *   - the buffer is in two blocks, we move it via the swap_buffer
+        */
+       if (buf->i) {
+               int block1 = buf->i;
+               int block2 = 0;
+               if (buf->p + buf->i > buf->data + buf->size) {
+                       /* non-contiguous block */
+                       block1 = buf->data + buf->size - buf->p;
+                       block2 = buf->p + buf->i - (buf->data + buf->size);
+               }
+               if (block2)
+                       memcpy(swap_buffer, buf->data, block2);
+               memmove(buf->data, buf->p, block1);
+               if (block2)
+                       memcpy(buf->data + block1, swap_buffer, block2);
+       }
+
+       buf->p = buf->data;
+}
+
 /* Realigns a possibly non-contiguous buffer by bouncing bytes from source to
  * destination. It does not use any intermediate buffer and does the move in
  * place, though it will be slower than a simple memmove() on contiguous data,
index 637c856ba02809ee6b9ffc7c5a79ef4268ae35f2..3db7de1facd30e736183f4848504930847ea2ab9 100644 (file)
@@ -1961,40 +1961,6 @@ int http_skip_chunk_crlf(struct http_msg *msg)
        return 1;
 }
 
-/* This function realigns a possibly wrapping http message at the beginning
- * of its buffer. The function may only be used when the buffer's tail is
- * empty.
- */
-void http_message_realign(struct http_msg *msg)
-{
-       struct buffer *buf = msg->buf;
-
-       /* two possible cases :
-        *   - the buffer is in one contiguous block, we move it in-place
-        *   - the buffer is in two blocks, we move it via the swap_buffer
-        */
-       if (buf->i) {
-               int block1 = buf->i;
-               int block2 = 0;
-               if (buf->p + buf->i > buf->data + buf->size) {
-                       /* non-contiguous block */
-                       block1 = buf->data + buf->size - buf->p;
-                       block2 = buf->p + buf->i - (buf->data + buf->size);
-               }
-               if (block2)
-                       memcpy(swap_buffer, buf->data, block2);
-               memmove(buf->data, buf->p, block1);
-               if (block2)
-                       memcpy(buf->data + block1, swap_buffer, block2);
-       }
-
-       /* adjust all known pointers */
-       buf->p = buf->data;
-       buf->flags &= ~BF_FULL;
-       if (bi_full(buf))
-               buf->flags |= BF_FULL;
-}
-
 /* This stream analyser waits for a complete HTTP request. It returns 1 if the
  * processing can continue on next analysers, or zero if it either needs more
  * data or wants to immediately abort the request (eg: timeout, error, ...). It
@@ -2063,7 +2029,7 @@ int http_wait_for_request(struct session *s, struct buffer *req, int an_bit)
                        }
                        if (bi_end(req) < b_ptr(req, msg->next) ||
                            bi_end(req) > req->data + req->size - global.tune.maxrewrite)
-                               http_message_realign(msg);
+                               buffer_slow_realign(msg->buf);
                }
 
                /* Note that we have the same problem with the response ; we
@@ -4473,7 +4439,7 @@ int http_wait_for_response(struct session *s, struct buffer *rep, int an_bit)
                                return 0;
                        }
                        if (rep->i <= rep->size - global.tune.maxrewrite)
-                               http_message_realign(msg);
+                               buffer_slow_realign(msg->buf);
                }
 
                if (likely(msg->next < rep->i))