]> code.delx.au - pulseaudio/blobdiff - polyp/protocol-simple.c
limit the number of concurrent connections for all four protocols
[pulseaudio] / polyp / protocol-simple.c
index f7c69d6b4cd5d23f2593f2df7333c6957895b1ac..058d4b828c6796e536b51049420f8e801e91eb24 100644 (file)
@@ -39,6 +39,9 @@
 #include "xmalloc.h"
 #include "log.h"
 
+/* Don't allow more than this many concurrent connections */
+#define MAX_CONNECTIONS 10
+
 struct connection {
     struct pa_protocol_simple *protocol;
     struct pa_iochannel *io;
@@ -287,6 +290,12 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
     char cname[256];
     assert(s && io && p);
 
+    if (pa_idxset_ncontents(p->connections)+1 > MAX_CONNECTIONS) {
+        pa_log(__FILE__": Warning! Too many connections (%u), dropping incoming connection.\n", MAX_CONNECTIONS);
+        pa_iochannel_free(io);
+        return;
+    }
+
     c = pa_xmalloc(sizeof(struct connection));
     c->io = io;
     c->sink_input = NULL;