[MEDIUM] add support for infinite forwarding
In TCP, we don't want to forward chunks of data, we want to forward
indefinitely. This patch introduces a special value for the amount
of data to be forwarded. When buffer_forward() is called with
BUF_INFINITE_FORWARD, it configures the buffer to never stop
forwarding until the end.
diff --git a/include/common/defaults.h b/include/common/defaults.h
index 966ef4f..c09f5a4 100644
--- a/include/common/defaults.h
+++ b/include/common/defaults.h
@@ -2,7 +2,7 @@
include/common/defaults.h
Miscellaneous default values.
- Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
+ Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -40,16 +40,6 @@
#define MAXREWRITE (BUFSIZE / 2)
#endif
-/* FORWARD_DEFAULT_SIZE
- * Indicates how many bytes may be forwarded at once in low-level stream-socks
- * without waking the owner task up. This should be much larger than the buffer
- * size. A few megabytes seem appropriate.
- */
-#ifndef FORWARD_DEFAULT_SIZE
-#define FORWARD_DEFAULT_SIZE (16*1024*1024)
-#endif
-
-
#define REQURI_LEN 1024
#define CAPTURE_LEN 64
diff --git a/include/proto/buffers.h b/include/proto/buffers.h
index 6878cfe..abaf5ee 100644
--- a/include/proto/buffers.h
+++ b/include/proto/buffers.h
@@ -85,9 +85,9 @@
* cause lockups when send_max goes down to zero if nobody is ready to push the
* remaining data.
*/
-static inline void buffer_forward(struct buffer *buf, unsigned int bytes)
+static inline void buffer_forward(struct buffer *buf, unsigned long bytes)
{
- unsigned int data_left;
+ unsigned long data_left;
if (!bytes)
return;
@@ -98,8 +98,13 @@
return;
}
- buf->to_forward += bytes - data_left;
buf->send_max += data_left;
+ if (buf->to_forward == BUF_INFINITE_FORWARD)
+ return;
+
+ buf->to_forward += bytes - data_left;
+ if (bytes == BUF_INFINITE_FORWARD)
+ buf->to_forward = bytes;
}
/* Schedule all remaining buffer data to be sent. send_max is not touched if it
@@ -380,8 +385,9 @@
if (buf->r - buf->data == buf->size)
buf->r -= buf->size;
- if ((signed)(buf->to_forward - 1) >= 0) {
- buf->to_forward--;
+ if (buf->to_forward >= 1) {
+ if (buf->to_forward != BUF_INFINITE_FORWARD)
+ buf->to_forward--;
buf->send_max++;
buf->flags &= ~BF_OUT_EMPTY;
}
diff --git a/include/types/buffers.h b/include/types/buffers.h
index 969c103..14cb966 100644
--- a/include/types/buffers.h
+++ b/include/types/buffers.h
@@ -143,6 +143,9 @@
#define AN_RTR_HTTP_HDR 0x00000200 /* inspect HTTP response headers */
#define AN_REQ_PRST_RDP_COOKIE 0x00000400 /* persistence on rdp cookie */
+/* Magic value to forward infinite size (TCP, ...), used with ->to_forward */
+#define BUF_INFINITE_FORWARD (~0UL)
+
/* describes a chunk of string */
struct chunk {
char *str; /* beginning of the string itself. Might not be 0-terminated */
@@ -164,7 +167,7 @@
unsigned int size; /* buffer size in bytes */
unsigned int max_len; /* read limit, used to keep room for header rewriting */
unsigned int send_max; /* number of bytes the sender can consume om this buffer, <= l */
- unsigned int to_forward; /* number of bytes to forward after send_max without a wake-up */
+ unsigned long to_forward; /* number of bytes to forward after send_max without a wake-up */
unsigned int analysers; /* bit field indicating what to do on the buffer */
int analyse_exp; /* expiration date for current analysers (if set) */
void (*hijacker)(struct session *, struct buffer *); /* alternative content producer */
@@ -205,7 +208,8 @@
The producer is responsible for decreasing ->to_forward and increasing
->send_max. The ->to_forward parameter indicates how many bytes may be fed
- into either data buffer without waking the parent up. The ->send_max
+ into either data buffer without waking the parent up. The special value
+ BUF_INFINITE_FORWARD is never decreased nor increased. The ->send_max
parameter says how many bytes may be read from the visible buffer. Thus it
may never exceed ->l. This parameter is updated by any buffer_write() as
well as any data forwarded through the visible buffer.