comparison src/http/ngx_http_copy_filter_module.c @ 518:86dad910eeb6 NGINX_0_8_11

nginx 0.8.11 *) Change: directive "gzip_disable msie6" enables gzipping for MSIE 6.0 SV1. *) Feature: file AIO support on FreeBSD and Linux. *) Feature: the "directio_alignment" directive.
author Igor Sysoev <http://sysoev.ru>
date Fri, 28 Aug 2009 00:00:00 +0400
parents e7dbea1ee115
children d41628eb4d0a
comparison
equal deleted inserted replaced
517:15b5cddc5190 518:86dad910eeb6
11 11
12 typedef struct { 12 typedef struct {
13 ngx_bufs_t bufs; 13 ngx_bufs_t bufs;
14 } ngx_http_copy_filter_conf_t; 14 } ngx_http_copy_filter_conf_t;
15 15
16
17 #if (NGX_HAVE_FILE_AIO)
18 static void ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx,
19 ngx_file_t *file);
20 static void ngx_http_copy_aio_event_handler(ngx_event_t *ev);
21 #endif
16 22
17 static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf); 23 static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf);
18 static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf, 24 static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
19 void *parent, void *child); 25 void *parent, void *child);
20 static ngx_int_t ngx_http_copy_filter_init(ngx_conf_t *cf); 26 static ngx_int_t ngx_http_copy_filter_init(ngx_conf_t *cf);
71 ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in) 77 ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
72 { 78 {
73 ngx_int_t rc; 79 ngx_int_t rc;
74 ngx_connection_t *c; 80 ngx_connection_t *c;
75 ngx_output_chain_ctx_t *ctx; 81 ngx_output_chain_ctx_t *ctx;
82 ngx_http_core_loc_conf_t *clcf;
76 ngx_http_copy_filter_conf_t *conf; 83 ngx_http_copy_filter_conf_t *conf;
77 84
78 c = r->connection; 85 c = r->connection;
86
87 if (r->aio) {
88 return NGX_AGAIN;
89 }
79 90
80 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, 91 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
81 "copy filter: \"%V?%V\"", &r->uri, &r->args); 92 "copy filter: \"%V?%V\"", &r->uri, &r->args);
82 93
83 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module); 94 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module);
84 95
85 if (ctx == NULL) { 96 if (ctx == NULL) {
86 conf = ngx_http_get_module_loc_conf(r, ngx_http_copy_filter_module);
87
88 ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)); 97 ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
89 if (ctx == NULL) { 98 if (ctx == NULL) {
90 return NGX_ERROR; 99 return NGX_ERROR;
91 } 100 }
92 101
93 ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module); 102 ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module);
94 103
104 conf = ngx_http_get_module_loc_conf(r, ngx_http_copy_filter_module);
105 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
106
95 ctx->sendfile = c->sendfile; 107 ctx->sendfile = c->sendfile;
96 ctx->need_in_memory = r->main_filter_need_in_memory 108 ctx->need_in_memory = r->main_filter_need_in_memory
97 || r->filter_need_in_memory; 109 || r->filter_need_in_memory;
98 ctx->need_in_temp = r->filter_need_temporary; 110 ctx->need_in_temp = r->filter_need_temporary;
99 111
112 ctx->alignment = clcf->directio_alignment;
113
100 ctx->pool = r->pool; 114 ctx->pool = r->pool;
101 ctx->bufs = conf->bufs; 115 ctx->bufs = conf->bufs;
102 ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module; 116 ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module;
103 117
104 ctx->output_filter = (ngx_output_chain_filter_pt) ngx_http_next_filter; 118 ctx->output_filter = (ngx_output_chain_filter_pt) ngx_http_next_filter;
105 ctx->filter_ctx = r; 119 ctx->filter_ctx = r;
106 120
121 #if (NGX_HAVE_FILE_AIO)
122 if (clcf->aio) {
123 ctx->aio = ngx_http_copy_aio_handler;
124 }
125 #endif
126
107 r->request_output = 1; 127 r->request_output = 1;
108 } 128 }
109 129
110 rc = ngx_output_chain(ctx, in); 130 rc = ngx_output_chain(ctx, in);
111 131
112 if (!c->destroyed) { 132 if (ctx->in == NULL) {
113 133 r->buffered &= ~NGX_HTTP_COPY_BUFFERED;
114 if (ctx->in == NULL) { 134
115 r->buffered &= ~NGX_HTTP_COPY_BUFFERED; 135 } else {
116 } else { 136 r->buffered |= NGX_HTTP_COPY_BUFFERED;
117 r->buffered |= NGX_HTTP_COPY_BUFFERED; 137 }
118 } 138
119 139 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
120 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 140 "copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
121 "copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
122 }
123 141
124 return rc; 142 return rc;
125 } 143 }
144
145
146 #if (NGX_HAVE_FILE_AIO)
147
148 static void
149 ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx, ngx_file_t *file)
150 {
151 ngx_http_request_t *r;
152
153 r = ctx->filter_ctx;
154
155 file->aio->data = r;
156 file->aio->handler = ngx_http_copy_aio_event_handler;
157
158 r->main->blocked++;
159 r->aio = 1;
160 }
161
162
163 static void
164 ngx_http_copy_aio_event_handler(ngx_event_t *ev)
165 {
166 ngx_event_aio_t *aio;
167 ngx_http_request_t *r;
168
169 aio = ev->data;
170 r = aio->data;
171
172 r->main->blocked--;
173 r->aio = 0;
174
175 r->connection->write->handler(r->connection->write);
176 }
177
178 #endif
126 179
127 180
128 static void * 181 static void *
129 ngx_http_copy_filter_create_conf(ngx_conf_t *cf) 182 ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
130 { 183 {