4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include "protocol-cli.h"
34 /* Don't allow more than this many concurrent connections */
35 #define MAX_CONNECTIONS 10
37 struct pa_protocol_cli {
38 struct pa_module *module;
40 struct pa_socket_server*server;
41 struct pa_idxset *connections;
44 static void cli_eof_cb(struct pa_cli*c, void*userdata) {
45 struct pa_protocol_cli *p = userdata;
47 pa_idxset_remove_by_data(p->connections, c, NULL);
51 static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
52 struct pa_protocol_cli *p = userdata;
56 if (pa_idxset_ncontents(p->connections)+1 > MAX_CONNECTIONS) {
57 pa_log(__FILE__": Warning! Too many connections (%u), dropping incoming connection.\n", MAX_CONNECTIONS);
58 pa_iochannel_free(io);
62 c = pa_cli_new(p->core, io, p->module);
64 pa_cli_set_eof_callback(c, cli_eof_cb, p);
66 pa_idxset_put(p->connections, c, NULL);
69 struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma) {
70 struct pa_protocol_cli* p;
71 assert(core && server);
73 p = pa_xmalloc(sizeof(struct pa_protocol_cli));
77 p->connections = pa_idxset_new(NULL, NULL);
79 pa_socket_server_set_callback(p->server, on_connection, p);
84 static void free_connection(void *p, void *userdata) {
89 void pa_protocol_cli_free(struct pa_protocol_cli *p) {
92 pa_idxset_free(p->connections, free_connection, NULL);
93 pa_socket_server_unref(p->server);