[MINOR] introduce structures required to support Linux kernel splicing

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.
This commit is contained in:
Willy Tarreau 2009-01-18 21:56:21 +01:00
parent 66aa61f76b
commit 259de1b702
3 changed files with 28 additions and 0 deletions

View 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 */

View 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];
};

View 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);