diff --git a/include/proto/buffers.h b/include/proto/buffers.h index 1cd665076..9ebc6ffc0 100644 --- a/include/proto/buffers.h +++ b/include/proto/buffers.h @@ -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 */ diff --git a/include/types/buffers.h b/include/types/buffers.h index 11383f295..ca8080954 100644 --- a/include/types/buffers.h +++ b/include/types/buffers.h @@ -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]; }; diff --git a/src/session.c b/src/session.c index aacde9222..cd4419971 100644 --- a/src/session.c +++ b/src/session.c @@ -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);