]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] introduce structures required to support Linux kernel splicing
authorWilly Tarreau <w@1wt.eu>
Sun, 18 Jan 2009 20:56:21 +0000 (21:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 18 Jan 2009 20:56:21 +0000 (21:56 +0100)
When CONFIG_HAP_LINUX_SPLICE is defined, the buffer structure will be
slightly enlarged to support information needed for kernel splicing
on Linux.

A first attempt consisted in putting this information into the stream
interface, but in the long term, it appeared really awkward. This
version puts the information into the buffer. The platform-dependant
part is conditionally added and will only enlarge the buffers when
compiled in.

One new flag has also been added to the buffers: BF_KERN_SPLICING.
It indicates that the application considers it is appropriate to
use splicing to forward remaining data.

include/proto/buffers.h
include/types/buffers.h
src/session.c

index 1cd66507617ea5c656b56f4e66ac30f183567343..9ebc6ffc0a6e737efec5515e507c86bec4b6a52b 100644 (file)
@@ -54,6 +54,9 @@ static inline void buffer_init(struct buffer *buf)
        buf->flags = BF_EMPTY;
        buf->r = buf->lr = buf->w = buf->data;
        buf->max_len = BUFSIZE;
+#if defined(CONFIG_HAP_LINUX_SPLICE)
+       buf->splice.prod = buf->splice.cons = -1; /* closed */
+#endif
 }
 
 /* returns 1 if the buffer is empty, 0 otherwise */
index 11383f29535bea8dbbb2ebe0165eb0bd43c8decd..ca808095482ed8469829e3a0d1648dcc6bfa1cca 100644 (file)
@@ -83,6 +83,7 @@
 #define BF_HIJACK         0x040000  /* the producer is temporarily replaced by ->hijacker */
 #define BF_ANA_TIMEOUT    0x080000  /* the analyser timeout has expired */
 #define BF_READ_ATTACHED  0x100000  /* the read side is attached for the first time */
+#define BF_KERN_SPLICING  0x200000  /* kernel splicing desired for this buffer */
 
 /* 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))
@@ -140,6 +141,12 @@ struct buffer {
        unsigned long long total;       /* total data read */
        struct stream_interface *prod;  /* producer attached to this buffer */
        struct stream_interface *cons;  /* consumer attached to this buffer */
+       struct {
+#if defined(CONFIG_HAP_LINUX_SPLICE)
+               int prod;               /* -1 or fd of the pipe's end towards the producer */
+               int cons;               /* -1 or fd of the pipe's end towards the consumer */
+#endif
+       } splice;
        char data[BUFSIZE];
 };
 
index aacde922250ad27c082f32d9536cd6edbe4beed3..cd4419971d23e467161814647687a71c76b5655c 100644 (file)
@@ -64,6 +64,24 @@ void session_free(struct session *s)
                sess_change_server(s, NULL);
        }
 
+#if defined(CONFIG_HAP_LINUX_SPLICE)
+       if (s->req->splice.prod >= 0)
+               close(s->req->splice.prod);
+       if (s->req->splice.cons >= 0)
+               close(s->req->splice.cons);
+       
+       if (s->req->splice.prod >= 0 || s->req->splice.cons >= 0)
+               usedpipes--;
+
+       if (s->rep->splice.prod >= 0)
+               close(s->rep->splice.prod);
+       if (s->rep->splice.cons >= 0)
+               close(s->rep->splice.cons);
+
+       if (s->rep->splice.prod >= 0 || s->rep->splice.cons >= 0)
+               usedpipes--;
+#endif
+
        pool_free2(pool2_buffer, s->req);
        pool_free2(pool2_buffer, s->rep);