From 74f899fc01a43c627a3ea668c9dff16aec5a4a91 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 11 Mar 2014 02:01:08 +0900 Subject: [PATCH] Replace NGHTTP2_MAX_FRAME_LENGTH with NGHTTP2_MAX_PAYLOADLEN --- lib/nghttp2_frame.c | 12 ++++++------ lib/nghttp2_frame.h | 14 +++++++------- lib/nghttp2_session.c | 12 ++++++------ tests/nghttp2_session_test.c | 28 ++++++++++++++-------------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/nghttp2_frame.c b/lib/nghttp2_frame.c index b6327bf1..6a08be97 100644 --- a/lib/nghttp2_frame.c +++ b/lib/nghttp2_frame.c @@ -264,13 +264,13 @@ ssize_t nghttp2_frame_pack_headers(nghttp2_buf *buf, frame */ memset(buf->pos, 0, NGHTTP2_FRAME_HDLEN); - /* pack ctrl header after length is determined */ - if(NGHTTP2_MAX_FRAME_LENGTH < frame->hd.length) { + /* pack frame header after length is determined */ + if(NGHTTP2_MAX_PAYLOADLEN < frame->hd.length) { /* Needs CONTINUATION */ nghttp2_frame_hd hd = frame->hd; hd.flags &= ~NGHTTP2_FLAG_END_HEADERS; - hd.length = NGHTTP2_MAX_FRAME_LENGTH; + hd.length = NGHTTP2_MAX_PAYLOADLEN; nghttp2_frame_pack_frame_hd(buf->pos, &hd); } else { @@ -473,13 +473,13 @@ ssize_t nghttp2_frame_pack_push_promise(nghttp2_buf *buf, frame */ memset(buf->pos, 0, NGHTTP2_FRAME_HDLEN); - /* pack ctrl header after length is determined */ - if(NGHTTP2_MAX_FRAME_LENGTH < frame->hd.length) { + /* pack frame header after length is determined */ + if(NGHTTP2_MAX_PAYLOADLEN < frame->hd.length) { /* Needs CONTINUATION */ nghttp2_frame_hd hd = frame->hd; hd.flags &= ~NGHTTP2_FLAG_END_HEADERS; - hd.length = NGHTTP2_MAX_FRAME_LENGTH; + hd.length = NGHTTP2_MAX_PAYLOADLEN; nghttp2_frame_pack_frame_hd(buf->pos, &hd); } else { diff --git a/lib/nghttp2_frame.h b/lib/nghttp2_frame.h index d74ea0bc..c2ee2c9a 100644 --- a/lib/nghttp2_frame.h +++ b/lib/nghttp2_frame.h @@ -42,7 +42,7 @@ /* The maximum payload length of a frame TODO: Must be renamed as NGHTTP2_MAX_PAYLOAD_LENGTH */ -#define NGHTTP2_MAX_FRAME_LENGTH ((1 << 14) - 1) +#define NGHTTP2_MAX_PAYLOADLEN ((1 << 14) - 1) /* The maximum length of DATA frame payload. To fit entire DATA frame into 4096K buffer, we use subtract header size (8 bytes) + 2 bytes @@ -111,9 +111,9 @@ size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame); * * frame->hd.length is assigned after length is determined during * packing process. If payload length is strictly larger than - * NGHTTP2_MAX_FRAME_LENGTH, payload data is still serialized as is, - * but frame->hd.length is set to NGHTTP2_MAX_FRAME_LENGTH and - * NGHTTP2_FLAG_END_HEADERS flag is cleared from frame->hd.flags. + * NGHTTP2_MAX_PAYLOADLEN, payload data is still serialized as is, but + * serialized header's payload length is set to NGHTTP2_MAX_PAYLOADLEN + * and NGHTTP2_FLAG_END_HEADERS flag is cleared. * * This function returns the size of packed frame (which equals to * nghttp2_buf_len(buf)) if it succeeds, or returns one of the @@ -254,9 +254,9 @@ int nghttp2_frame_unpack_settings_payload2(nghttp2_settings_entry **iv_ptr, * * frame->hd.length is assigned after length is determined during * packing process. If payload length is strictly larger than - * NGHTTP2_MAX_FRAME_LENGTH, payload data is still serialized as is, - * but frame->hd.length is set to NGHTTP2_MAX_FRAME_LENGTH and - * NGHTTP2_FLAG_END_HEADERS flag is cleared from frame->hd.flags. + * NGHTTP2_MAX_PAYLOADLEN, payload data is still serialized as is, but + * serialized header's payload length is set to NGHTTP2_MAX_PAYLOADLEN + * and NGHTTP2_FLAG_END_HEADERS flag is cleared. * * This function returns the size of packed frame (which equals to * nghttp2_buf_len(buf)) if it succeeds, or returns one of the diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 444200b4..5ddf1a84 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -1178,15 +1178,15 @@ static ssize_t session_headers_add_pad(nghttp2_session *session, DEBUGF(fprintf(stderr, "padding selected: payloadlen=%zu, padlen=%zu\n", frame->hd.length, frame->headers.padlen)); - if(frame->hd.length > NGHTTP2_MAX_FRAME_LENGTH) { + if(frame->hd.length > NGHTTP2_MAX_PAYLOADLEN) { nghttp2_frame_hd hd = frame->hd; hd.flags &= ~NGHTTP2_FLAG_END_HEADERS; - hd.length = NGHTTP2_MAX_FRAME_LENGTH; + hd.length = NGHTTP2_MAX_PAYLOADLEN; - if(NGHTTP2_MAX_FRAME_LENGTH > frame->hd.length - frame->headers.padlen) { + if(NGHTTP2_MAX_PAYLOADLEN > frame->hd.length - frame->headers.padlen) { size_t padlen; - padlen = NGHTTP2_MAX_FRAME_LENGTH - + padlen = NGHTTP2_MAX_PAYLOADLEN - (frame->hd.length - frame->headers.padlen); DEBUGF(fprintf(stderr, "padding across 2 frames\n")); @@ -1608,7 +1608,7 @@ static int nghttp2_session_after_frame_sent(nghttp2_session *session) nghttp2_frame_hd cont_hd; cont_hd.length = nghttp2_min(framebuf->last - framebuf->mark, - NGHTTP2_MAX_FRAME_LENGTH); + NGHTTP2_MAX_PAYLOADLEN); cont_hd.type = NGHTTP2_CONTINUATION; cont_hd.stream_id = frame->hd.stream_id; cont_hd.flags = NGHTTP2_FLAG_NONE; @@ -1970,7 +1970,7 @@ ssize_t nghttp2_session_mem_send(nghttp2_session *session, /* We have to get frame size from headers, because frame->hd.length does not always shows the actual frame size, especially for HEADERS size > - NGHTTP2_MAX_FRAME_LENGTH */ + NGHTTP2_MAX_PAYLOADLEN */ frame = nghttp2_outbound_item_get_ctrl_frame(item); framebuf->mark = framebuf->pos + NGHTTP2_FRAME_HDLEN + diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 54f756f2..02c3444c 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -3628,19 +3628,19 @@ void test_nghttp2_session_flow_control_data_recv(void) NGHTTP2_PRI_DEFAULT, NGHTTP2_STREAM_OPENED, NULL); - session->local_window_size = NGHTTP2_MAX_FRAME_LENGTH; - stream->local_window_size = NGHTTP2_MAX_FRAME_LENGTH; + session->local_window_size = NGHTTP2_MAX_PAYLOADLEN; + stream->local_window_size = NGHTTP2_MAX_PAYLOADLEN; /* Create DATA frame */ memset(data, 0, sizeof(data)); - hd.length = NGHTTP2_MAX_FRAME_LENGTH; + hd.length = NGHTTP2_MAX_PAYLOADLEN; hd.type = NGHTTP2_DATA; hd.flags = NGHTTP2_FLAG_END_STREAM; hd.stream_id = 1; nghttp2_frame_pack_frame_hd(data, &hd); - CU_ASSERT(NGHTTP2_MAX_FRAME_LENGTH+NGHTTP2_FRAME_HDLEN == + CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN+NGHTTP2_FRAME_HDLEN == nghttp2_session_mem_recv(session, data, - NGHTTP2_MAX_FRAME_LENGTH + + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); item = nghttp2_session_get_next_ob_item(session); @@ -3648,7 +3648,7 @@ void test_nghttp2_session_flow_control_data_recv(void) issued, but connection-level does. */ CU_ASSERT(NGHTTP2_WINDOW_UPDATE == OB_CTRL_TYPE(item)); CU_ASSERT(0 == OB_CTRL(item)->hd.stream_id); - CU_ASSERT(NGHTTP2_MAX_FRAME_LENGTH == + CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN == OB_CTRL(item)->window_update.window_size_increment); CU_ASSERT(0 == nghttp2_session_send(session)); @@ -3658,15 +3658,15 @@ void test_nghttp2_session_flow_control_data_recv(void) RST_STREAM is issued by the remote, but the local side keeps sending DATA frames. Without calculating connection-level window, the subsequent flow control gets confused. */ - CU_ASSERT(NGHTTP2_MAX_FRAME_LENGTH+NGHTTP2_FRAME_HDLEN == + CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN+NGHTTP2_FRAME_HDLEN == nghttp2_session_mem_recv(session, data, - NGHTTP2_MAX_FRAME_LENGTH + + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(NGHTTP2_WINDOW_UPDATE == OB_CTRL_TYPE(item)); CU_ASSERT(0 == OB_CTRL(item)->hd.stream_id); - CU_ASSERT(NGHTTP2_MAX_FRAME_LENGTH == + CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN == OB_CTRL(item)->window_update.window_size_increment); nghttp2_session_del(session); @@ -4199,7 +4199,7 @@ void test_nghttp2_session_pack_headers_with_padding(void) nva, ARRLEN(nva), NULL, NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(acc.length > NGHTTP2_MAX_FRAME_LENGTH); + CU_ASSERT(acc.length > NGHTTP2_MAX_PAYLOADLEN); ud.frame_recv_cb_called = 0; CU_ASSERT((ssize_t)acc.length == nghttp2_session_mem_recv(sv_session, acc.buf, acc.length)); @@ -4213,7 +4213,7 @@ void test_nghttp2_session_pack_headers_with_padding(void) acc.length = 0; CU_ASSERT(0 == nghttp2_session_send(sv_session)); - CU_ASSERT(acc.length > NGHTTP2_MAX_FRAME_LENGTH); + CU_ASSERT(acc.length > NGHTTP2_MAX_PAYLOADLEN); ud.frame_recv_cb_called = 0; CU_ASSERT((ssize_t)acc.length == nghttp2_session_mem_recv(session, acc.buf, acc.length)); @@ -4261,7 +4261,7 @@ void test_nghttp2_session_pack_headers_with_padding2(void) nva, ARRLEN(nva), NULL, NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(acc.length > NGHTTP2_MAX_FRAME_LENGTH); + CU_ASSERT(acc.length > NGHTTP2_MAX_PAYLOADLEN); ud.frame_recv_cb_called = 0; CU_ASSERT((ssize_t)acc.length == @@ -4310,7 +4310,7 @@ void test_nghttp2_session_pack_headers_with_padding3(void) nva, ARRLEN(nva), NULL, NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(acc.length > NGHTTP2_MAX_FRAME_LENGTH); + CU_ASSERT(acc.length > NGHTTP2_MAX_PAYLOADLEN); ud.frame_recv_cb_called = 0; CU_ASSERT((ssize_t)acc.length == nghttp2_session_mem_recv(sv_session, acc.buf, acc.length)); @@ -4354,7 +4354,7 @@ void test_nghttp2_session_pack_headers_with_padding4(void) nva, ARRLEN(nva), NULL, NULL)); CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(acc.length < NGHTTP2_MAX_FRAME_LENGTH); + CU_ASSERT(acc.length < NGHTTP2_MAX_PAYLOADLEN); ud.frame_recv_cb_called = 0; CU_ASSERT((ssize_t)acc.length == nghttp2_session_mem_recv(sv_session, acc.buf, acc.length));