comparison src/http/ngx_http_write_filter.c @ 153:c71aeb75c071

nginx-0.0.1-2003-10-21-20:49:56 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 21 Oct 2003 16:49:56 +0000
parents ef8c87afcfc5
children eac26585476e
comparison
equal deleted inserted replaced
152:fb48bf4fea1c 153:c71aeb75c071
4 #include <ngx_event.h> 4 #include <ngx_event.h>
5 #include <ngx_http.h> 5 #include <ngx_http.h>
6 6
7 7
8 typedef struct { 8 typedef struct {
9 ssize_t buffer_output;
10 } ngx_http_write_filter_conf_t;
11
12
13 typedef struct {
14 ngx_chain_t *out; 9 ngx_chain_t *out;
15 } ngx_http_write_filter_ctx_t; 10 } ngx_http_write_filter_ctx_t;
16 11
17 12
18 static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf); 13 static void *ngx_http_write_filter_create_conf(ngx_conf_t *cf);
20 void *parent, void *child); 15 void *parent, void *child);
21 static int ngx_http_write_filter_init(ngx_cycle_t *cycle); 16 static int ngx_http_write_filter_init(ngx_cycle_t *cycle);
22 17
23 18
24 static ngx_command_t ngx_http_write_filter_commands[] = { 19 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},
25 27
26 {ngx_string("buffer_output"), 28 {ngx_string("buffer_output"),
27 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 29 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
28 ngx_conf_set_size_slot, 30 ngx_conf_set_size_slot,
29 NGX_HTTP_LOC_CONF_OFFSET, 31 NGX_HTTP_LOC_CONF_OFFSET,
79 /* find the size, the flush point and the last entry of the saved chain */ 81 /* find the size, the flush point and the last entry of the saved chain */
80 82
81 for (ce = ctx->out; ce; ce = ce->next) { 83 for (ce = ctx->out; ce; ce = ce->next) {
82 le = &ce->next; 84 le = &ce->next;
83 85
84 if (ce->hunk->type & NGX_HUNK_IN_MEMORY) { 86 size += ngx_hunk_size(ce->hunk);
85 size += ce->hunk->last - ce->hunk->pos;
86 } else {
87 size += ce->hunk->file_last - ce->hunk->file_pos;
88 }
89 87
90 if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { 88 if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) {
91 flush = size; 89 flush = size;
92 } 90 }
93 91
94 if (ce->hunk->type & NGX_HUNK_LAST) { 92 if (ce->hunk->type & NGX_HUNK_LAST) {
95 last = 1; 93 last = 1;
96 } 94 }
97 } 95 }
96
97 conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
98 ngx_http_write_filter_module);
98 99
99 /* add the new chain to the existent one */ 100 /* add the new chain to the existent one */
100 101
101 for (/* void */; in; in = in->next) { 102 for (/* void */; in; in = in->next) {
102 ngx_test_null(ce, ngx_alloc_chain_entry(r->pool), NGX_ERROR); 103 ngx_test_null(ce, ngx_alloc_chain_entry(r->pool), NGX_ERROR);
104 ce->hunk = in->hunk; 105 ce->hunk = in->hunk;
105 ce->next = NULL; 106 ce->next = NULL;
106 *le = ce; 107 *le = ce;
107 le = &ce->next; 108 le = &ce->next;
108 109
109 if (ce->hunk->type & NGX_HUNK_IN_MEMORY) { 110 if (!(ngx_io.flags & NGX_IO_SENDFILE) || !conf->sendfile) {
110 size += ce->hunk->last - ce->hunk->pos; 111 ce->hunk->type &= ~NGX_HUNK_FILE;
111 } else { 112 }
112 size += ce->hunk->file_last - ce->hunk->file_pos; 113
113 } 114 size += ngx_hunk_size(ce->hunk);
114 115
115 if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { 116 if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) {
116 flush = size; 117 flush = size;
117 } 118 }
118 119
119 if (ce->hunk->type & NGX_HUNK_LAST) { 120 if (ce->hunk->type & NGX_HUNK_LAST) {
120 last = 1; 121 last = 1;
121 } 122 }
122 } 123 }
123
124 conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
125 ngx_http_write_filter_module);
126 124
127 #if (NGX_DEBUG_WRITE_FILTER) 125 #if (NGX_DEBUG_WRITE_FILTER)
128 ngx_log_debug(r->connection->log, 126 ngx_log_debug(r->connection->log,
129 "write filter: last:%d flush:%qd size:%qd" _ 127 "write filter: last:%d flush:%qd size:%qd" _
130 last _ flush _ size); 128 last _ flush _ size);
174 ngx_test_null(conf, 172 ngx_test_null(conf,
175 ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)), 173 ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)),
176 NULL); 174 NULL);
177 175
178 conf->buffer_output = NGX_CONF_UNSET; 176 conf->buffer_output = NGX_CONF_UNSET;
177 conf->sendfile = NGX_CONF_UNSET;
179 178
180 return conf; 179 return conf;
181 } 180 }
182 181
183 182
186 { 185 {
187 ngx_http_write_filter_conf_t *prev = parent; 186 ngx_http_write_filter_conf_t *prev = parent;
188 ngx_http_write_filter_conf_t *conf = child; 187 ngx_http_write_filter_conf_t *conf = child;
189 188
190 ngx_conf_merge_size_value(conf->buffer_output, prev->buffer_output, 1460); 189 ngx_conf_merge_size_value(conf->buffer_output, prev->buffer_output, 1460);
190 ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
191 191
192 return NULL; 192 return NULL;
193 } 193 }
194 194
195 195