[nginx] SPDY: store the length of frame instead of its whole size.
Valentin Bartenev
vbart at nginx.com
Wed Jan 22 03:10:15 UTC 2014
details: http://hg.nginx.org/nginx/rev/e4adaa47af65
branches:
changeset: 5529:e4adaa47af65
user: Valentin Bartenev <vbart at nginx.com>
date: Wed Jan 22 04:58:19 2014 +0400
description:
SPDY: store the length of frame instead of its whole size.
The "length" value better corresponds with the specification and reduces
confusion about whether frame's header is included in "size" or not.
Also this change simplifies some parts of code, since in more cases the
length of frame is more useful than its actual size, especially considering
that the size of frame header is constant.
diffstat:
src/http/ngx_http_spdy.c | 20 +++++++++-----------
src/http/ngx_http_spdy.h | 2 +-
src/http/ngx_http_spdy_filter_module.c | 19 ++++++++++---------
3 files changed, 20 insertions(+), 21 deletions(-)
diffs (134 lines):
diff -r d5de6c25b759 -r e4adaa47af65 src/http/ngx_http_spdy.c
--- a/src/http/ngx_http_spdy.c Wed Jan 22 04:58:19 2014 +0400
+++ b/src/http/ngx_http_spdy.c Wed Jan 22 04:58:19 2014 +0400
@@ -494,9 +494,9 @@ ngx_http_spdy_send_output_queue(ngx_http
out = frame;
ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "spdy frame out: %p sid:%ui prio:%ui bl:%d size:%uz",
+ "spdy frame out: %p sid:%ui prio:%ui bl:%d len:%uz",
out, out->stream ? out->stream->id : 0, out->priority,
- out->blocked, out->size);
+ out->blocked, out->length);
}
cl = c->send_chain(c, cl, 0);
@@ -537,9 +537,9 @@ ngx_http_spdy_send_output_queue(ngx_http
}
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "spdy frame sent: %p sid:%ui bl:%d size:%uz",
+ "spdy frame sent: %p sid:%ui bl:%d len:%uz",
out, out->stream ? out->stream->id : 0,
- out->blocked, out->size);
+ out->blocked, out->length);
}
frame = NULL;
@@ -1587,9 +1587,7 @@ ngx_http_spdy_send_settings(ngx_http_spd
frame->handler = ngx_http_spdy_settings_frame_handler;
frame->stream = NULL;
#if (NGX_DEBUG)
- frame->size = NGX_SPDY_FRAME_HEADER_SIZE
- + NGX_SPDY_SETTINGS_NUM_SIZE
- + NGX_SPDY_SETTINGS_PAIR_SIZE;
+ frame->length = NGX_SPDY_SETTINGS_NUM_SIZE + NGX_SPDY_SETTINGS_PAIR_SIZE;
#endif
frame->priority = NGX_SPDY_HIGHEST_PRIORITY;
frame->blocked = 0;
@@ -1637,7 +1635,7 @@ ngx_http_spdy_settings_frame_handler(ngx
static ngx_http_spdy_out_frame_t *
-ngx_http_spdy_get_ctl_frame(ngx_http_spdy_connection_t *sc, size_t size,
+ngx_http_spdy_get_ctl_frame(ngx_http_spdy_connection_t *sc, size_t length,
ngx_uint_t priority)
{
ngx_chain_t *cl;
@@ -1677,13 +1675,13 @@ ngx_http_spdy_get_ctl_frame(ngx_http_spd
}
#if (NGX_DEBUG)
- if (size > NGX_SPDY_CTL_FRAME_BUFFER_SIZE - NGX_SPDY_FRAME_HEADER_SIZE) {
+ if (length > NGX_SPDY_CTL_FRAME_BUFFER_SIZE - NGX_SPDY_FRAME_HEADER_SIZE) {
ngx_log_error(NGX_LOG_ALERT, sc->pool->log, 0,
- "requested control frame is too big: %uz", size);
+ "requested control frame is too big: %uz", length);
return NULL;
}
- frame->size = size;
+ frame->length = length;
#endif
frame->priority = priority;
diff -r d5de6c25b759 -r e4adaa47af65 src/http/ngx_http_spdy.h
--- a/src/http/ngx_http_spdy.h Wed Jan 22 04:58:19 2014 +0400
+++ b/src/http/ngx_http_spdy.h Wed Jan 22 04:58:19 2014 +0400
@@ -142,7 +142,7 @@ struct ngx_http_spdy_out_frame_s {
ngx_http_spdy_out_frame_t *frame);
ngx_http_spdy_stream_t *stream;
- size_t size;
+ size_t length;
ngx_uint_t priority;
unsigned blocked:1;
diff -r d5de6c25b759 -r e4adaa47af65 src/http/ngx_http_spdy_filter_module.c
--- a/src/http/ngx_http_spdy_filter_module.c Wed Jan 22 04:58:19 2014 +0400
+++ b/src/http/ngx_http_spdy_filter_module.c Wed Jan 22 04:58:19 2014 +0400
@@ -560,13 +560,14 @@ ngx_http_spdy_header_filter(ngx_http_req
r->header_size = len;
+ len -= NGX_SPDY_FRAME_HEADER_SIZE;
+
if (r->header_only) {
b->last_buf = 1;
- p = ngx_spdy_frame_write_flags_and_len(p, NGX_SPDY_FLAG_FIN,
- len - NGX_SPDY_FRAME_HEADER_SIZE);
+ p = ngx_spdy_frame_write_flags_and_len(p, NGX_SPDY_FLAG_FIN, len);
+
} else {
- p = ngx_spdy_frame_write_flags_and_len(p, 0,
- len - NGX_SPDY_FRAME_HEADER_SIZE);
+ p = ngx_spdy_frame_write_flags_and_len(p, 0, len);
}
(void) ngx_spdy_frame_write_sid(p, stream->id);
@@ -588,14 +589,14 @@ ngx_http_spdy_header_filter(ngx_http_req
frame->last = cl;
frame->handler = ngx_http_spdy_syn_frame_handler;
frame->stream = stream;
- frame->size = len;
+ frame->length = len;
frame->priority = stream->priority;
frame->blocked = 1;
frame->fin = r->header_only;
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, stream->request->connection->log, 0,
- "spdy:%ui create SYN_REPLY frame %p: size:%uz",
- stream->id, frame, frame->size);
+ "spdy:%ui create SYN_REPLY frame %p: len:%uz",
+ stream->id, frame, frame->length);
ngx_http_spdy_queue_blocked_frame(sc, frame);
@@ -881,7 +882,7 @@ ngx_http_spdy_filter_get_data_frame(ngx_
frame->last = last;
frame->handler = ngx_http_spdy_data_frame_handler;
frame->stream = stream;
- frame->size = NGX_SPDY_FRAME_HEADER_SIZE + len;
+ frame->length = len;
frame->priority = stream->priority;
frame->blocked = 0;
frame->fin = last->buf->last_buf;
@@ -1043,7 +1044,7 @@ ngx_http_spdy_handle_frame(ngx_http_spdy
r = stream->request;
- r->connection->sent += frame->size;
+ r->connection->sent += NGX_SPDY_FRAME_HEADER_SIZE + frame->length;
if (frame->fin) {
stream->out_closed = 1;
More information about the nginx-devel
mailing list