X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fhttpd.c;h=8a3844329d86fde041d4d83b14182e7ff7a2076b;hb=d1bbd169e04d1568d45d9ef50394cae4b2059161;hp=9a56997ac4ee1c0b61c82719940b402b5764446a;hpb=23e7e3ae2b2adfa49635495c0950b76e17987c93;p=deb_shairplay.git diff --git a/src/lib/httpd.c b/src/lib/httpd.c index 9a56997..8a38443 100644 --- a/src/lib/httpd.c +++ b/src/lib/httpd.c @@ -39,6 +39,7 @@ struct httpd_s { int use_rtsp; int max_connections; + int open_connections; http_connection_t *connections; /* These variables only edited mutex locked */ @@ -115,6 +116,7 @@ httpd_add_connection(httpd_t *httpd, int fd, unsigned char *local, int local_len return; } + httpd->open_connections++; httpd->connections[i].socket_fd = fd; httpd->connections[i].connected = 1; httpd->connections[i].user_data = httpd->callbacks.conn_init(httpd->callbacks.opaque, local, local_len, remote, remote_len); @@ -131,6 +133,7 @@ httpd_remove_connection(httpd_t *httpd, http_connection_t *connection) shutdown(connection->socket_fd, SHUT_WR); closesocket(connection->socket_fd); connection->connected = 0; + httpd->open_connections--; } static THREAD_RETVAL @@ -161,8 +164,10 @@ httpd_thread(void *arg) /* Get the correct nfds value and set rfds */ FD_ZERO(&rfds); - FD_SET(httpd->server_fd, &rfds); - nfds = httpd->server_fd+1; + if (httpd->open_connections < httpd->max_connections) { + FD_SET(httpd->server_fd, &rfds); + nfds = httpd->server_fd+1; + } for (i=0; imax_connections; i++) { int socket_fd; if (!httpd->connections[i].connected) { @@ -230,10 +235,10 @@ httpd_thread(void *arg) assert(connection->request); } - logger_log(httpd->logger, LOGGER_DEBUG, "Receiving on socket %d\n", httpd->connections[i].socket_fd); + logger_log(httpd->logger, LOGGER_DEBUG, "Receiving on socket %d\n", connection->socket_fd); ret = recv(connection->socket_fd, buffer, sizeof(buffer), 0); if (ret == 0) { - logger_log(httpd->logger, LOGGER_INFO, "Connection closed\n"); + logger_log(httpd->logger, LOGGER_INFO, "Connection closed for socket %d\n", connection->socket_fd); httpd_remove_connection(httpd, connection); continue; } @@ -288,11 +293,11 @@ httpd_thread(void *arg) if (!connection->connected) { continue; } - logger_log(httpd->logger, LOGGER_INFO, "Removing connection\n"); + logger_log(httpd->logger, LOGGER_INFO, "Removing connection for socket %d\n", connection->socket_fd); httpd_remove_connection(httpd, connection); } - logger_log(httpd->logger, LOGGER_INFO, "Exiting thread\n"); + logger_log(httpd->logger, LOGGER_INFO, "Exiting HTTP thread\n"); return 0; }