aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorViliam Mateicka <viliam.mateicka@gmail.com>2009-10-29 22:38:18 +0100
committerViliam Mateicka <viliam.mateicka@gmail.com>2009-10-29 22:38:18 +0100
commitbb5acc939fccd27c5ac47173905dcdf84f88a722 (patch)
treecde754299f868f651cfe8dafaa3fbddebb32f53f /src/output
parentbde3d1433997af8cc430f4b9d38e5bde97d3b760 (diff)
downloadmpd-bb5acc939fccd27c5ac47173905dcdf84f88a722.tar.gz
mpd-bb5acc939fccd27c5ac47173905dcdf84f88a722.tar.xz
mpd-bb5acc939fccd27c5ac47173905dcdf84f88a722.zip
httpd: add config option to limit number of clients
Diffstat (limited to '')
-rw-r--r--src/output/httpd_internal.h6
-rw-r--r--src/output/httpd_output_plugin.c17
2 files changed, 20 insertions, 3 deletions
diff --git a/src/output/httpd_internal.h b/src/output/httpd_internal.h
index 2257e27a2..83e9498c6 100644
--- a/src/output/httpd_internal.h
+++ b/src/output/httpd_internal.h
@@ -97,6 +97,12 @@ struct httpd_output {
* function.
*/
char buffer[32768];
+
+ /**
+ * The maximum and current number of clients connected
+ * at the same time.
+ */
+ guint clients_max, clients_cnt;
};
/**
diff --git a/src/output/httpd_output_plugin.c b/src/output/httpd_output_plugin.c
index d1296abc2..675297cd3 100644
--- a/src/output/httpd_output_plugin.c
+++ b/src/output/httpd_output_plugin.c
@@ -76,6 +76,8 @@ httpd_output_init(G_GNUC_UNUSED const struct audio_format *audio_format,
else
httpd->content_type = "application/octet-stream";
+ httpd->clients_max = config_get_block_unsigned(param,"max_clients", 0);
+
/* initialize listen address */
sin = (struct sockaddr_in *)&httpd->address;
@@ -124,6 +126,7 @@ httpd_client_add(struct httpd_output *httpd, int fd)
httpd->encoder->plugin->tag == NULL);
httpd->clients = g_list_prepend(httpd->clients, client);
+ httpd->clients_cnt++;
/* pass metadata to client */
if (httpd->metadata)
@@ -146,10 +149,16 @@ httpd_listen_in_event(G_GNUC_UNUSED GIOChannel *source,
connected */
fd = accept(httpd->fd, (struct sockaddr*)&sa, &sa_length);
- if (fd >= 0)
- httpd_client_add(httpd, fd);
- else if (fd < 0 && errno != EINTR)
+ if (fd >= 0) {
+ /* can we allow additional client */
+ if (!httpd->clients_max ||
+ httpd->clients_cnt < httpd->clients_max)
+ httpd_client_add(httpd, fd);
+ else
+ close(fd);
+ } else if (fd < 0 && errno != EINTR) {
g_warning("accept() failed: %s", g_strerror(errno));
+ }
g_mutex_unlock(httpd->mutex);
@@ -237,6 +246,7 @@ httpd_output_open(void *data, struct audio_format *audio_format,
/* initialize other attributes */
httpd->clients = NULL;
+ httpd->clients_cnt = 0;
httpd->timer = timer_new(audio_format);
g_mutex_unlock(httpd->mutex);
@@ -281,6 +291,7 @@ httpd_output_remove_client(struct httpd_output *httpd,
assert(client != NULL);
httpd->clients = g_list_remove(httpd->clients, client);
+ httpd->clients_cnt--;
}
void