annotate src/http/ngx_http_copy_filter_module.c @ 535:80f7156c2965 NGINX_0_8_14

nginx 0.8.14 *) Bugfix: an expired cached response might stick in the "UPDATING" state. *) Bugfix: a segmentation fault might occur in worker process, if error_log was set to info or debug level. Thanks to Sergey Bochenkov. *) Bugfix: in embedded perl module; the bug had appeared in 0.8.11. *) Bugfix: an "error_page" directive did not redirect a 413 error; the bug had appeared in 0.6.10.
author Igor Sysoev <http://sysoev.ru>
date Mon, 07 Sep 2009 00:00:00 +0400
parents 1bc8c12d80ec
children 0161f3197817
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 typedef struct {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 ngx_bufs_t bufs;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 } ngx_http_copy_filter_conf_t;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
17 #if (NGX_HAVE_FILE_AIO)
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
18 static void ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx,
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
19 ngx_file_t *file);
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
20 static void ngx_http_copy_aio_event_handler(ngx_event_t *ev);
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
21 #if (NGX_HAVE_AIO_SENDFILE)
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
22 static void ngx_http_copy_aio_sendfile_event_handler(ngx_event_t *ev);
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
23 #endif
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
24 #endif
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
25
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 void *parent, void *child);
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
29 static ngx_int_t ngx_http_copy_filter_init(ngx_conf_t *cf);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 static ngx_command_t ngx_http_copy_filter_commands[] = {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 { ngx_string("output_buffers"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 ngx_conf_set_bufs_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 offsetof(ngx_http_copy_filter_conf_t, bufs),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 NULL },
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 ngx_null_command
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 static ngx_http_module_t ngx_http_copy_filter_module_ctx = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
46 NULL, /* preconfiguration */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
47 ngx_http_copy_filter_init, /* postconfiguration */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 NULL, /* create main configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50 NULL, /* init main configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 NULL, /* create server configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53 NULL, /* merge server configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 ngx_http_copy_filter_create_conf, /* create location configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 ngx_http_copy_filter_merge_conf /* merge location configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 ngx_module_t ngx_http_copy_filter_module = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
61 NGX_MODULE_V1,
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 &ngx_http_copy_filter_module_ctx, /* module context */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 ngx_http_copy_filter_commands, /* module directives */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 NGX_HTTP_MODULE, /* module type */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
65 NULL, /* init master */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
66 NULL, /* init module */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
67 NULL, /* init process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
68 NULL, /* init thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
69 NULL, /* exit thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
70 NULL, /* exit process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
71 NULL, /* exit master */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
72 NGX_MODULE_V1_PADDING
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 static ngx_http_output_body_filter_pt ngx_http_next_filter;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 static ngx_int_t
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
82 ngx_int_t rc;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
83 ngx_connection_t *c;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 ngx_output_chain_ctx_t *ctx;
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
85 ngx_http_core_loc_conf_t *clcf;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86 ngx_http_copy_filter_conf_t *conf;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
88 c = r->connection;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
89
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
90 if (r->aio) {
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
91 return NGX_AGAIN;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
92 }
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
93
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
94 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
95 "http copy filter: \"%V?%V\"", &r->uri, &r->args);
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
96
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
97 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 if (ctx == NULL) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100 ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101 if (ctx == NULL) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 return NGX_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
107 conf = ngx_http_get_module_loc_conf(r, ngx_http_copy_filter_module);
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
108 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
109
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
110 ctx->sendfile = c->sendfile;
62
0790a8599248 nginx 0.1.31
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
111 ctx->need_in_memory = r->main_filter_need_in_memory
0790a8599248 nginx 0.1.31
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
112 || r->filter_need_in_memory;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 ctx->need_in_temp = r->filter_need_temporary;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
115 ctx->alignment = clcf->directio_alignment;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
116
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 ctx->pool = r->pool;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 ctx->bufs = conf->bufs;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 ctx->output_filter = (ngx_output_chain_filter_pt) ngx_http_next_filter;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 ctx->filter_ctx = r;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
124 #if (NGX_HAVE_FILE_AIO)
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
125 if (clcf->aio) {
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
126 ctx->aio = ngx_http_copy_aio_handler;
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
127 #if (NGX_HAVE_AIO_SENDFILE)
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
128 c->aio_sendfile = (clcf->aio == NGX_HTTP_AIO_SENDFILE);
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
129 #endif
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
130 }
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
131 #endif
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
132
216
fa32d59d9a15 nginx 0.3.55
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
133 r->request_output = 1;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
136 for ( ;; ) {
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
137 rc = ngx_output_chain(ctx, in);
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
138
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
139 if (ctx->in == NULL) {
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
140 r->buffered &= ~NGX_HTTP_COPY_BUFFERED;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
141
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
142 } else {
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
143 r->buffered |= NGX_HTTP_COPY_BUFFERED;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
144 }
254
f3ec44f4a53b nginx 0.4.12
Igor Sysoev <http://sysoev.ru>
parents: 230
diff changeset
145
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
146 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
147 "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
148
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
149 #if (NGX_HAVE_FILE_AIO && NGX_HAVE_AIO_SENDFILE)
254
f3ec44f4a53b nginx 0.4.12
Igor Sysoev <http://sysoev.ru>
parents: 230
diff changeset
150
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
151 if (c->busy_sendfile) {
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
152 ssize_t n;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
153 off_t offset;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
154 ngx_file_t *file;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
155 ngx_http_ephemeral_t *e;
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
156
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
157 file = c->busy_sendfile->file;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
158 offset = c->busy_sendfile->file_pos;
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
159
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
160 if (file->aio) {
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
161 c->aio_sendfile = (offset != file->aio->last_offset);
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
162 file->aio->last_offset = offset;
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
163
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
164 if (c->aio_sendfile == 0) {
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
165 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
166 "sendfile(%V) returned busy again",
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
167 &file->name);
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
168 }
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
169 }
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
170
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
171 c->busy_sendfile = NULL;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
172 e = (ngx_http_ephemeral_t *) &r->uri_start;
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
173
535
80f7156c2965 nginx 0.8.14
Igor Sysoev <http://sysoev.ru>
parents: 533
diff changeset
174 n = ngx_file_aio_read(file, &e->aio_preload, 1, offset, r->pool);
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
175
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
176 if (n > 0) {
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
177 continue;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
178 }
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
179
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
180 rc = n;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
181
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
182 if (file->aio) {
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
183 file->aio->data = r;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
184 file->aio->handler = ngx_http_copy_aio_sendfile_event_handler;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
185
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
186 r->main->blocked++;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
187 r->aio = 1;
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
188 }
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
189 }
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
190 #endif
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
191
533
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
192 return rc;
1bc8c12d80ec nginx 0.8.13
Igor Sysoev <http://sysoev.ru>
parents: 531
diff changeset
193 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
196
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
197 #if (NGX_HAVE_FILE_AIO)
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
198
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
199 static void
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
200 ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx, ngx_file_t *file)
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
201 {
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
202 ngx_http_request_t *r;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
203
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
204 r = ctx->filter_ctx;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
205
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
206 file->aio->data = r;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
207 file->aio->handler = ngx_http_copy_aio_event_handler;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
208
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
209 r->main->blocked++;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
210 r->aio = 1;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
211 }
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
212
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
213
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
214 static void
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
215 ngx_http_copy_aio_event_handler(ngx_event_t *ev)
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
216 {
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
217 ngx_event_aio_t *aio;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
218 ngx_http_request_t *r;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
219
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
220 aio = ev->data;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
221 r = aio->data;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
222
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
223 r->main->blocked--;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
224 r->aio = 0;
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
225
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
226 r->connection->write->handler(r->connection->write);
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
227 }
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
228
531
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
229
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
230 #if (NGX_HAVE_AIO_SENDFILE)
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
231
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
232 static void
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
233 ngx_http_copy_aio_sendfile_event_handler(ngx_event_t *ev)
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
234 {
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
235 ngx_event_aio_t *aio;
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
236 ngx_http_request_t *r;
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
237
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
238 aio = ev->data;
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
239 r = aio->data;
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
240
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
241 r->main->blocked--;
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
242 r->aio = 0;
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
243 ev->complete = 0;
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
244
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
245 r->connection->write->handler(r->connection->write);
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
246 }
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
247
d41628eb4d0a nginx 0.8.12
Igor Sysoev <http://sysoev.ru>
parents: 529
diff changeset
248 #endif
529
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
249 #endif
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
250
86dad910eeb6 nginx 0.8.11
Igor Sysoev <http://sysoev.ru>
parents: 435
diff changeset
251
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 static void *
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255 ngx_http_copy_filter_conf_t *conf;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 conf = ngx_palloc(cf->pool, sizeof(ngx_http_copy_filter_conf_t));
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258 if (conf == NULL) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259 return NULL;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262 conf->bufs.num = 0;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264 return conf;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 static char *
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269 ngx_http_copy_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 ngx_http_copy_filter_conf_t *prev = parent;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 ngx_http_copy_filter_conf_t *conf = child;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 1, 32768);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276 return NULL;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
279
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 static ngx_int_t
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
281 ngx_http_copy_filter_init(ngx_conf_t *cf)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 ngx_http_next_filter = ngx_http_top_body_filter;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284 ngx_http_top_body_filter = ngx_http_copy_filter;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286 return NGX_OK;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288