From 68b5ffc1dcbe6e5c24995d7b6c8903e0b1b5272b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 9 Feb 2014 21:46:15 +0900 Subject: [PATCH] Rename padding related names --- lib/includes/nghttp2/nghttp2.h | 10 +++++----- lib/nghttp2_frame.c | 15 ++++++++------- lib/nghttp2_frame.h | 12 ++++++------ lib/nghttp2_session.c | 14 +++++++------- lib/nghttp2_session.h | 4 ++-- src/HttpServer.cc | 6 +++--- src/HttpServer.h | 2 +- src/nghttp.cc | 16 ++++++++-------- src/nghttpd.cc | 8 ++++---- tests/nghttp2_session_test.c | 6 +++--- 10 files changed, 47 insertions(+), 46 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index d268e622..6983b1d4 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -151,9 +151,9 @@ typedef struct { * @macro * * The default value of DATA padding alignment. See - * :member:`NGHTTP2_OPT_PAD_ALIGNMENT`. + * :member:`NGHTTP2_OPT_PADDING_BOUNDARY`. */ -#define NGHTTP2_PAD_ALIGNMENT 16 +#define NGHTTP2_PADDING_BOUNDARY 64 /** * @enum @@ -1341,7 +1341,7 @@ typedef enum { * to this alignment. The option value must be greater than or equal * to 8. */ - NGHTTP2_OPT_PAD_ALIGNMENT = 1 << 3 + NGHTTP2_OPT_PADDING_BOUNDARY = 1 << 3 } nghttp2_opt; /** @@ -1363,9 +1363,9 @@ typedef struct { */ uint8_t no_auto_connection_window_update; /** - * :enum:`NGHTTP2_OPT_PAD_ALIGNMENT` + * :enum:`NGHTTP2_OPT_PADDING_BOUNDARY` */ - uint16_t pad_alignment; + uint16_t padding_boundary; } nghttp2_opt_set; /** diff --git a/lib/nghttp2_frame.c b/lib/nghttp2_frame.c index 1d656081..6cdcf3ec 100644 --- a/lib/nghttp2_frame.c +++ b/lib/nghttp2_frame.c @@ -228,7 +228,7 @@ ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr, size_t *bufoff_ptr, nghttp2_headers *frame, nghttp2_hd_deflater *deflater, - size_t align) + size_t boundary) { size_t payloadoff = NGHTTP2_FRAME_HEAD_LENGTH + 2; size_t nv_offset = @@ -244,13 +244,13 @@ ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr, payloadlen = nghttp2_frame_headers_payload_nv_offset(frame) + rv; - if(align > 0) { + if(boundary > 0) { ssize_t padlen; padlen = nghttp2_frame_add_pad(buf_ptr, buflen_ptr, bufoff_ptr, &frame->hd.flags, payloadlen, - payloadlen + align, - align); + payloadlen + boundary, + boundary); if(padlen < 0) { return padlen; } @@ -665,11 +665,12 @@ ssize_t nghttp2_frame_add_pad(uint8_t **buf_ptr, size_t *buflen_ptr, uint8_t *flags_ptr, size_t payloadlen, size_t payloadmax, - size_t align) + size_t boundary) { int rv; - size_t nextlen = nghttp2_min((payloadlen + align - 1) / align * align, - payloadmax); + size_t nextlen = + nghttp2_min((payloadlen + boundary - 1) / boundary * boundary, + payloadmax); size_t padlen = nextlen - payloadlen; size_t trail_padlen = 0; /* extra 2 bytes for PAD_HIGH and PAD_LOW. */ diff --git a/lib/nghttp2_frame.h b/lib/nghttp2_frame.h index 92d6f0fa..4aa592f6 100644 --- a/lib/nghttp2_frame.h +++ b/lib/nghttp2_frame.h @@ -107,8 +107,8 @@ size_t nghttp2_frame_headers_payload_nv_offset(nghttp2_headers *frame); * The first byte the frame is serialized is returned in the * |*bufoff_ptr|. * - * The |align| is used as padding alignment. If the |align| is zero, - * no padding is added. + * The |boundary| is used as padding boundary. If the |boundary| is + * zero, no padding is added. * * frame->hd.length is assigned after length is determined during * packing process. If payload length is strictly larger than @@ -132,7 +132,7 @@ ssize_t nghttp2_frame_pack_headers(uint8_t **buf_ptr, size_t *bufoff_ptr, nghttp2_headers *frame, nghttp2_hd_deflater *deflater, - size_t align); + size_t boundary); /* * Unpacks HEADERS frame byte sequence into |frame|. This function @@ -508,8 +508,8 @@ int nghttp2_iv_check(const nghttp2_settings_entry *iv, size_t niv); * payload must start at offset NGHTTP2_FRAME_HEAD_LENGTH + 2 from * |*buf_ptr| to account for PAD_HIGH and PAD_LOW. The maximum payload * allowed is given in the |payloadmax|. The padding will not be made - * more than |payloadmax|. The padding alignment is given in the - * |align|. + * more than |payloadmax|. The padding boundary is given in the + * |boundary|. * * The |*flags_ptr| is updated to include NGHTTP2_FLAG_PAD_LOW and * NGHTTP2_FLAG_PAD_HIGH based on the padding length. The @@ -582,6 +582,6 @@ ssize_t nghttp2_frame_add_pad(uint8_t **buf_ptr, size_t *buflen_ptr, uint8_t *flags_ptr, size_t payloadlen, size_t payloadmax, - size_t align); + size_t boundary); #endif /* NGHTTP2_FRAME_H */ diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 76cfbfcc..52fa3267 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -224,11 +224,11 @@ static int nghttp2_session_new(nghttp2_session **session_ptr, (*session_ptr)->opt_flags |= NGHTTP2_OPTMASK_NO_AUTO_CONNECTION_WINDOW_UPDATE; } - if((opt_set_mask & NGHTTP2_OPT_PAD_ALIGNMENT) && - opt_set->pad_alignment >= 8) { - (*session_ptr)->pad_alignment = opt_set->pad_alignment; + if((opt_set_mask & NGHTTP2_OPT_PADDING_BOUNDARY) && + opt_set->padding_boundary >= 8) { + (*session_ptr)->padding_boundary = opt_set->padding_boundary; } else { - (*session_ptr)->pad_alignment = NGHTTP2_PAD_ALIGNMENT; + (*session_ptr)->padding_boundary = NGHTTP2_PADDING_BOUNDARY; } (*session_ptr)->remote_window_size = NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE; @@ -1123,7 +1123,7 @@ static ssize_t nghttp2_session_prep_frame(nghttp2_session *session, &session->aob.framebufoff, &frame->headers, &session->hd_deflater, - session->pad_alignment); + session->padding_boundary); if(framebuflen < 0) { return framebuflen; } @@ -4227,11 +4227,11 @@ ssize_t nghttp2_session_pack_data(nghttp2_session *session, frame->hd.flags &= ~(NGHTTP2_FLAG_PAD_HIGH | NGHTTP2_FLAG_PAD_LOW); flags = 0; - if(session->pad_alignment && + if(session->padding_boundary && payloadlen > 0 && (size_t)payloadlen < datamax) { rv = nghttp2_frame_add_pad(buf_ptr, buflen_ptr, bufoff_ptr, &flags, payloadlen, datamax, - session->pad_alignment); + session->padding_boundary); if(rv < 0) { return rv; } diff --git a/lib/nghttp2_session.h b/lib/nghttp2_session.h index a205cb60..d17b8105 100644 --- a/lib/nghttp2_session.h +++ b/lib/nghttp2_session.h @@ -153,8 +153,8 @@ struct nghttp2_session { size_t num_incoming_streams; /* The number of bytes allocated for nvbuf */ size_t nvbuflen; - /* padding alignemnt. See NGHTTP2_OPT_PAD_ALIGNMENT. */ - size_t pad_alignment; + /* padding alignemnt. See NGHTTP2_OPT_PADDING_BOUNDARY. */ + size_t padding_boundary; /* Next Stream ID. Made unsigned int to detect >= (1 << 31). */ uint32_t next_stream_id; /* The largest stream ID received so far */ diff --git a/src/HttpServer.cc b/src/HttpServer.cc index df09f4e4..4fb59244 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -66,7 +66,7 @@ const std::string NGHTTPD_SERVER = "nghttpd nghttp2/" NGHTTP2_VERSION; Config::Config() : data_ptr(nullptr), output_upper_thres(1024*1024), - pad_alignment(NGHTTP2_PAD_ALIGNMENT), + padding_boundary(NGHTTP2_PADDING_BOUNDARY), header_table_size(-1), port(0), verbose(false), @@ -365,11 +365,11 @@ int Http2Handler::on_connect() nghttp2_opt_set opt_set; memset(&opt_set, 0, sizeof(opt_set)); - opt_set.pad_alignment = sessions_->get_config()->pad_alignment; + opt_set.padding_boundary = sessions_->get_config()->padding_boundary; fill_callback(callbacks, sessions_->get_config()); r = nghttp2_session_server_new2(&session_, &callbacks, this, - NGHTTP2_OPT_PAD_ALIGNMENT, &opt_set); + NGHTTP2_OPT_PADDING_BOUNDARY, &opt_set); if(r != 0) { return r; } diff --git a/src/HttpServer.h b/src/HttpServer.h index ad5feefa..308d3b10 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -56,7 +56,7 @@ struct Config { std::string cert_file; void *data_ptr; size_t output_upper_thres; - size_t pad_alignment; + size_t padding_boundary; ssize_t header_table_size; uint16_t port; bool verbose; diff --git a/src/nghttp.cc b/src/nghttp.cc index 27837404..197b4c26 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -82,7 +82,7 @@ struct Config { std::string keyfile; std::string datafile; size_t output_upper_thres; - size_t pad_alignment; + size_t padding_boundary; ssize_t peer_max_concurrent_streams; ssize_t header_table_size; int32_t pri; @@ -100,7 +100,7 @@ struct Config { bool continuation; Config() : output_upper_thres(1024*1024), - pad_alignment(NGHTTP2_PAD_ALIGNMENT), + padding_boundary(NGHTTP2_PADDING_BOUNDARY), peer_max_concurrent_streams(NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS), header_table_size(-1), pri(NGHTTP2_PRI_DEFAULT), @@ -716,10 +716,10 @@ struct HttpClient { } nghttp2_opt_set opt_set; opt_set.peer_max_concurrent_streams = config.peer_max_concurrent_streams; - opt_set.pad_alignment = config.pad_alignment; + opt_set.padding_boundary = config.padding_boundary; rv = nghttp2_session_client_new2(&session, callbacks, this, NGHTTP2_OPT_PEER_MAX_CONCURRENT_STREAMS | - NGHTTP2_OPT_PAD_ALIGNMENT, + NGHTTP2_OPT_PADDING_BOUNDARY, &opt_set); if(rv != 0) { return -1; @@ -1710,8 +1710,8 @@ void print_help(std::ostream& out) << " is large enough as it is seen as unlimited.\n" << " -c, --header-table-size=\n" << " Specify decoder header table size.\n" - << " -b, --pad=\n" - << " Alignment of frame payload padding.\n" + << " -b, --padding=\n" + << " Padding boundary for frame payload.\n" << " --color Force colored log output.\n" << " --continuation Send large header to test CONTINUATION.\n" << std::endl; @@ -1740,7 +1740,7 @@ int main(int argc, char **argv) {"pri", required_argument, nullptr, 'p'}, {"peer-max-concurrent-streams", required_argument, nullptr, 'M'}, {"header-table-size", required_argument, nullptr, 'c'}, - {"data-pad", required_argument, nullptr, 'b'}, + {"padding", required_argument, nullptr, 'b'}, {"cert", required_argument, &flag, 1}, {"key", required_argument, &flag, 2}, {"color", no_argument, &flag, 3}, @@ -1766,7 +1766,7 @@ int main(int argc, char **argv) print_help(std::cout); exit(EXIT_SUCCESS); case 'b': - config.pad_alignment = strtol(optarg, nullptr, 10); + config.padding_boundary = strtol(optarg, nullptr, 10); break; case 'n': config.null_out = true; diff --git a/src/nghttpd.cc b/src/nghttpd.cc index 741475d0..2287171d 100644 --- a/src/nghttpd.cc +++ b/src/nghttpd.cc @@ -115,8 +115,8 @@ void print_help(std::ostream& out) << " -p/=/foo.png -p/doc=/bar.css\n" << " PATH and PUSH_PATHs are relative to document\n" << " root. See --htdocs option.\n" - << " -b, --pad=\n" - << " Alignment of frame payload padding.\n" + << " -b, --padding=\n" + << " Padding boundary for frame payload.\n" << " -h, --help Print this help.\n" << std::endl; } @@ -136,7 +136,7 @@ int main(int argc, char **argv) {"verify-client", no_argument, nullptr, 'V'}, {"header-table-size", required_argument, nullptr, 'c'}, {"push", required_argument, nullptr, 'p'}, - {"data-pad", required_argument, nullptr, 'b'}, + {"padding", required_argument, nullptr, 'b'}, {"no-tls", no_argument, &flag, 1}, {"color", no_argument, &flag, 2}, {nullptr, 0, nullptr, 0} @@ -155,7 +155,7 @@ int main(int argc, char **argv) config.verify_client = true; break; case 'b': - config.pad_alignment = strtol(optarg, nullptr, 10); + config.padding_boundary = strtol(optarg, nullptr, 10); break; case 'd': config.htdocs = optarg; diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 7bc2b8d3..e30c7e0f 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -3870,7 +3870,7 @@ void test_nghttp2_session_pack_data_with_padding(void) data_prd.read_callback = fixed_length_data_source_read_callback; nghttp2_session_client_new(&session, &callbacks, &ud); - session->pad_alignment = 512; + session->padding_boundary = 512; nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, NULL, 0, &data_prd, NULL); @@ -3881,7 +3881,7 @@ void test_nghttp2_session_pack_data_with_padding(void) CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); frame = OB_DATA(session->aob.item); - CU_ASSERT(session->pad_alignment - datalen == frame->padlen); + CU_ASSERT(session->padding_boundary - datalen == frame->padlen); CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_LOW); CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_HIGH); @@ -3905,7 +3905,7 @@ void test_nghttp2_session_pack_data_with_padding(void) CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); frame = OB_DATA(session->aob.item); - CU_ASSERT((frame->padlen + datalen) % session->pad_alignment == 0); + CU_ASSERT((frame->padlen + datalen) % session->padding_boundary == 0); CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PAD_LOW); CU_ASSERT(0 == (frame->hd.flags & NGHTTP2_FLAG_PAD_HIGH));