Mercurial > hg > nginx
comparison src/http/ngx_http_write_filter.c @ 44:0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 09 Jan 2003 05:36:00 +0000 |
parents | 53cd05892261 |
children | f1ee46c036a4 |
comparison
equal
deleted
inserted
replaced
43:53cd05892261 | 44:0e81ac0bb3e2 |
---|---|
11 #include <ngx_http_config.h> | 11 #include <ngx_http_config.h> |
12 #include <ngx_http_write_filter.h> | 12 #include <ngx_http_write_filter.h> |
13 | 13 |
14 | 14 |
15 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool); | 15 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool); |
16 static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool, | |
17 void *parent, void *child); | |
16 | 18 |
17 | 19 |
18 static ngx_command_t ngx_http_write_filter_commands[] = { | 20 static ngx_command_t ngx_http_write_filter_commands[] = { |
19 | 21 |
20 {ngx_string("write_buffer"), | 22 {ngx_string("write_buffer"), |
21 NGX_CONF_TAKE1, | 23 NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, |
22 ngx_conf_set_size_slot, | 24 ngx_conf_set_size_slot, |
23 NGX_HTTP_LOC_CONF, | 25 NGX_HTTP_LOC_CONF_OFFSET, |
24 offsetof(ngx_http_write_filter_conf_t, buffer_output)}, | 26 offsetof(ngx_http_write_filter_conf_t, buffer_output)}, |
25 | 27 |
26 {ngx_string(""), 0, NULL, 0, 0} | 28 {ngx_string(""), 0, NULL, 0, 0} |
27 }; | 29 }; |
28 | 30 |
31 NGX_HTTP_MODULE, | 33 NGX_HTTP_MODULE, |
32 | 34 |
33 NULL, /* create server config */ | 35 NULL, /* create server config */ |
34 NULL, /* init server config */ | 36 NULL, /* init server config */ |
35 ngx_http_write_filter_create_conf, /* create location config */ | 37 ngx_http_write_filter_create_conf, /* create location config */ |
36 NULL, /* merge location config */ | 38 ngx_http_write_filter_merge_conf, /* merge location config */ |
37 | 39 |
38 NULL, /* translate handler */ | 40 NULL, /* translate handler */ |
39 | 41 |
40 NULL, /* output header filter */ | 42 NULL, /* output header filter */ |
41 NULL, /* next output header filter */ | 43 NULL, /* next output header filter */ |
43 NULL, /* next output body filter */ | 45 NULL, /* next output body filter */ |
44 }; | 46 }; |
45 | 47 |
46 | 48 |
47 ngx_module_t ngx_http_write_filter_module = { | 49 ngx_module_t ngx_http_write_filter_module = { |
50 0, /* module index */ | |
48 &ngx_http_write_filter_module_ctx, /* module context */ | 51 &ngx_http_write_filter_module_ctx, /* module context */ |
49 ngx_http_write_filter_commands, /* module directives */ | 52 ngx_http_write_filter_commands, /* module directives */ |
50 NGX_HTTP_MODULE_TYPE, /* module type */ | 53 NGX_HTTP_MODULE_TYPE, /* module type */ |
51 NULL /* init module */ | 54 NULL /* init module */ |
52 }; | 55 }; |
77 /* find size, flush point and last link of saved chain */ | 80 /* find size, flush point and last link of saved chain */ |
78 for (ch = ctx->out; ch; ch = ch->next) { | 81 for (ch = ctx->out; ch; ch = ch->next) { |
79 prev = &ch->next; | 82 prev = &ch->next; |
80 size += ch->hunk->last.file - ch->hunk->pos.file; | 83 size += ch->hunk->last.file - ch->hunk->pos.file; |
81 | 84 |
82 ngx_log_debug(r->connection->log, "old chunk: %x " QX_FMT " " QD_FMT _ | 85 #if (NGX_DEBUG_WRITE_FILTER) |
86 ngx_log_debug(r->connection->log, "write filter: old chunk: %x " | |
87 QX_FMT " " QD_FMT _ | |
83 ch->hunk->type _ ch->hunk->pos.file _ | 88 ch->hunk->type _ ch->hunk->pos.file _ |
84 ch->hunk->last.file - ch->hunk->pos.file); | 89 ch->hunk->last.file - ch->hunk->pos.file); |
90 #endif | |
85 | 91 |
86 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { | 92 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { |
87 flush = size; | 93 flush = size; |
88 } | 94 } |
89 | 95 |
100 ch->next = NULL; | 106 ch->next = NULL; |
101 *prev = ch; | 107 *prev = ch; |
102 prev = &ch->next; | 108 prev = &ch->next; |
103 size += ch->hunk->last.file - ch->hunk->pos.file; | 109 size += ch->hunk->last.file - ch->hunk->pos.file; |
104 | 110 |
105 ngx_log_debug(r->connection->log, "new chunk: %x " QX_FMT " " QD_FMT _ | 111 #if (NGX_DEBUG_WRITE_FILTER) |
112 ngx_log_debug(r->connection->log, "write filter: new chunk: %x " | |
113 QX_FMT " " QD_FMT _ | |
106 ch->hunk->type _ ch->hunk->pos.file _ | 114 ch->hunk->type _ ch->hunk->pos.file _ |
107 ch->hunk->last.file - ch->hunk->pos.file); | 115 ch->hunk->last.file - ch->hunk->pos.file); |
116 #endif | |
108 | 117 |
109 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { | 118 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { |
110 flush = size; | 119 flush = size; |
111 } | 120 } |
112 | 121 |
117 | 126 |
118 conf = (ngx_http_write_filter_conf_t *) | 127 conf = (ngx_http_write_filter_conf_t *) |
119 ngx_http_get_module_loc_conf(r->main ? r->main : r, | 128 ngx_http_get_module_loc_conf(r->main ? r->main : r, |
120 ngx_http_write_filter_module_ctx); | 129 ngx_http_write_filter_module_ctx); |
121 | 130 |
122 ngx_log_debug(r->connection->log, "l:%d f:%d" _ last _ flush); | 131 #if (NGX_DEBUG_WRITE_FILTER) |
132 ngx_log_debug(r->connection->log, "write filter: last:%d flush:%d" _ | |
133 last _ flush); | |
134 #endif | |
123 | 135 |
124 if (!last && flush == 0 && size < conf->buffer_output) { | 136 if (!last && flush == 0 && size < conf->buffer_output) { |
125 return NGX_OK; | 137 return NGX_OK; |
126 } | 138 } |
127 | 139 |
148 | 160 |
149 conf->buffer_output = NGX_CONF_UNSET; | 161 conf->buffer_output = NGX_CONF_UNSET; |
150 | 162 |
151 return conf; | 163 return conf; |
152 } | 164 } |
165 | |
166 | |
167 static char *ngx_http_write_filter_merge_conf(ngx_pool_t *pool, | |
168 void *parent, void *child) | |
169 { | |
170 ngx_http_write_filter_conf_t *prev = | |
171 (ngx_http_write_filter_conf_t *) parent; | |
172 ngx_http_write_filter_conf_t *conf = | |
173 (ngx_http_write_filter_conf_t *) child; | |
174 | |
175 ngx_conf_merge(conf->buffer_output, prev->buffer_output, 1460); | |
176 | |
177 return NULL; | |
178 } | |
179 |