[nginx] SPDY: use frame->next pointer to chain free frames.

Valentin Bartenev vbart at nginx.com
Wed Jan 22 03:10:13 UTC 2014


details:   http://hg.nginx.org/nginx/rev/d5de6c25b759
branches:  
changeset: 5528:d5de6c25b759
user:      Valentin Bartenev <vbart at nginx.com>
date:      Wed Jan 22 04:58:19 2014 +0400
description:
SPDY: use frame->next pointer to chain free frames.

There is no need in separate "free" pointer and like it is for ngx_chain_t
the "next" pointer can be used.  But after this change successfully handled
frame should not be accessed, so the frame handling cycle was improved to
store pointer to the next frame before processing.

Also worth noting that initializing "free" pointer to NULL in the original
code was surplus.

diffstat:

 src/http/ngx_http_spdy.c               |  10 +++++-----
 src/http/ngx_http_spdy.h               |   2 --
 src/http/ngx_http_spdy_filter_module.c |   6 ++----
 3 files changed, 7 insertions(+), 11 deletions(-)

diffs (90 lines):

diff -r f3f7b72ca6e9 -r d5de6c25b759 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
@@ -527,7 +527,9 @@ ngx_http_spdy_send_output_queue(ngx_http
         }
     }
 
-    for ( /* void */ ; out; out = out->next) {
+    for ( /* void */ ; out; out = fn) {
+        fn = out->next;
+
         if (out->handler(sc, out) != NGX_OK) {
             out->blocked = 1;
             out->priority = NGX_SPDY_HIGHEST_PRIORITY;
@@ -1644,7 +1646,7 @@ ngx_http_spdy_get_ctl_frame(ngx_http_spd
     frame = sc->free_ctl_frames;
 
     if (frame) {
-        sc->free_ctl_frames = frame->free;
+        sc->free_ctl_frames = frame->next;
 
         cl = frame->first;
         cl->buf->pos = cl->buf->start;
@@ -1674,8 +1676,6 @@ ngx_http_spdy_get_ctl_frame(ngx_http_spd
         frame->stream = NULL;
     }
 
-    frame->free = NULL;
-
 #if (NGX_DEBUG)
     if (size > NGX_SPDY_CTL_FRAME_BUFFER_SIZE - NGX_SPDY_FRAME_HEADER_SIZE) {
         ngx_log_error(NGX_LOG_ALERT, sc->pool->log, 0,
@@ -1705,7 +1705,7 @@ ngx_http_spdy_ctl_frame_handler(ngx_http
         return NGX_AGAIN;
     }
 
-    frame->free = sc->free_ctl_frames;
+    frame->next = sc->free_ctl_frames;
     sc->free_ctl_frames = frame;
 
     return NGX_OK;
diff -r f3f7b72ca6e9 -r d5de6c25b759 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
@@ -141,8 +141,6 @@ struct ngx_http_spdy_out_frame_s {
     ngx_int_t                      (*handler)(ngx_http_spdy_connection_t *sc,
                                         ngx_http_spdy_out_frame_t *frame);
 
-    ngx_http_spdy_out_frame_t       *free;
-
     ngx_http_spdy_stream_t          *stream;
     size_t                           size;
 
diff -r f3f7b72ca6e9 -r d5de6c25b759 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
@@ -587,7 +587,6 @@ ngx_http_spdy_header_filter(ngx_http_req
     frame->first = cl;
     frame->last = cl;
     frame->handler = ngx_http_spdy_syn_frame_handler;
-    frame->free = NULL;
     frame->stream = stream;
     frame->size = len;
     frame->priority = stream->priority;
@@ -821,7 +820,7 @@ ngx_http_spdy_filter_get_data_frame(ngx_
     frame = stream->free_frames;
 
     if (frame) {
-        stream->free_frames = frame->free;
+        stream->free_frames = frame->next;
 
     } else {
         frame = ngx_palloc(stream->request->pool,
@@ -881,7 +880,6 @@ ngx_http_spdy_filter_get_data_frame(ngx_
     frame->first = first;
     frame->last = last;
     frame->handler = ngx_http_spdy_data_frame_handler;
-    frame->free = NULL;
     frame->stream = stream;
     frame->size = NGX_SPDY_FRAME_HEADER_SIZE + len;
     frame->priority = stream->priority;
@@ -1051,7 +1049,7 @@ ngx_http_spdy_handle_frame(ngx_http_spdy
         stream->out_closed = 1;
     }
 
-    frame->free = stream->free_frames;
+    frame->next = stream->free_frames;
     stream->free_frames = frame;
 
     stream->queued--;



More information about the nginx-devel mailing list