Adjust transmission frame buffer size to support maximum payload size

This commit is contained in:
Tatsuhiro Tsujikawa 2014-04-02 20:33:01 +09:00
parent 9d9eb48258
commit 9c4c99bf96
3 changed files with 13 additions and 18 deletions

View File

@ -43,18 +43,16 @@
/* The number of bytes of frame header. */ /* The number of bytes of frame header. */
#define NGHTTP2_FRAME_HDLEN 8 #define NGHTTP2_FRAME_HDLEN 8
/* The maximum frame and payload length. The spec allows maximum #define NGHTTP2_MAX_PAYLOADLEN 16383
payload length up to 16383 bytes. Due to efficient buffer /* The one frame buffer length for tranmission. We may use several of
allocation, we choose smaller buffer. Actual payload limit offsets them to support CONTINUATION. To account for padding specifiers
frame header and possible PAD_HIGH and PAD_LOW to ease (PAD_HIGH and PAD_LOW), we allocate extra 2 bytes, which saves
serialization and save memcopying. */ extra large memcopying. */
#define NGHTTP2_MAX_FRAMELEN 8192 #define NGHTTP2_FRAMEBUF_CHUNKLEN \
#define NGHTTP2_MAX_PAYLOADLEN (NGHTTP2_MAX_FRAMELEN - NGHTTP2_FRAME_HDLEN - 2) (NGHTTP2_FRAME_HDLEN + 2 + NGHTTP2_MAX_PAYLOADLEN)
/* The maximum length of DATA frame payload. To fit entire DATA frame /* The maximum length of DATA frame payload. */
into 4096K buffer, we use subtract header size (8 bytes) + 2 bytes #define NGHTTP2_DATA_PAYLOAD_LENGTH 4096
padding. See nghttp2_session_pack_data(). */
#define NGHTTP2_DATA_PAYLOAD_LENGTH (4096 - NGHTTP2_FRAME_HDLEN - 2)
/* The number of bytes for each SETTINGS entry */ /* The number of bytes for each SETTINGS entry */
#define NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH 5 #define NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH 5

View File

@ -321,12 +321,9 @@ static int nghttp2_session_new(nghttp2_session **session_ptr,
(*session_ptr)->server = 1; (*session_ptr)->server = 1;
} }
/* 2 for PAD_HIGH and PAD_LOW. We have maximum 64KB of frame /* 2 for PAD_HIGH and PAD_LOW. */
serialization buffer for transmission */
rv = nghttp2_bufs_init3(&(*session_ptr)->aob.framebufs, rv = nghttp2_bufs_init3(&(*session_ptr)->aob.framebufs,
NGHTTP2_MAX_FRAMELEN, NGHTTP2_FRAMEBUF_CHUNKLEN, 8, 1,
(1 << 17) / NGHTTP2_MAX_FRAMELEN,
(1 << 13) / NGHTTP2_MAX_FRAMELEN,
NGHTTP2_FRAME_HDLEN + 2); NGHTTP2_FRAME_HDLEN + 2);
if(rv != 0) { if(rv != 0) {
goto fail_aob_framebuf; goto fail_aob_framebuf;

View File

@ -4659,7 +4659,7 @@ void test_nghttp2_session_pack_headers_with_padding(void)
accumulator acc; accumulator acc;
my_user_data ud; my_user_data ud;
nghttp2_session_callbacks callbacks; nghttp2_session_callbacks callbacks;
nghttp2_nv nva[4086]; nghttp2_nv nva[8172];
size_t i; size_t i;
nghttp2_priority_spec pri_spec; nghttp2_priority_spec pri_spec;
@ -4725,7 +4725,7 @@ void test_nghttp2_session_pack_headers_with_padding2(void)
accumulator acc; accumulator acc;
my_user_data ud; my_user_data ud;
nghttp2_session_callbacks callbacks; nghttp2_session_callbacks callbacks;
nghttp2_nv nva[8182]; nghttp2_nv nva[16364];
size_t i; size_t i;
for(i = 0; i < ARRLEN(nva); ++i) { for(i = 0; i < ARRLEN(nva); ++i) {