Changeset 2033

Show
Ignore:
Timestamp:
01/15/2008 11:59:25 PM (8 months ago)
Author:
glen
Message:

- chunk.c patches from #1510

Location:
trunk/src
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/chunk.c

    r1893 r2033  
    295295        c->type = FILE_CHUNK; 
    296296        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; 
    299299        c->offset = 0; 
    300300        c->file.is_temp = 1; 
     
    307307 
    308308/** 
    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 */ 
     311off_t chunkqueue_steal_chunk(chunkqueue *cq, chunk *c) { 
    312312        /* 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; 
    316315 
    317316        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; 
    339346} 
    340347 
     
    350357 
    351358        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); 
    384360        } 
    385361 
     
    450426                        we_want = we_have < max_len ? we_have : max_len; 
    451427         
    452                         if (c->offset == 0 && we_have == we_want) { 
     428                        if (we_have == we_want) { 
    453429                                /* steal whole chunk */ 
    454430                                chunkqueue_steal_chunk(out, c); 
     
    541517        c->type = MEM_CHUNK; 
    542518        c->offset = 0; 
    543         buffer_copy_string_len(c->mem, mem, len - 1); 
     519        buffer_copy_string_len(c->mem, mem, len); 
    544520 
    545521        chunkqueue_append_chunk(cq, c); 
  • trunk/src/chunk.h

    r1893 r2033  
    6868LI_API chunk * chunkqueue_get_append_tempfile(chunkqueue *cq); 
    6969LI_API int chunkqueue_steal_tempfile(chunkqueue *cq, chunk *in); 
    70 LI_API int chunkqueue_steal_chunk(chunkqueue *cq, chunk *c); 
     70LI_API off_t chunkqueue_steal_chunk(chunkqueue *cq, chunk *c); 
    7171LI_API off_t chunkqueue_steal_chunks_len(chunkqueue *cq, chunk *c, off_t max_len); 
    7272LI_API off_t chunkqueue_steal_all_chunks(chunkqueue *cq, chunkqueue *in); 
  • trunk/src/mod_cgi.c

    r1952 r2033  
    258258                if (c->mem->used == 0) continue; 
    259259 
    260                 we_have = c->mem->used - c->offset - 1; 
     260                we_have = chunkqueue_steal_chunk(con->send, c); 
    261261                sess->rb->bytes_out += we_have; 
    262262                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                 } 
    272263        } 
    273264        chunkqueue_remove_finished_chunks(sess->rb); 
  • trunk/src/mod_chunked.c

    r1891 r2033  
    336336                        break; 
    337337                } 
    338                 chunkqueue_append_mem(out, "\r\n", 2 + 1); 
     338                chunkqueue_append_mem(out, CONST_STR_LEN("\r\n")); 
    339339                we_have += 2; 
    340340                out->bytes_in += we_have; 
     
    343343        /* terminate the last chunk */ 
    344344        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")); 
    346346                out->bytes_in += 5; 
    347347        } 
  • trunk/src/mod_deflate.c

    r1891 r2033  
    396396                        len = hctx->output->size - z->avail_out; 
    397397                        out += len; 
    398                         chunkqueue_append_mem(hctx->out, hctx->output->ptr, len+1); 
     398                        chunkqueue_append_mem(hctx->out, hctx->output->ptr, len); 
    399399                        hctx->out->bytes_in += len; 
    400400                        z->next_out = (unsigned char *)hctx->output->ptr; 
     
    461461                if(z->avail_out == 0 || (flush && len > 0)) { 
    462462                        out += len; 
    463                         chunkqueue_append_mem(hctx->out, hctx->output->ptr, len+1); 
     463                        chunkqueue_append_mem(hctx->out, hctx->output->ptr, len); 
    464464                        hctx->out->bytes_in += len; 
    465465                        z->next_out = (unsigned char *)hctx->output->ptr; 
     
    505505                c[7] = (z->total_in >> 24) & 0xff; 
    506506                /* append footer to write_queue */ 
    507                 chunkqueue_append_mem(hctx->out, (char *)c, 9); 
     507                chunkqueue_append_mem(hctx->out, (char *)c, 8); 
    508508                hctx->out->bytes_in += 8; 
    509509                if(p->conf.debug) { 
     
    605605                        len = hctx->output->size - bz->avail_out; 
    606606                        out += len; 
    607                         chunkqueue_append_mem(hctx->out, hctx->output->ptr, len+1); 
     607                        chunkqueue_append_mem(hctx->out, hctx->output->ptr, len); 
    608608                        hctx->out->bytes_in += len; 
    609609                        bz->next_out = hctx->output->ptr; 
     
    662662                if(bz->avail_out == 0 || (flush && len > 0)) { 
    663663                        out += len; 
    664                         chunkqueue_append_mem(hctx->out, hctx->output->ptr, len+1); 
     664                        chunkqueue_append_mem(hctx->out, hctx->output->ptr, len); 
    665665                        hctx->out->bytes_in += len; 
    666666                        bz->next_out = hctx->output->ptr; 
  • trunk/src/mod_magnet.c

    r2003 r2033  
    585585                                const char *s = lua_tolstring(L, -1, &s_len); 
    586586 
    587                                 chunkqueue_append_mem(con->send, s, s_len + 1); 
     587                                chunkqueue_append_mem(con->send, s, s_len); 
    588588                        } else if (lua_istable(L, -1)) { 
    589589                                lua_getfield(L, -1, "filename"); 
  • trunk/src/mod_proxy.c

    r1858 r2033  
    679679 
    680680        /* 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); 
    686682 
    687683        chunkqueue_remove_finished_chunks(hctx->rb); 
  • trunk/src/mod_proxy_core.c

    r1858 r2033  
    527527                        con->send->bytes_in += we_have; 
    528528                        /* 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); 
    538530                } else { 
    539531                        /* discard the data */ 
    540                         c->offset = c->mem->used - 1; /* mark the incoming side as read */ 
     532                        chunk_set_done(c); 
    541533                } 
    542534        } 
  • trunk/src/mod_scgi.c

    r1952 r2033  
    17371737 
    17381738        /* 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); 
    17441740 
    17451741        chunkqueue_remove_finished_chunks(hctx->rb);