comparison src/http/ngx_http_copy_filter_module.c @ 531:d41628eb4d0a NGINX_0_8_12

nginx 0.8.12 *) Feature: the "sendfile" parameter in the "aio" directive on FreeBSD. *) Bugfix: in try_files; the bug had appeared in 0.8.11. *) Bugfix: in memcached; the bug had appeared in 0.8.11.
author Igor Sysoev <http://sysoev.ru>
date Mon, 31 Aug 2009 00:00:00 +0400
parents 86dad910eeb6
children 1bc8c12d80ec
comparison
equal deleted inserted replaced
530:1fd1b769cd78 531:d41628eb4d0a
16 16
17 #if (NGX_HAVE_FILE_AIO) 17 #if (NGX_HAVE_FILE_AIO)
18 static void ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx, 18 static void ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx,
19 ngx_file_t *file); 19 ngx_file_t *file);
20 static void ngx_http_copy_aio_event_handler(ngx_event_t *ev); 20 static void ngx_http_copy_aio_event_handler(ngx_event_t *ev);
21 #if (NGX_HAVE_AIO_SENDFILE)
22 static void ngx_http_copy_aio_sendfile_event_handler(ngx_event_t *ev);
23 #endif
21 #endif 24 #endif
22 25
23 static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf); 26 static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf);
24 static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf, 27 static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
25 void *parent, void *child); 28 void *parent, void *child);
87 if (r->aio) { 90 if (r->aio) {
88 return NGX_AGAIN; 91 return NGX_AGAIN;
89 } 92 }
90 93
91 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, 94 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
92 "copy filter: \"%V?%V\"", &r->uri, &r->args); 95 "http copy filter: \"%V?%V\"", &r->uri, &r->args);
93 96
94 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module); 97 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module);
95 98
96 if (ctx == NULL) { 99 if (ctx == NULL) {
97 ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)); 100 ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
119 ctx->filter_ctx = r; 122 ctx->filter_ctx = r;
120 123
121 #if (NGX_HAVE_FILE_AIO) 124 #if (NGX_HAVE_FILE_AIO)
122 if (clcf->aio) { 125 if (clcf->aio) {
123 ctx->aio = ngx_http_copy_aio_handler; 126 ctx->aio = ngx_http_copy_aio_handler;
127 #if (NGX_HAVE_AIO_SENDFILE)
128 c->aio_sendfile = (clcf->aio == NGX_HTTP_AIO_SENDFILE);
129 #endif
124 } 130 }
125 #endif 131 #endif
126 132
127 r->request_output = 1; 133 r->request_output = 1;
128 } 134 }
134 140
135 } else { 141 } else {
136 r->buffered |= NGX_HTTP_COPY_BUFFERED; 142 r->buffered |= NGX_HTTP_COPY_BUFFERED;
137 } 143 }
138 144
139 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 145 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
140 "copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args); 146 "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
147
148 #if (NGX_HAVE_AIO_SENDFILE)
149
150 if (c->busy_sendfile) {
151 off_t offset;
152 ngx_file_t *file;
153 ngx_http_ephemeral_t *e;
154
155 file = c->busy_sendfile->file;
156 offset = c->busy_sendfile->file_pos;
157
158 if (file->aio) {
159 c->aio_sendfile = (offset != file->aio->last_offset);
160 file->aio->last_offset = offset;
161
162 if (c->aio_sendfile == 0) {
163 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
164 "sendfile(%V) returned busy again", &file->name);
165 }
166 }
167
168 c->busy_sendfile = NULL;
169 e = (ngx_http_ephemeral_t *) &r->uri_start;
170
171 (void) ngx_file_aio_read(file, e->preload, 4, offset, r->pool);
172
173 if (file->aio) {
174 file->aio->data = r;
175 file->aio->handler = ngx_http_copy_aio_sendfile_event_handler;
176
177 r->main->blocked++;
178 r->aio = 1;
179 }
180 }
181
182 #endif
141 183
142 return rc; 184 return rc;
143 } 185 }
144 186
145 187
173 r->aio = 0; 215 r->aio = 0;
174 216
175 r->connection->write->handler(r->connection->write); 217 r->connection->write->handler(r->connection->write);
176 } 218 }
177 219
220
221 #if (NGX_HAVE_AIO_SENDFILE)
222
223 static void
224 ngx_http_copy_aio_sendfile_event_handler(ngx_event_t *ev)
225 {
226 ngx_event_aio_t *aio;
227 ngx_http_request_t *r;
228
229 aio = ev->data;
230 r = aio->data;
231
232 r->main->blocked--;
233 r->aio = 0;
234 ev->complete = 0;
235
236 r->connection->write->handler(r->connection->write);
237 }
238
239 #endif
178 #endif 240 #endif
179 241
180 242
181 static void * 243 static void *
182 ngx_http_copy_filter_create_conf(ngx_conf_t *cf) 244 ngx_http_copy_filter_create_conf(ngx_conf_t *cf)