Changeset 2033
- Timestamp:
- 01/15/2008 11:59:25 PM (8 months ago)
- Location:
- trunk/src
- Files:
-
- 9 modified
-
chunk.c (modified) (5 diffs)
-
chunk.h (modified) (1 diff)
-
mod_cgi.c (modified) (1 diff)
-
mod_chunked.c (modified) (2 diffs)
-
mod_deflate.c (modified) (5 diffs)
-
mod_magnet.c (modified) (1 diff)
-
mod_proxy.c (modified) (1 diff)
-
mod_proxy_core.c (modified) (1 diff)
-
mod_scgi.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/chunk.c
r1893 r2033 295 295 c->type = FILE_CHUNK; 296 296 buffer_copy_string_buffer(c->file.name, in->file.name); 297 c->file.start = in-> offset;298 c->file.length = in->file.length - c->file.start -in->offset;297 c->file.start = in->file.start + in->offset; 298 c->file.length = in->file.length - in->offset; 299 299 c->offset = 0; 300 300 c->file.is_temp = 1; … … 307 307 308 308 /** 309 * move the content of chunk to another chunkqueue 310 */ 311 int chunkqueue_steal_chunk(chunkqueue *cq, chunk *c) {309 * move the content of chunk to another chunkqueue. return total bytes copied/stolen. 310 */ 311 off_t chunkqueue_steal_chunk(chunkqueue *cq, chunk *c) { 312 312 /* we are copying the whole buffer, just steal it */ 313 size_t len; 314 char *s; 315 buffer *b; 313 off_t total = 0; 314 buffer *b, btmp; 316 315 317 316 if (!cq) return 0; 318 319 assert(c->type == MEM_CHUNK); 320 321 b = chunkqueue_get_append_buffer(cq); 322 323 /* swap len, alloced-size and pointer */ 324 len = b->used; 325 b->used = c->mem->used; 326 c->mem->used = len; 327 328 len = b->size; 329 b->size = c->mem->size; 330 c->mem->size = len; 331 332 s = b->ptr; 333 b->ptr = c->mem->ptr; 334 c->mem->ptr = s; 335 336 chunk_set_done(c); /* mark the old chunk as read */ 337 338 return 0; 317 if (chunk_is_done(c)) return 0; 318 319 switch (c->type) { 320 case MEM_CHUNK: 321 total = c->mem->used - c->offset - 1; 322 if (c->offset == 0) { 323 b = chunkqueue_get_append_buffer(cq); 324 btmp = *b; *b = *(c->mem); *(c->mem) = btmp; 325 } else { 326 chunkqueue_append_mem(cq, c->mem->ptr + c->offset, total); 327 chunk_set_done(c); 328 } 329 break; 330 case FILE_CHUNK: 331 total = c->file.length - c->offset; 332 333 if (c->file.is_temp) { 334 chunkqueue_steal_tempfile(cq, c); 335 } else { 336 chunkqueue_append_file(cq, c->file.name, c->file.start + c->offset, c->file.length - c->offset); 337 chunk_set_done(c); 338 } 339 340 break; 341 case UNUSED_CHUNK: 342 return 0; 343 } 344 345 return total; 339 346 } 340 347 … … 350 357 351 358 for (c = in->first; c; c = c->next) { 352 off_t we_have = 0; 353 354 /* is there something to move ? */ 355 if (chunk_is_done(c)) continue; 356 357 switch (c->type) { 358 case MEM_CHUNK: 359 we_have = c->mem->used - c->offset - 1; 360 361 if (c->offset == 0) { 362 chunkqueue_steal_chunk(cq, c); 363 } else { 364 chunkqueue_append_buffer(cq, c->mem); 365 } 366 break; 367 case FILE_CHUNK: 368 we_have = c->file.length - c->offset; 369 370 if (c->file.is_temp) { 371 chunkqueue_steal_tempfile(cq, c); 372 } else { 373 chunkqueue_append_file(cq, c->file.name, c->file.start, c->file.length); 374 } 375 376 break; 377 case UNUSED_CHUNK: 378 break; 379 } 380 381 chunk_set_done(c); 382 383 total += we_have; 359 total += chunkqueue_steal_chunk(cq, c); 384 360 } 385 361 … … 450 426 we_want = we_have < max_len ? we_have : max_len; 451 427 452 if ( c->offset == 0 &&we_have == we_want) {428 if (we_have == we_want) { 453 429 /* steal whole chunk */ 454 430 chunkqueue_steal_chunk(out, c); … … 541 517 c->type = MEM_CHUNK; 542 518 c->offset = 0; 543 buffer_copy_string_len(c->mem, mem, len - 1);519 buffer_copy_string_len(c->mem, mem, len); 544 520 545 521 chunkqueue_append_chunk(cq, c); -
trunk/src/chunk.h
r1893 r2033 68 68 LI_API chunk * chunkqueue_get_append_tempfile(chunkqueue *cq); 69 69 LI_API int chunkqueue_steal_tempfile(chunkqueue *cq, chunk *in); 70 LI_API int chunkqueue_steal_chunk(chunkqueue *cq, chunk *c);70 LI_API off_t chunkqueue_steal_chunk(chunkqueue *cq, chunk *c); 71 71 LI_API off_t chunkqueue_steal_chunks_len(chunkqueue *cq, chunk *c, off_t max_len); 72 72 LI_API off_t chunkqueue_steal_all_chunks(chunkqueue *cq, chunkqueue *in); -
trunk/src/mod_cgi.c
r1952 r2033 258 258 if (c->mem->used == 0) continue; 259 259 260 we_have = c ->mem->used - c->offset - 1;260 we_have = chunkqueue_steal_chunk(con->send, c); 261 261 sess->rb->bytes_out += we_have; 262 262 con->send->bytes_in += we_have; 263 if (c->offset == 0) {264 /* steal the buffer from the previous queue */265 266 chunkqueue_steal_chunk(con->send, c);267 } else {268 chunkqueue_append_mem(con->send, c->mem->ptr + c->offset, c->mem->used - c->offset);269 270 c->offset = c->mem->used - 1; /* mark the incoming side as read */271 }272 263 } 273 264 chunkqueue_remove_finished_chunks(sess->rb); -
trunk/src/mod_chunked.c
r1891 r2033 336 336 break; 337 337 } 338 chunkqueue_append_mem(out, "\r\n", 2 + 1);338 chunkqueue_append_mem(out, CONST_STR_LEN("\r\n")); 339 339 we_have += 2; 340 340 out->bytes_in += we_have; … … 343 343 /* terminate the last chunk */ 344 344 if (in->is_closed) { 345 chunkqueue_append_mem(out, "0\r\n\r\n", 5 + 1);345 chunkqueue_append_mem(out, CONST_STR_LEN("0\r\n\r\n")); 346 346 out->bytes_in += 5; 347 347 } -
trunk/src/mod_deflate.c
r1891 r2033 396 396 len = hctx->output->size - z->avail_out; 397 397 out += len; 398 chunkqueue_append_mem(hctx->out, hctx->output->ptr, len +1);398 chunkqueue_append_mem(hctx->out, hctx->output->ptr, len); 399 399 hctx->out->bytes_in += len; 400 400 z->next_out = (unsigned char *)hctx->output->ptr; … … 461 461 if(z->avail_out == 0 || (flush && len > 0)) { 462 462 out += len; 463 chunkqueue_append_mem(hctx->out, hctx->output->ptr, len +1);463 chunkqueue_append_mem(hctx->out, hctx->output->ptr, len); 464 464 hctx->out->bytes_in += len; 465 465 z->next_out = (unsigned char *)hctx->output->ptr; … … 505 505 c[7] = (z->total_in >> 24) & 0xff; 506 506 /* append footer to write_queue */ 507 chunkqueue_append_mem(hctx->out, (char *)c, 9);507 chunkqueue_append_mem(hctx->out, (char *)c, 8); 508 508 hctx->out->bytes_in += 8; 509 509 if(p->conf.debug) { … … 605 605 len = hctx->output->size - bz->avail_out; 606 606 out += len; 607 chunkqueue_append_mem(hctx->out, hctx->output->ptr, len +1);607 chunkqueue_append_mem(hctx->out, hctx->output->ptr, len); 608 608 hctx->out->bytes_in += len; 609 609 bz->next_out = hctx->output->ptr; … … 662 662 if(bz->avail_out == 0 || (flush && len > 0)) { 663 663 out += len; 664 chunkqueue_append_mem(hctx->out, hctx->output->ptr, len +1);664 chunkqueue_append_mem(hctx->out, hctx->output->ptr, len); 665 665 hctx->out->bytes_in += len; 666 666 bz->next_out = hctx->output->ptr; -
trunk/src/mod_magnet.c
r2003 r2033 585 585 const char *s = lua_tolstring(L, -1, &s_len); 586 586 587 chunkqueue_append_mem(con->send, s, s_len + 1);587 chunkqueue_append_mem(con->send, s, s_len); 588 588 } else if (lua_istable(L, -1)) { 589 589 lua_getfield(L, -1, "filename"); -
trunk/src/mod_proxy.c
r1858 r2033 679 679 680 680 /* copy the content to the next cq */ 681 for (c = hctx->rb->first; c; c = c->next) { 682 chunkqueue_append_mem(con->send, c->mem->ptr + c->offset, c->mem->used - c->offset); 683 684 c->offset = c->mem->used - 1; 685 } 681 chunkqueue_steal_all_chunks(con->send, hctx->rb); 686 682 687 683 chunkqueue_remove_finished_chunks(hctx->rb); -
trunk/src/mod_proxy_core.c
r1858 r2033 527 527 con->send->bytes_in += we_have; 528 528 /* X-Sendfile ignores the content-body */ 529 if (c->offset == 0) { 530 /* steal the buffer from the previous queue */ 531 532 chunkqueue_steal_chunk(con->send, c); 533 } else { 534 chunkqueue_append_mem(con->send, c->mem->ptr + c->offset, c->mem->used - c->offset); 535 536 c->offset = c->mem->used - 1; /* mark the incoming side as read */ 537 } 529 chunkqueue_steal_chunk(con->send, c); 538 530 } else { 539 531 /* discard the data */ 540 c ->offset = c->mem->used - 1; /* mark the incoming side as read */532 chunk_set_done(c); 541 533 } 542 534 } -
trunk/src/mod_scgi.c
r1952 r2033 1737 1737 1738 1738 /* copy the content to the next cq */ 1739 for (c = hctx->rb->first; c; c = c->next) { 1740 chunkqueue_append_mem(con->send, c->mem->ptr + c->offset, c->mem->used - c->offset); 1741 1742 c->offset = c->mem->used - 1; 1743 } 1739 chunkqueue_steal_all_chunks(con->send, hctx->rb); 1744 1740 1745 1741 chunkqueue_remove_finished_chunks(hctx->rb);

