| 753 | |
| 754 | |
| 755 | static void new_connection(int server_fd, int is_rtsp) |
| 756 | { |
| 757 | struct sockaddr_in from_addr; |
| 758 | int fd, len; |
| 759 | HTTPContext *c = NULL; |
| 760 | |
| 761 | len = sizeof(from_addr); |
| 762 | fd = accept(server_fd, (struct sockaddr *)&from_addr, |
| 763 | &len); |
| 764 | if (fd < 0) { |
| 765 | http_log("error during accept %s\n", strerror(errno)); |
| 766 | return; |
| 767 | } |
| 768 | ff_socket_nonblock(fd, 1); |
| 769 | |
| 770 | if (nb_connections >= nb_max_connections) { |
| 771 | http_send_too_busy_reply(fd); |
| 772 | goto fail; |
| 773 | } |
| 774 | |
| 775 | /* add a new connection */ |
| 776 | c = av_mallocz(sizeof(HTTPContext)); |
| 777 | if (!c) |
| 778 | goto fail; |
| 779 | |
| 780 | c->fd = fd; |
| 781 | c->poll_entry = NULL; |
| 782 | c->from_addr = from_addr; |
| 783 | c->buffer_size = IOBUFFER_INIT_SIZE; |
| 784 | c->buffer = av_malloc(c->buffer_size); |
| 785 | if (!c->buffer) |
| 786 | goto fail; |
| 787 | |
| 788 | c->next = first_http_ctx; |
| 789 | first_http_ctx = c; |
| 790 | nb_connections++; |
| 791 | |
| 792 | start_wait_request(c, is_rtsp); |
| 793 | |
| 794 | return; |
| 795 | |
| 796 | fail: |
| 797 | if (c) { |
| 798 | av_free(c->buffer); |
| 799 | av_free(c); |
| 800 | } |
| 801 | closesocket(fd); |
| 802 | } |
| 803 | |
| 804 | static void close_connection(HTTPContext *c) |
| 805 | { |
no test coverage detected