Revision 19c8c4ec

View differences:

ffserver.c
124 124
    uint8_t *buffer_ptr, *buffer_end;
125 125
    int http_error;
126 126
    int post;
127
    int chunked_encoding;
128
    int chunk_size;               /* 0 if it needs to be read */
127 129
    struct HTTPContext *next;
128 130
    int got_key_frame; /* stream 0 => 1, stream 1 => 2, stream 2=> 4 */
129 131
    int64_t data_count;
......
2440 2442
    c->buffer_ptr = c->buffer;
2441 2443
    c->buffer_end = c->buffer + FFM_PACKET_SIZE;
2442 2444
    c->stream->feed_opened = 1;
2445
    c->chunked_encoding = !!strcasestr(c->buffer, "Transfer-Encoding: chunked");
2443 2446
    return 0;
2444 2447
}
2445 2448

  
2446 2449
static int http_receive_data(HTTPContext *c)
2447 2450
{
2448 2451
    HTTPContext *c1;
2452
    int len, loop_run = 0;
2449 2453

  
2450
    if (c->buffer_end > c->buffer_ptr) {
2451
        int len;
2454
    while (c->chunked_encoding && !c->chunk_size &&
2455
           c->buffer_end > c->buffer_ptr) {
2456
        /* read chunk header, if present */
2457
        len = recv(c->fd, c->buffer_ptr, 1, 0);
2458

  
2459
        if (len < 0) {
2460
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
2461
                ff_neterrno() != FF_NETERROR(EINTR))
2462
                /* error : close connection */
2463
                goto fail;
2464
        } else if (len == 0) {
2465
            /* end of connection : close it */
2466
            goto fail;
2467
        } else if (c->buffer_ptr - c->buffer >= 2 &&
2468
                   !memcmp(c->buffer_ptr - 1, "\r\n", 2)) {
2469
            c->chunk_size = strtol(c->buffer, 0, 16);
2470
            if (c->chunk_size == 0) // end of stream
2471
                goto fail;
2472
            c->buffer_ptr = c->buffer;
2473
            break;
2474
        } else if (++loop_run > 10) {
2475
            /* no chunk header, abort */
2476
            goto fail;
2477
        } else {
2478
            c->buffer_ptr++;
2479
        }
2480
    }
2452 2481

  
2453
        len = recv(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
2482
    if (c->buffer_end > c->buffer_ptr) {
2483
        len = recv(c->fd, c->buffer_ptr,
2484
                   FFMIN(c->chunk_size, c->buffer_end - c->buffer_ptr), 0);
2454 2485
        if (len < 0) {
2455 2486
            if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
2456 2487
                ff_neterrno() != FF_NETERROR(EINTR))
......
2460 2491
            /* end of connection : close it */
2461 2492
            goto fail;
2462 2493
        else {
2494
            c->chunk_size -= len;
2463 2495
            c->buffer_ptr += len;
2464 2496
            c->data_count += len;
2465 2497
            update_datarate(&c->datarate, c->data_count);

Also available in: Unified diff