comparison src/http/ngx_http_write_filter.c @ 1:d220029ac7f3

nginx-0.0.1-2002-08-15-21:20:26 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 15 Aug 2002 17:20:26 +0000
parents
children 34a521b1a148
comparison
equal deleted inserted replaced
0:4eff17414a43 1:d220029ac7f3
1
2 #include <ngx_config.h>
3
4 #include <ngx_hunk.h>
5 #include <ngx_http.h>
6 #include <ngx_http_filter.h>
7 #include <ngx_event_write.h>
8
9 #include <ngx_http_write_filter.h>
10
11
12 ngx_http_module_t ngx_http_write_filter_module;
13
14
15 /* 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 /* */
26
27
28 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
29 {
30 int last;
31 off_t size, flush;
32 ngx_chain_t *ch, **prev, *chain;
33 ngx_http_write_filter_ctx_t *ctx;
34
35 ctx = (ngx_http_write_filter_ctx_t *)
36 ngx_get_module_ctx(r->main ? r->main : r,
37 &ngx_http_write_filter_module);
38 size = flush = 0;
39 last = 0;
40 prev = &ctx->out;
41
42 /* find size, flush point and last link of saved chain */
43 for (ch = ctx->out; ch; ch = ch->next) {
44 prev = &ch->next;
45 size += ch->hunk->last.file - ch->hunk->pos.file;
46
47 if (ch->hunk->type & NGX_HUNK_FLUSH)
48 flush = size;
49
50 if (ch->hunk->type & NGX_HUNK_LAST)
51 last = 1;
52 }
53
54 /* add new chain to existent one */
55 for (/* void */; in; in = in->next) {
56 ngx_test_null(ch, ngx_palloc(r->pool, sizeof(ngx_chain_t)),
57 NGX_HTTP_FILTER_ERROR);
58
59 ch->hunk = in->hunk;
60 ch->next = NULL;
61 *prev = ch;
62 prev = &ch->next;
63 size += ch->hunk->last.file - ch->hunk->pos.file;
64
65 if (ch->hunk->type & NGX_HUNK_FLUSH)
66 flush = size;
67
68 if (ch->hunk->type & NGX_HUNK_LAST)
69 last = 1;
70 }
71
72 if (flush == 0 && size < ctx->buffer_output)
73 return NGX_HTTP_FILTER_DONE;
74
75 chain = ngx_event_write(r->connection, ctx->out, flush);
76 if (chain == (ngx_chain_t *) -1)
77 return NGX_HTTP_FILTER_ERROR;
78
79 ctx->out = chain;
80
81 return (chain ? NGX_HTTP_FILTER_AGAIN : NGX_HTTP_FILTER_DONE);
82 }