MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / http_receive_data

Function http_receive_data

ffserver.c:2620–2774  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2618}
2619
2620static int http_receive_data(HTTPContext *c)
2621{
2622 HTTPContext *c1;
2623 int len, loop_run = 0;
2624
2625 while (c->chunked_encoding && !c->chunk_size &&
2626 c->buffer_end > c->buffer_ptr) {
2627 /* read chunk header, if present */
2628 len = recv(c->fd, c->buffer_ptr, 1, 0);
2629
2630 if (len < 0) {
2631 if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
2632 ff_neterrno() != FF_NETERROR(EINTR))
2633 /* error : close connection */
2634 goto fail;
2635 } else if (len == 0) {
2636 /* end of connection : close it */
2637 goto fail;
2638 } else if (c->buffer_ptr - c->buffer >= 2 &&
2639 !memcmp(c->buffer_ptr - 1, "\r\n", 2)) {
2640 c->chunk_size = strtol(c->buffer, 0, 16);
2641 if (c->chunk_size == 0) // end of stream
2642 goto fail;
2643 c->buffer_ptr = c->buffer;
2644 break;
2645 } else if (++loop_run > 10) {
2646 /* no chunk header, abort */
2647 goto fail;
2648 } else {
2649 c->buffer_ptr++;
2650 }
2651 }
2652
2653 if (c->buffer_end > c->buffer_ptr) {
2654 len = recv(c->fd, c->buffer_ptr,
2655 FFMIN(c->chunk_size, c->buffer_end - c->buffer_ptr), 0);
2656 if (len < 0) {
2657 if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
2658 ff_neterrno() != FF_NETERROR(EINTR))
2659 /* error : close connection */
2660 goto fail;
2661 } else if (len == 0)
2662 /* end of connection : close it */
2663 goto fail;
2664 else {
2665 c->chunk_size -= len;
2666 c->buffer_ptr += len;
2667 c->data_count += len;
2668 update_datarate(&c->datarate, c->data_count);
2669 }
2670 }
2671
2672 if (c->buffer_ptr - c->buffer >= 2 && c->data_count > FFM_PACKET_SIZE) {
2673 if (c->buffer[0] != 'f' ||
2674 c->buffer[1] != 'm') {
2675 http_log("Feed stream has become desynchronized -- disconnecting\n");
2676 goto fail;
2677 }

Callers 1

handle_connectionFunction · 0.85

Calls 10

update_datarateFunction · 0.85
http_logFunction · 0.85
ffm_write_write_indexFunction · 0.85
av_find_input_formatFunction · 0.85
url_open_bufFunction · 0.85
av_open_input_streamFunction · 0.85
av_freeFunction · 0.85
av_close_input_streamFunction · 0.85
av_mallocFunction · 0.85
closeFunction · 0.85

Tested by

no test coverage detected