comparison src/http/ngx_http_write_filter.c @ 154:eac26585476e

nginx-0.0.1-2003-10-22-11:05:29 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 22 Oct 2003 07:05:29 +0000
parents c71aeb75c071
children 46eb23d9471d
comparison
equal deleted inserted replaced
153:c71aeb75c071 154:eac26585476e
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 #include <ngx_event.h> 4 #include <ngx_event.h>
5 #include <ngx_http.h> 5 #include <ngx_http.h>
6
7
8 typedef struct {
9 ssize_t buffer_output;
10 } ngx_http_write_filter_conf_t;
6 11
7 12
8 typedef struct { 13 typedef struct {
9 ngx_chain_t *out; 14 ngx_chain_t *out;
10 } ngx_http_write_filter_ctx_t; 15 } ngx_http_write_filter_ctx_t;
15 void *parent, void *child); 20 void *parent, void *child);
16 static int ngx_http_write_filter_init(ngx_cycle_t *cycle); 21 static int ngx_http_write_filter_init(ngx_cycle_t *cycle);
17 22
18 23
19 static ngx_command_t ngx_http_write_filter_commands[] = { 24 static ngx_command_t ngx_http_write_filter_commands[] = {
20
21 {ngx_string("sendfile"),
22 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
23 ngx_conf_set_flag_slot,
24 NGX_HTTP_LOC_CONF_OFFSET,
25 offsetof(ngx_http_write_filter_conf_t, sendfile),
26 NULL},
27 25
28 {ngx_string("buffer_output"), 26 {ngx_string("buffer_output"),
29 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 27 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
30 ngx_conf_set_size_slot, 28 ngx_conf_set_size_slot,
31 NGX_HTTP_LOC_CONF_OFFSET, 29 NGX_HTTP_LOC_CONF_OFFSET,
92 if (ce->hunk->type & NGX_HUNK_LAST) { 90 if (ce->hunk->type & NGX_HUNK_LAST) {
93 last = 1; 91 last = 1;
94 } 92 }
95 } 93 }
96 94
97 conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
98 ngx_http_write_filter_module);
99
100 /* add the new chain to the existent one */ 95 /* add the new chain to the existent one */
101 96
102 for (/* void */; in; in = in->next) { 97 for (/* void */; in; in = in->next) {
103 ngx_test_null(ce, ngx_alloc_chain_entry(r->pool), NGX_ERROR); 98 ngx_test_null(ce, ngx_alloc_chain_entry(r->pool), NGX_ERROR);
104 99
105 ce->hunk = in->hunk; 100 ce->hunk = in->hunk;
106 ce->next = NULL; 101 ce->next = NULL;
107 *le = ce; 102 *le = ce;
108 le = &ce->next; 103 le = &ce->next;
109
110 if (!(ngx_io.flags & NGX_IO_SENDFILE) || !conf->sendfile) {
111 ce->hunk->type &= ~NGX_HUNK_FILE;
112 }
113 104
114 size += ngx_hunk_size(ce->hunk); 105 size += ngx_hunk_size(ce->hunk);
115 106
116 if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { 107 if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) {
117 flush = size; 108 flush = size;
125 #if (NGX_DEBUG_WRITE_FILTER) 116 #if (NGX_DEBUG_WRITE_FILTER)
126 ngx_log_debug(r->connection->log, 117 ngx_log_debug(r->connection->log,
127 "write filter: last:%d flush:%qd size:%qd" _ 118 "write filter: last:%d flush:%qd size:%qd" _
128 last _ flush _ size); 119 last _ flush _ size);
129 #endif 120 #endif
121
122 conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
123 ngx_http_write_filter_module);
130 124
131 /* 125 /*
132 * avoid the output if there is no last hunk, no flush point and 126 * avoid the output if there is no last hunk, no flush point and
133 * size of the hunks is smaller then "buffer_output" 127 * size of the hunks is smaller then "buffer_output"
134 */ 128 */
172 ngx_test_null(conf, 166 ngx_test_null(conf,
173 ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)), 167 ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)),
174 NULL); 168 NULL);
175 169
176 conf->buffer_output = NGX_CONF_UNSET; 170 conf->buffer_output = NGX_CONF_UNSET;
177 conf->sendfile = NGX_CONF_UNSET;
178 171
179 return conf; 172 return conf;
180 } 173 }
181 174
182 175
185 { 178 {
186 ngx_http_write_filter_conf_t *prev = parent; 179 ngx_http_write_filter_conf_t *prev = parent;
187 ngx_http_write_filter_conf_t *conf = child; 180 ngx_http_write_filter_conf_t *conf = child;
188 181
189 ngx_conf_merge_size_value(conf->buffer_output, prev->buffer_output, 1460); 182 ngx_conf_merge_size_value(conf->buffer_output, prev->buffer_output, 1460);
190 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
191 183
192 return NULL; 184 return NULL;
193 } 185 }
194 186
195 187