comparison src/http/ngx_http_write_filter.c @ 26:53cb81681040

nginx-0.0.1-2002-12-15-09:25:09 import
author Igor Sysoev <igor@sysoev.ru>
date Sun, 15 Dec 2002 06:25:09 +0000
parents 77c7629a2627
children 59e7c7f30d49
comparison
equal deleted inserted replaced
25:a8b156554dfe 26:53cb81681040
7 #include <ngx_http_config.h> 7 #include <ngx_http_config.h>
8 #include <ngx_http_output_filter.h> 8 #include <ngx_http_output_filter.h>
9 #include <ngx_http_write_filter.h> 9 #include <ngx_http_write_filter.h>
10 10
11 11
12 static ngx_command_t ngx_http_write_filter_commands[]; 12 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in);
13 13
14 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool); 14 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool);
15
16
17 static ngx_command_t ngx_http_write_filter_commands[] = {
18
19 {"write_buffer", ngx_conf_set_size_slot,
20 offsetof(ngx_http_write_filter_conf_t, buffer_output),
21 NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1,
22 "set write filter size to buffer output"},
23
24 {NULL}
25
26 };
27
15 28
16 ngx_http_module_t ngx_http_write_filter_module = { 29 ngx_http_module_t ngx_http_write_filter_module = {
17 NGX_HTTP_MODULE, 30 NGX_HTTP_MODULE,
18 31
19 NULL, /* create server config */ 32 NULL, /* create server config */
21 ngx_http_write_filter_commands, /* module directives */ 34 ngx_http_write_filter_commands, /* module directives */
22 35
23 NULL, /* init module */ 36 NULL, /* init module */
24 NULL, /* translate handler */ 37 NULL, /* translate handler */
25 38
26 NULL /* init output body filter */ 39 NULL, /* output header filter */
27 }; 40 NULL, /* next output header filter */
28 41 ngx_http_write_filter, /* output body filter */
29 42 NULL, /* next output body filter */
30 static ngx_command_t ngx_http_write_filter_commands[] = {
31
32 {"write_buffer", ngx_conf_set_size_slot,
33 offsetof(ngx_http_write_filter_conf_t, buffer_output),
34 NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1,
35 "set write filter size to buffer output"},
36
37 {NULL}
38
39 }; 43 };
40 44
41 45
42 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) 46 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
43 { 47 {
67 71
68 ngx_log_debug(r->connection->log, "old chunk: %x " QX_FMT " " QD_FMT _ 72 ngx_log_debug(r->connection->log, "old chunk: %x " QX_FMT " " QD_FMT _
69 ch->hunk->type _ ch->hunk->pos.file _ 73 ch->hunk->type _ ch->hunk->pos.file _
70 ch->hunk->last.file - ch->hunk->pos.file); 74 ch->hunk->last.file - ch->hunk->pos.file);
71 75
72 if (ch->hunk->type & NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED) 76 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED))
73 flush = size; 77 flush = size;
74 78
75 if (ch->hunk->type & NGX_HUNK_LAST) 79 if (ch->hunk->type & NGX_HUNK_LAST)
76 last = 1; 80 last = 1;
77 } 81 }
88 92
89 ngx_log_debug(r->connection->log, "new chunk: %x " QX_FMT " " QD_FMT _ 93 ngx_log_debug(r->connection->log, "new chunk: %x " QX_FMT " " QD_FMT _
90 ch->hunk->type _ ch->hunk->pos.file _ 94 ch->hunk->type _ ch->hunk->pos.file _
91 ch->hunk->last.file - ch->hunk->pos.file); 95 ch->hunk->last.file - ch->hunk->pos.file);
92 96
93 if (ch->hunk->type & NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED) 97 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED))
94 flush = size; 98 flush = size;
95 99
96 if (ch->hunk->type & NGX_HUNK_LAST) 100 if (ch->hunk->type & NGX_HUNK_LAST)
97 last = 1; 101 last = 1;
98 } 102 }
99 103
100 conf = (ngx_http_write_filter_conf_t *) 104 conf = (ngx_http_write_filter_conf_t *)
101 ngx_get_module_loc_conf(r->main ? r->main : r, 105 ngx_get_module_loc_conf(r->main ? r->main : r,
102 ngx_http_write_filter_module); 106 ngx_http_write_filter_module);
107
108 ngx_log_debug(r->connection->log, "l:%d f:%d" _ last _ flush);
103 109
104 if (!last && flush == 0 && size < conf->buffer_output) 110 if (!last && flush == 0 && size < conf->buffer_output)
105 return NGX_OK; 111 return NGX_OK;
106 112
107 chain = ngx_event_write(r->connection, ctx->out, flush); 113 chain = ngx_event_write(r->connection, ctx->out, flush);