[vlc-commits] HTTP/2 HEADERS frame formatting optimistic zero-copy

Rémi Denis-Courmont git at videolan.org
Sun Dec 13 17:20:29 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Dec  9 21:48:56 2015 +0200| [20e49306f5aae8ef1f6a36cd1d03a910572ee09d] | committer: Rémi Denis-Courmont

HTTP/2 HEADERS frame formatting optimistic zero-copy

This avoids memory copying in the most common case that HTTP/2 headers
fit in a single HTT/2 frame.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=20e49306f5aae8ef1f6a36cd1d03a910572ee09d
---

 modules/access/http/h2frame.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/modules/access/http/h2frame.c b/modules/access/http/h2frame.c
index 99361c6..4a021b4 100644
--- a/modules/access/http/h2frame.c
+++ b/modules/access/http/h2frame.c
@@ -159,6 +159,18 @@ vlc_h2_frame_headers(uint_fast32_t stream_id, uint_fast32_t mtu, bool eos,
 
     size_t len = hpack_encode(NULL, 0, headers, count);
 
+    if (likely(len <= mtu))
+    {   /* Most common case: single frame - with zero copy */
+        flags |= VLC_H2_HEADERS_END_HEADERS;
+
+        f = vlc_h2_frame_alloc(VLC_H2_FRAME_HEADERS, flags, stream_id, len);
+        if (unlikely(f == NULL))
+            return NULL;
+
+        hpack_encode(vlc_h2_frame_payload(f), len, headers, count);
+        return f;
+    }
+
     /* Edge case: HEADERS frame then CONTINUATION frame(s) */
     uint8_t *payload = malloc(len);
     if (unlikely(payload == NULL))
@@ -188,9 +200,6 @@ vlc_h2_frame_headers(uint_fast32_t stream_id, uint_fast32_t mtu, bool eos,
         len -= mtu;
     }
 
-static_assert(VLC_H2_CONTINUATION_END_HEADERS == VLC_H2_HEADERS_END_HEADERS,
-              "Oops");
-
     flags |= VLC_H2_CONTINUATION_END_HEADERS;
 
     n = vlc_h2_frame_alloc(type, flags, stream_id, len);



More information about the vlc-commits mailing list