main loop of the http server */
| 583 | |
| 584 | /* main loop of the http server */ |
| 585 | static int http_server(void) |
| 586 | { |
| 587 | int server_fd = 0, rtsp_server_fd = 0; |
| 588 | int ret, delay, delay1; |
| 589 | struct pollfd *poll_table, *poll_entry; |
| 590 | HTTPContext *c, *c_next; |
| 591 | |
| 592 | if(!(poll_table = av_mallocz((nb_max_http_connections + 2)*sizeof(*poll_table)))) { |
| 593 | http_log("Impossible to allocate a poll table handling %d connections.\n", nb_max_http_connections); |
| 594 | return -1; |
| 595 | } |
| 596 | |
| 597 | if (my_http_addr.sin_port) { |
| 598 | server_fd = socket_open_listen(&my_http_addr); |
| 599 | if (server_fd < 0) |
| 600 | return -1; |
| 601 | } |
| 602 | |
| 603 | if (my_rtsp_addr.sin_port) { |
| 604 | rtsp_server_fd = socket_open_listen(&my_rtsp_addr); |
| 605 | if (rtsp_server_fd < 0) |
| 606 | return -1; |
| 607 | } |
| 608 | |
| 609 | if (!rtsp_server_fd && !server_fd) { |
| 610 | http_log("HTTP and RTSP disabled.\n"); |
| 611 | return -1; |
| 612 | } |
| 613 | |
| 614 | http_log("FFserver started.\n"); |
| 615 | |
| 616 | start_children(first_feed); |
| 617 | |
| 618 | start_multicast(); |
| 619 | |
| 620 | for(;;) { |
| 621 | poll_entry = poll_table; |
| 622 | if (server_fd) { |
| 623 | poll_entry->fd = server_fd; |
| 624 | poll_entry->events = POLLIN; |
| 625 | poll_entry++; |
| 626 | } |
| 627 | if (rtsp_server_fd) { |
| 628 | poll_entry->fd = rtsp_server_fd; |
| 629 | poll_entry->events = POLLIN; |
| 630 | poll_entry++; |
| 631 | } |
| 632 | |
| 633 | /* wait for events on each HTTP handle */ |
| 634 | c = first_http_ctx; |
| 635 | delay = 1000; |
| 636 | while (c != NULL) { |
| 637 | int fd; |
| 638 | fd = c->fd; |
| 639 | switch(c->state) { |
| 640 | case HTTPSTATE_SEND_HEADER: |
| 641 | case RTSPSTATE_SEND_REPLY: |
| 642 | case RTSPSTATE_SEND_PACKET: |
no test coverage detected