comparison src/http/ngx_http_write_filter.c @ 61:4f3e2abcc2c4

nginx-0.0.1-2003-02-11-19:42:23 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 11 Feb 2003 16:42:23 +0000
parents e8cdc2989cee
children 36d2c25cc9bb
comparison
equal deleted inserted replaced
60:50186b49f2ad 61:4f3e2abcc2c4
55 }; 55 };
56 56
57 57
58 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) 58 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
59 { 59 {
60 int last; 60 int last;
61 off_t size, flush; 61 off_t size, flush;
62 ngx_chain_t *ch, **prev, *chain; 62 ngx_chain_t *ce, **le, *chain;
63 ngx_http_write_filter_ctx_t *ctx; 63 ngx_http_write_filter_ctx_t *ctx;
64 ngx_http_write_filter_conf_t *conf; 64 ngx_http_write_filter_conf_t *conf;
65 65
66 66
67 ctx = (ngx_http_write_filter_ctx_t *) 67 ctx = (ngx_http_write_filter_ctx_t *)
72 sizeof(ngx_http_write_filter_ctx_t)); 72 sizeof(ngx_http_write_filter_ctx_t));
73 } 73 }
74 74
75 size = flush = 0; 75 size = flush = 0;
76 last = 0; 76 last = 0;
77 prev = &ctx->out; 77 le = &ctx->out;
78 78
79 /* find size, flush point and last link of saved chain */ 79 /* find the size, the flush point and the last entry of saved chain */
80 for (ch = ctx->out; ch; ch = ch->next) { 80 for (ce = ctx->out; ce; ce = ce->next) {
81 prev = &ch->next; 81 le = &ce->next;
82 size += ch->hunk->last.file - ch->hunk->pos.file; 82 size += ce->hunk->last.file - ce->hunk->pos.file;
83 83
84 #if (NGX_DEBUG_WRITE_FILTER) 84 #if (NGX_DEBUG_WRITE_FILTER0)
85 ngx_log_debug(r->connection->log, "write filter: old chunk: %x " 85 ngx_log_debug(r->connection->log, "write filter: old chunk: %x "
86 QX_FMT " " QD_FMT _ 86 QX_FMT " " QD_FMT _
87 ch->hunk->type _ ch->hunk->pos.file _ 87 ce->hunk->type _ ce->hunk->pos.file _
88 ch->hunk->last.file - ch->hunk->pos.file); 88 ce->hunk->last.file - ce->hunk->pos.file);
89 #endif 89 #endif
90 90
91 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { 91 if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) {
92 flush = size; 92 flush = size;
93 } 93 }
94 94
95 if (ch->hunk->type & NGX_HUNK_LAST) { 95 if (ce->hunk->type & NGX_HUNK_LAST) {
96 last = 1; 96 last = 1;
97 } 97 }
98 } 98 }
99 99
100 /* add new chain to existent one */ 100 /* add the new chain to the existent one */
101 for (/* void */; in; in = in->next) { 101 for (/* void */; in; in = in->next) {
102 ngx_test_null(ch, ngx_palloc(r->pool, sizeof(ngx_chain_t)), NGX_ERROR); 102 ngx_test_null(ce, ngx_palloc(r->pool, sizeof(ngx_chain_t)), NGX_ERROR);
103 103
104 ch->hunk = in->hunk; 104 ce->hunk = in->hunk;
105 ch->next = NULL; 105 ce->next = NULL;
106 *prev = ch; 106 *le = ce;
107 prev = &ch->next; 107 le = &ce->next;
108 size += ch->hunk->last.file - ch->hunk->pos.file; 108 size += ce->hunk->last.file - ce->hunk->pos.file;
109 109
110 #if (NGX_DEBUG_WRITE_FILTER) 110 #if (NGX_DEBUG_WRITE_FILTER0)
111 ngx_log_debug(r->connection->log, "write filter: new chunk: %x " 111 ngx_log_debug(r->connection->log, "write filter: new hunk: %x "
112 QX_FMT " " QD_FMT _ 112 QX_FMT " " QD_FMT _
113 ch->hunk->type _ ch->hunk->pos.file _ 113 ce->hunk->type _ ce->hunk->pos.file _
114 ch->hunk->last.file - ch->hunk->pos.file); 114 ce->hunk->last.file - ce->hunk->pos.file);
115 #endif 115 #endif
116 116
117 if (ch->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) { 117 if (ce->hunk->type & (NGX_HUNK_FLUSH|NGX_HUNK_RECYCLED)) {
118 flush = size; 118 flush = size;
119 } 119 }
120 120
121 if (ch->hunk->type & NGX_HUNK_LAST) { 121 if (ce->hunk->type & NGX_HUNK_LAST) {
122 last = 1; 122 last = 1;
123 } 123 }
124 } 124 }
125 125
126 conf = (ngx_http_write_filter_conf_t *) 126 conf = (ngx_http_write_filter_conf_t *)
127 ngx_http_get_module_loc_conf(r->main ? r->main : r, 127 ngx_http_get_module_loc_conf(r->main ? r->main : r,
128 ngx_http_write_filter_module); 128 ngx_http_write_filter_module);
129 129
130 #if (NGX_DEBUG_WRITE_FILTER) 130 #if (NGX_DEBUG_WRITE_FILTER0)
131 ngx_log_debug(r->connection->log, "write filter: last:%d flush:%d" _ 131 ngx_log_debug(r->connection->log, "write filter: last:%d flush:%d" _
132 last _ flush); 132 last _ flush);
133 #endif 133 #endif
134 134
135 /* avoid the output if there is no last hunk, no flush point and
136 size of the hunks is smaller then 'write_buffer' */
135 if (!last && flush == 0 && size < conf->buffer_output) { 137 if (!last && flush == 0 && size < conf->buffer_output) {
136 return NGX_OK; 138 return NGX_OK;
137 } 139 }
138 140
139 chain = ngx_event_write(r->connection, ctx->out, flush); 141 chain = ngx_event_write(r->connection, ctx->out, flush);
140 if (chain == (ngx_chain_t *) -1) { 142
143 #if (NGX_DEBUG_WRITE_FILTER)
144 ngx_log_debug(r->connection->log, "write filter %x" _ chain);
145 #endif
146
147 if (chain == NGX_CHAIN_ERROR) {
141 return NGX_ERROR; 148 return NGX_ERROR;
142 } 149 }
143 150
144 ctx->out = chain; 151 ctx->out = chain;
145 152
146 ngx_log_debug(r->connection->log, "write filter %x" _ chain); 153 if (chain == NULL) {
154 return NGX_OK;
147 155
148 return (chain ? NGX_AGAIN : NGX_OK); 156 } else {
157 return NGX_AGAIN;
158 }
149 } 159 }
150 160
151 161
152 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool) 162 static void *ngx_http_write_filter_create_conf(ngx_pool_t *pool)
153 { 163 {