comparison src/http/ngx_http_write_filter.c @ 9:6f58641241bb

nginx-0.0.1-2002-09-07-14:14:25 import
author Igor Sysoev <igor@sysoev.ru>
date Sat, 07 Sep 2002 10:14:25 +0000
parents 708f8bb772ec
children 4f3879d9b6f6
comparison
equal deleted inserted replaced
8:708f8bb772ec 9:6f58641241bb
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 3 #include <ngx_core.h>
4 #include <ngx_hunk.h> 4 #include <ngx_hunk.h>
5 #include <ngx_event_write.h> 5 #include <ngx_event_write.h>
6 #include <ngx_http.h> 6 #include <ngx_http.h>
7 #include <ngx_http_output_filter.h> 7 #include <ngx_http_output_filter.h>
8
9 #include <ngx_http_write_filter.h> 8 #include <ngx_http_write_filter.h>
10 9
11 10
12 ngx_http_module_t ngx_http_write_filter_module; 11 ngx_http_module_t ngx_http_write_filter_module = {
12 NGX_HTTP_MODULE
13 };
13 14
14 15
15 /* STUB */ 16 /* STUB */
16 static ngx_http_write_filter_ctx_t module_ctx;
17
18 void ngx_http_write_filter_init()
19 {
20 module_ctx.buffer_output = 10240;
21 module_ctx.out = NULL;
22
23 ngx_http_write_filter_module.ctx = &module_ctx;
24 }
25 /* */ 17 /* */
26 18
27 19
28 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) 20 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
29 { 21 {
30 int last; 22 int last;
31 off_t size, flush; 23 off_t size, flush;
32 ngx_chain_t *ch, **prev, *chain; 24 ngx_chain_t *ch, **prev, *chain;
33 ngx_http_write_filter_ctx_t *ctx; 25 ngx_http_write_filter_ctx_t *ctx;
26 ngx_http_write_filter_conf_t *conf;
27
34 28
35 ctx = (ngx_http_write_filter_ctx_t *) 29 ctx = (ngx_http_write_filter_ctx_t *)
36 ngx_get_module_ctx(r->main ? r->main : r, 30 ngx_get_module_ctx(r->main ? r->main : r,
37 &ngx_http_write_filter_module); 31 ngx_http_write_filter_module);
32 if (ctx == NULL)
33 ngx_test_null(ctx,
34 ngx_pcalloc(r->pool, sizeof(ngx_http_write_filter_ctx_t)),
35 NGX_ERROR);
36
38 size = flush = 0; 37 size = flush = 0;
39 last = 0; 38 last = 0;
40 prev = &ctx->out; 39 prev = &ctx->out;
41 40
42 /* find size, flush point and last link of saved chain */ 41 /* find size, flush point and last link of saved chain */
74 73
75 if (ch->hunk->type & NGX_HUNK_LAST) 74 if (ch->hunk->type & NGX_HUNK_LAST)
76 last = 1; 75 last = 1;
77 } 76 }
78 77
79 if (!last && flush == 0 && size < ctx->buffer_output) 78 conf = (ngx_http_write_filter_conf_t *)
79 ngx_get_module_loc_conf(r->main ? r->main : r,
80 ngx_http_write_filter_module);
81
82 if (!last && flush == 0 && size < conf->buffer_output)
80 return NGX_OK; 83 return NGX_OK;
81 84
82 chain = ngx_event_write(r->connection, ctx->out, flush); 85 chain = ngx_event_write(r->connection, ctx->out, flush);
83 if (chain == (ngx_chain_t *) -1) 86 if (chain == (ngx_chain_t *) -1)
84 return NGX_ERROR; 87 return NGX_ERROR;
87 90
88 ngx_log_debug(r->connection->log, "write filter %x" _ chain); 91 ngx_log_debug(r->connection->log, "write filter %x" _ chain);
89 92
90 return (chain ? NGX_AGAIN : NGX_OK); 93 return (chain ? NGX_AGAIN : NGX_OK);
91 } 94 }
95
96
97 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool)
98 {
99 ngx_http_write_filter_conf_t *conf;
100
101 ngx_test_null(conf,
102 ngx_pcalloc(pool, sizeof(ngx_http_write_filter_conf_t)),
103 NULL);
104
105 conf->buffer_output = 16384;
106 }
107
108 static void *ngx_http_write_filter_set_hunk_size(ngx_pool_t *pool, void *conf,
109 char *size)
110 {
111 ngx_http_write_filter_conf_t *cf = (ngx_http_write_filter_conf_t *) conf;
112
113 cf->buffer_output = atoi(size);
114 if (cf->buffer_output <= 0)
115 return "Error";
116
117 cf->buffer_output *= 1024;
118 return NULL;
119 }
120