Fix #23 on issue tracker.
[deb_shairplay.git] / src / lib / httpd.c
index 757f05064ae49b9cb14b9b95cbc3c2e86487d7c0..f081c5e65cc74eb4c10f8ac7ad2818a50cffc73f 100644 (file)
@@ -237,7 +237,8 @@ httpd_thread(void *arg)
                                continue;
                        }
                }
-               if (httpd->server_fd6 != -1 && FD_ISSET(httpd->server_fd6, &rfds)) {
+               if (httpd->open_connections < httpd->max_connections &&
+                   httpd->server_fd6 != -1 && FD_ISSET(httpd->server_fd6, &rfds)) {
                        ret = httpd_accept_connection(httpd, httpd->server_fd6, 1);
                        if (ret == -1) {
                                break;
@@ -304,6 +305,11 @@ httpd_thread(void *arg)
                                                }
                                                written += ret;
                                        }
+
+                                       if (http_response_get_disconnect(response)) {
+                                               logger_log(httpd->logger, LOGGER_INFO, "Disconnecting on software request");
+                                               httpd_remove_connection(httpd, connection);
+                                       }
                                } else {
                                        logger_log(httpd->logger, LOGGER_INFO, "Didn't get response");
                                }