Mercurial > hg > nginx
comparison src/http/ngx_http_copy_filter_module.c @ 3065:113cd532b328
aio sendfile
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 30 Aug 2009 09:52:39 +0000 |
parents | aa720192937b |
children | 6fb94acd3a09 |
comparison
equal
deleted
inserted
replaced
3064:23e6f26fb4bd | 3065:113cd532b328 |
---|---|
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); |
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 } |
137 } | 143 } |
138 | 144 |
139 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | 145 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, |
140 "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args); | 146 "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args); |
141 | 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 | |
183 | |
142 return rc; | 184 return rc; |
143 } | 185 } |
144 | 186 |
145 | 187 |
146 #if (NGX_HAVE_FILE_AIO) | 188 #if (NGX_HAVE_FILE_AIO) |
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) |