Mercurial > hg > nginx
comparison src/http/ngx_http_write_filter.c @ 41:59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 26 Dec 2002 16:26:23 +0000 |
parents | 53cb81681040 |
children | cd035a94e0b6 |
comparison
equal
deleted
inserted
replaced
40:d5d4f3bba6f0 | 41:59e7c7f30d49 |
---|---|
3 #include <ngx_core.h> | 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_config.h> | 7 #include <ngx_http_config.h> |
8 #include <ngx_http_output_filter.h> | |
9 #include <ngx_http_write_filter.h> | 8 #include <ngx_http_write_filter.h> |
10 | 9 |
11 | |
12 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in); | |
13 | 10 |
14 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool); | 11 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool); |
15 | 12 |
16 | 13 |
17 static ngx_command_t ngx_http_write_filter_commands[] = { | 14 static ngx_command_t ngx_http_write_filter_commands[] = { |
18 | 15 |
19 {"write_buffer", ngx_conf_set_size_slot, | 16 {ngx_string("write_buffer"), |
20 offsetof(ngx_http_write_filter_conf_t, buffer_output), | 17 NGX_CONF_TAKE1, |
21 NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1, | 18 ngx_conf_set_size_slot, |
22 "set write filter size to buffer output"}, | 19 NGX_HTTP_LOC_CONF, |
20 offsetof(ngx_http_write_filter_conf_t, buffer_output)}, | |
23 | 21 |
24 {NULL} | 22 {ngx_string(""), 0, NULL, 0, 0} |
25 | |
26 }; | 23 }; |
27 | 24 |
28 | 25 |
29 ngx_http_module_t ngx_http_write_filter_module = { | 26 ngx_http_module_t ngx_http_write_filter_module_ctx = { |
30 NGX_HTTP_MODULE, | 27 NGX_HTTP_MODULE, |
31 | 28 |
32 NULL, /* create server config */ | 29 NULL, /* create server config */ |
33 ngx_http_write_filter_create_conf, /* create location config */ | 30 ngx_http_write_filter_create_conf, /* create location config */ |
34 ngx_http_write_filter_commands, /* module directives */ | |
35 | 31 |
36 NULL, /* init module */ | |
37 NULL, /* translate handler */ | 32 NULL, /* translate handler */ |
38 | 33 |
39 NULL, /* output header filter */ | 34 NULL, /* output header filter */ |
40 NULL, /* next output header filter */ | 35 NULL, /* next output header filter */ |
41 ngx_http_write_filter, /* output body filter */ | 36 ngx_http_write_filter, /* output body filter */ |
42 NULL, /* next output body filter */ | 37 NULL, /* next output body filter */ |
38 }; | |
39 | |
40 | |
41 ngx_module_t ngx_http_write_filter_module = { | |
42 &ngx_http_write_filter_module_ctx, /* module context */ | |
43 ngx_http_write_filter_commands, /* module directives */ | |
44 NGX_HTTP_MODULE_TYPE, /* module type */ | |
45 NULL /* init module */ | |
43 }; | 46 }; |
44 | 47 |
45 | 48 |
46 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) | 49 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) |
47 { | 50 { |
51 ngx_http_write_filter_ctx_t *ctx; | 54 ngx_http_write_filter_ctx_t *ctx; |
52 ngx_http_write_filter_conf_t *conf; | 55 ngx_http_write_filter_conf_t *conf; |
53 | 56 |
54 | 57 |
55 ctx = (ngx_http_write_filter_ctx_t *) | 58 ctx = (ngx_http_write_filter_ctx_t *) |
56 ngx_get_module_ctx(r->main ? r->main : r, | 59 ngx_http_get_module_ctx(r->main ? r->main : r, |
57 ngx_http_write_filter_module); | 60 ngx_http_write_filter_module_ctx); |
58 if (ctx == NULL) | 61 if (ctx == NULL) { |
59 ngx_http_create_ctx(r, ctx, | 62 ngx_http_create_ctx(r, ctx, |
60 ngx_http_write_filter_module, | 63 ngx_http_write_filter_module_ctx, |
61 sizeof(ngx_http_write_filter_ctx_t)); | 64 sizeof(ngx_http_write_filter_ctx_t)); |
65 } | |
62 | 66 |
63 size = flush = 0; | 67 size = flush = 0; |
64 last = 0; | 68 last = 0; |
65 prev = &ctx->out; | 69 prev = &ctx->out; |
66 | 70 |
71 | 75 |
72 ngx_log_debug(r->connection->log, "old chunk: %x " QX_FMT " " QD_FMT _ | 76 ngx_log_debug(r->connection->log, "old chunk: %x " QX_FMT " " QD_FMT _ |
73 ch->hunk->type _ ch->hunk->pos.file _ | 77 ch->hunk->type _ ch->hunk->pos.file _ |
74 ch->hunk->last.file - ch->hunk->pos.file); | 78 ch->hunk->last.file - ch->hunk->pos.file); |
75 | 79 |
76 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) | 80 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { |
77 flush = size; | 81 flush = size; |
82 } | |
78 | 83 |
79 if (ch->hunk->type & NGX_HUNK_LAST) | 84 if (ch->hunk->type & NGX_HUNK_LAST) { |
80 last = 1; | 85 last = 1; |
86 } | |
81 } | 87 } |
82 | 88 |
83 /* add new chain to existent one */ | 89 /* add new chain to existent one */ |
84 for (/* void */; in; in = in->next) { | 90 for (/* void */; in; in = in->next) { |
85 ngx_test_null(ch, ngx_palloc(r->pool, sizeof(ngx_chain_t)), NGX_ERROR); | 91 ngx_test_null(ch, ngx_palloc(r->pool, sizeof(ngx_chain_t)), NGX_ERROR); |
92 | 98 |
93 ngx_log_debug(r->connection->log, "new chunk: %x " QX_FMT " " QD_FMT _ | 99 ngx_log_debug(r->connection->log, "new chunk: %x " QX_FMT " " QD_FMT _ |
94 ch->hunk->type _ ch->hunk->pos.file _ | 100 ch->hunk->type _ ch->hunk->pos.file _ |
95 ch->hunk->last.file - ch->hunk->pos.file); | 101 ch->hunk->last.file - ch->hunk->pos.file); |
96 | 102 |
97 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) | 103 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { |
98 flush = size; | 104 flush = size; |
105 } | |
99 | 106 |
100 if (ch->hunk->type & NGX_HUNK_LAST) | 107 if (ch->hunk->type & NGX_HUNK_LAST) { |
101 last = 1; | 108 last = 1; |
109 } | |
102 } | 110 } |
103 | 111 |
104 conf = (ngx_http_write_filter_conf_t *) | 112 conf = (ngx_http_write_filter_conf_t *) |
105 ngx_get_module_loc_conf(r->main ? r->main : r, | 113 ngx_http_get_module_loc_conf(r->main ? r->main : r, |
106 ngx_http_write_filter_module); | 114 ngx_http_write_filter_module_ctx); |
107 | 115 |
108 ngx_log_debug(r->connection->log, "l:%d f:%d" _ last _ flush); | 116 ngx_log_debug(r->connection->log, "l:%d f:%d" _ last _ flush); |
109 | 117 |
110 if (!last && flush == 0 && size < conf->buffer_output) | 118 if (!last && flush == 0 && size < conf->buffer_output) { |
111 return NGX_OK; | 119 return NGX_OK; |
120 } | |
112 | 121 |
113 chain = ngx_event_write(r->connection, ctx->out, flush); | 122 chain = ngx_event_write(r->connection, ctx->out, flush); |
114 if (chain == (ngx_chain_t *) -1) | 123 if (chain == (ngx_chain_t *) -1) { |
115 return NGX_ERROR; | 124 return NGX_ERROR; |
125 } | |
116 | 126 |
117 ctx->out = chain; | 127 ctx->out = chain; |
118 | 128 |
119 ngx_log_debug(r->connection->log, "write filter %x" _ chain); | 129 ngx_log_debug(r->connection->log, "write filter %x" _ chain); |
120 | 130 |