From 9c4c99bf965b43305390357934f0bc1dfbf44bfc Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 2 Apr 2014 20:33:01 +0900 Subject: [PATCH] Adjust transmission frame buffer size to support maximum payload size --- lib/nghttp2_frame.h | 20 +++++++++----------- lib/nghttp2_session.c | 7 ++----- tests/nghttp2_session_test.c | 4 ++-- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/lib/nghttp2_frame.h b/lib/nghttp2_frame.h index 31b972b2..719e1f64 100644 --- a/lib/nghttp2_frame.h +++ b/lib/nghttp2_frame.h @@ -43,18 +43,16 @@ /* The number of bytes of frame header. */ #define NGHTTP2_FRAME_HDLEN 8 -/* The maximum frame and payload length. The spec allows maximum - payload length up to 16383 bytes. Due to efficient buffer - allocation, we choose smaller buffer. Actual payload limit offsets - frame header and possible PAD_HIGH and PAD_LOW to ease - serialization and save memcopying. */ -#define NGHTTP2_MAX_FRAMELEN 8192 -#define NGHTTP2_MAX_PAYLOADLEN (NGHTTP2_MAX_FRAMELEN - NGHTTP2_FRAME_HDLEN - 2) +#define NGHTTP2_MAX_PAYLOADLEN 16383 +/* The one frame buffer length for tranmission. We may use several of + them to support CONTINUATION. To account for padding specifiers + (PAD_HIGH and PAD_LOW), we allocate extra 2 bytes, which saves + extra large memcopying. */ +#define NGHTTP2_FRAMEBUF_CHUNKLEN \ + (NGHTTP2_FRAME_HDLEN + 2 + NGHTTP2_MAX_PAYLOADLEN) -/* The maximum length of DATA frame payload. To fit entire DATA frame - into 4096K buffer, we use subtract header size (8 bytes) + 2 bytes - padding. See nghttp2_session_pack_data(). */ -#define NGHTTP2_DATA_PAYLOAD_LENGTH (4096 - NGHTTP2_FRAME_HDLEN - 2) +/* The maximum length of DATA frame payload. */ +#define NGHTTP2_DATA_PAYLOAD_LENGTH 4096 /* The number of bytes for each SETTINGS entry */ #define NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH 5 diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index a4082388..10f0f9c0 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -321,12 +321,9 @@ static int nghttp2_session_new(nghttp2_session **session_ptr, (*session_ptr)->server = 1; } - /* 2 for PAD_HIGH and PAD_LOW. We have maximum 64KB of frame - serialization buffer for transmission */ + /* 2 for PAD_HIGH and PAD_LOW. */ rv = nghttp2_bufs_init3(&(*session_ptr)->aob.framebufs, - NGHTTP2_MAX_FRAMELEN, - (1 << 17) / NGHTTP2_MAX_FRAMELEN, - (1 << 13) / NGHTTP2_MAX_FRAMELEN, + NGHTTP2_FRAMEBUF_CHUNKLEN, 8, 1, NGHTTP2_FRAME_HDLEN + 2); if(rv != 0) { goto fail_aob_framebuf; diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 49c902d1..accdfdbd 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -4659,7 +4659,7 @@ void test_nghttp2_session_pack_headers_with_padding(void) accumulator acc; my_user_data ud; nghttp2_session_callbacks callbacks; - nghttp2_nv nva[4086]; + nghttp2_nv nva[8172]; size_t i; nghttp2_priority_spec pri_spec; @@ -4725,7 +4725,7 @@ void test_nghttp2_session_pack_headers_with_padding2(void) accumulator acc; my_user_data ud; nghttp2_session_callbacks callbacks; - nghttp2_nv nva[8182]; + nghttp2_nv nva[16364]; size_t i; for(i = 0; i < ARRLEN(nva); ++i) {