comparison src/http/ngx_http_copy_filter_module.c @ 3052:6060225e9261

FreeBSD and Linux AIO support
author Igor Sysoev <igor@sysoev.ru>
date Fri, 28 Aug 2009 08:12:35 +0000
parents f54b02dbb12b
children 0d253659da12
comparison
equal deleted inserted replaced
3051:26dfc0fa22c8 3052:6060225e9261
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);
102 ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module; 113 ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module;
103 114
104 ctx->output_filter = (ngx_output_chain_filter_pt) ngx_http_next_filter; 115 ctx->output_filter = (ngx_output_chain_filter_pt) ngx_http_next_filter;
105 ctx->filter_ctx = r; 116 ctx->filter_ctx = r;
106 117
118 #if (NGX_HAVE_FILE_AIO)
119 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
120 if (clcf->aio) {
121 ctx->aio = ngx_http_copy_aio_handler;
122 }
123 #endif
124
107 r->request_output = 1; 125 r->request_output = 1;
108 } 126 }
109 127
110 rc = ngx_output_chain(ctx, in); 128 rc = ngx_output_chain(ctx, in);
111 129
119 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 137 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
120 "copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args); 138 "copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args);
121 139
122 return rc; 140 return rc;
123 } 141 }
142
143
144 #if (NGX_HAVE_FILE_AIO)
145
146 static void
147 ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx, ngx_file_t *file)
148 {
149 ngx_http_request_t *r;
150
151 r = ctx->filter_ctx;
152
153 file->aio->data = r;
154 file->aio->handler = ngx_http_copy_aio_event_handler;
155
156 r->main->blocked++;
157 r->aio = 1;
158 }
159
160
161 static void
162 ngx_http_copy_aio_event_handler(ngx_event_t *ev)
163 {
164 ngx_event_aio_t *aio;
165 ngx_http_request_t *r;
166
167 aio = ev->data;
168 r = aio->data;
169
170 r->main->blocked--;
171 r->aio = 0;
172
173 r->connection->write->handler(r->connection->write);
174 }
175
176 #endif
124 177
125 178
126 static void * 179 static void *
127 ngx_http_copy_filter_create_conf(ngx_conf_t *cf) 180 ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
128 { 181 {