[PATCH 3 of 4] HTTP/2: make SETTINGS ACK frame reusable
Piotr Sikora
piotrsikora at google.com
Mon Apr 24 22:48:25 UTC 2017
# HG changeset patch
# User Piotr Sikora <piotrsikora at google.com>
# Date 1493073310 25200
# Mon Apr 24 15:35:10 2017 -0700
# Node ID b8d7f4a4d5abb4a27a772910358e263d49c618ef
# Parent a8cfd4c454ff5433629bfd16444c6c71ee932fa1
HTTP/2: make SETTINGS ACK frame reusable.
Signed-off-by: Piotr Sikora <piotrsikora at google.com>
diff -r a8cfd4c454ff -r b8d7f4a4d5ab src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c
+++ b/src/http/v2/ngx_http_v2.c
@@ -28,6 +28,7 @@
#define NGX_HTTP_V2_HTTP_1_1_REQUIRED 0xd
/* frame sizes */
+#define NGX_HTTP_V2_SETTINGS_ACK_SIZE 0
#define NGX_HTTP_V2_RST_STREAM_SIZE 4
#define NGX_HTTP_V2_PRIORITY_SIZE 5
#define NGX_HTTP_V2_PING_SIZE 8
@@ -128,8 +129,7 @@ static ngx_http_v2_node_t *ngx_http_v2_g
#define ngx_http_v2_index_size(h2scf) (h2scf->streams_index_mask + 1)
#define ngx_http_v2_index(h2scf, sid) ((sid >> 1) & h2scf->streams_index_mask)
-static ngx_int_t ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c,
- ngx_uint_t ack);
+static ngx_int_t ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c);
static ngx_int_t ngx_http_v2_settings_frame_handler(
ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame);
static ngx_int_t ngx_http_v2_send_window_update(ngx_http_v2_connection_t *h2c,
@@ -269,7 +269,7 @@ ngx_http_v2_init(ngx_event_t *rev)
return;
}
- if (ngx_http_v2_send_settings(h2c, 0) == NGX_ERROR) {
+ if (ngx_http_v2_send_settings(h2c) == NGX_ERROR) {
ngx_http_close_connection(c);
return;
}
@@ -1980,7 +1980,8 @@ static u_char *
ngx_http_v2_state_settings_params(ngx_http_v2_connection_t *h2c, u_char *pos,
u_char *end)
{
- ngx_uint_t id, value, adjustment;
+ ngx_uint_t id, value, adjustment;
+ ngx_http_v2_out_frame_t *frame;
adjustment = 0;
@@ -2035,7 +2036,14 @@ ngx_http_v2_state_settings_params(ngx_ht
pos += NGX_HTTP_V2_SETTINGS_PARAM_SIZE;
}
- ngx_http_v2_send_settings(h2c, 1);
+ frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_SETTINGS_ACK_SIZE,
+ NGX_HTTP_V2_SETTINGS_FRAME,
+ NGX_HTTP_V2_ACK_FLAG, 0);
+ if (frame == NULL) {
+ return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
+ }
+
+ ngx_http_v2_queue_blocked_frame(h2c, frame);
if (adjustment) {
if (ngx_http_v2_adjust_windows(h2c, adjustment) != NGX_OK) {
@@ -2487,7 +2495,7 @@ ngx_http_v2_parse_int(ngx_http_v2_connec
static ngx_int_t
-ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c, ngx_uint_t ack)
+ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c)
{
size_t len;
ngx_buf_t *buf;
@@ -2495,8 +2503,8 @@ ngx_http_v2_send_settings(ngx_http_v2_co
ngx_http_v2_srv_conf_t *h2scf;
ngx_http_v2_out_frame_t *frame;
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 send SETTINGS frame ack:%ui", ack);
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
+ "http2 send SETTINGS frame params:3");
frame = ngx_palloc(h2c->pool, sizeof(ngx_http_v2_out_frame_t));
if (frame == NULL) {
@@ -2508,7 +2516,7 @@ ngx_http_v2_send_settings(ngx_http_v2_co
return NGX_ERROR;
}
- len = ack ? 0 : (sizeof(uint16_t) + sizeof(uint32_t)) * 3;
+ len = NGX_HTTP_V2_SETTINGS_PARAM_SIZE * 3;
buf = ngx_create_temp_buf(h2c->pool, NGX_HTTP_V2_FRAME_HEADER_SIZE + len);
if (buf == NULL) {
@@ -2532,28 +2540,26 @@ ngx_http_v2_send_settings(ngx_http_v2_co
buf->last = ngx_http_v2_write_len_and_type(buf->last, len,
NGX_HTTP_V2_SETTINGS_FRAME);
- *buf->last++ = ack ? NGX_HTTP_V2_ACK_FLAG : NGX_HTTP_V2_NO_FLAG;
+ *buf->last++ = NGX_HTTP_V2_NO_FLAG;
buf->last = ngx_http_v2_write_sid(buf->last, 0);
- if (!ack) {
- h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- buf->last = ngx_http_v2_write_uint16(buf->last,
- NGX_HTTP_V2_MAX_STREAMS_SETTING);
- buf->last = ngx_http_v2_write_uint32(buf->last,
- h2scf->concurrent_streams);
-
- buf->last = ngx_http_v2_write_uint16(buf->last,
+ h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
+ ngx_http_v2_module);
+
+ buf->last = ngx_http_v2_write_uint16(buf->last,
+ NGX_HTTP_V2_MAX_STREAMS_SETTING);
+ buf->last = ngx_http_v2_write_uint32(buf->last,
+ h2scf->concurrent_streams);
+
+ buf->last = ngx_http_v2_write_uint16(buf->last,
NGX_HTTP_V2_INIT_WINDOW_SIZE_SETTING);
- buf->last = ngx_http_v2_write_uint32(buf->last, h2scf->preread_size);
-
- buf->last = ngx_http_v2_write_uint16(buf->last,
- NGX_HTTP_V2_MAX_FRAME_SIZE_SETTING);
- buf->last = ngx_http_v2_write_uint32(buf->last,
- NGX_HTTP_V2_MAX_FRAME_SIZE);
- }
+ buf->last = ngx_http_v2_write_uint32(buf->last, h2scf->preread_size);
+
+ buf->last = ngx_http_v2_write_uint16(buf->last,
+ NGX_HTTP_V2_MAX_FRAME_SIZE_SETTING);
+ buf->last = ngx_http_v2_write_uint32(buf->last,
+ NGX_HTTP_V2_MAX_FRAME_SIZE);
ngx_http_v2_queue_blocked_frame(h2c, frame);
More information about the nginx-devel
mailing list