6 #include "protocol-native.h"
7 #include "protocol-native-spec.h"
10 #include "sourceoutput.h"
11 #include "sinkinput.h"
13 #include "tagstruct.h"
14 #include "pdispatch.h"
15 #include "pstream-util.h"
20 struct pa_protocol_native;
22 struct record_stream {
23 struct connection *connection;
25 struct pa_source_output *source_output;
26 struct pa_memblockq *memblockq;
30 struct playback_stream {
31 struct connection *connection;
33 struct pa_sink_input *sink_input;
34 struct pa_memblockq *memblockq;
35 size_t requested_bytes;
42 struct pa_protocol_native *protocol;
43 struct pa_client *client;
44 struct pa_pstream *pstream;
45 struct pa_pdispatch *pdispatch;
46 struct pa_idxset *record_streams, *playback_streams;
47 uint32_t rrobin_index;
50 struct pa_protocol_native {
51 struct pa_module *module;
54 struct pa_socket_server *server;
55 struct pa_idxset *connections;
56 uint8_t auth_cookie[PA_NATIVE_COOKIE_LENGTH];
59 static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk);
60 static void sink_input_drop_cb(struct pa_sink_input *i, size_t length);
61 static void sink_input_kill_cb(struct pa_sink_input *i);
62 static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i);
64 static void request_bytes(struct playback_stream*s);
66 static void source_output_kill_cb(struct pa_source_output *o);
67 static void source_output_push_cb(struct pa_source_output *o, const struct pa_memchunk *chunk);
69 static void command_exit(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
70 static void command_create_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
71 static void command_delete_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
72 static void command_drain_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
73 static void command_create_record_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
74 static void command_delete_record_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
75 static void command_auth(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
76 static void command_set_name(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
77 static void command_lookup(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
79 static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
80 [PA_COMMAND_ERROR] = { NULL },
81 [PA_COMMAND_TIMEOUT] = { NULL },
82 [PA_COMMAND_REPLY] = { NULL },
83 [PA_COMMAND_CREATE_PLAYBACK_STREAM] = { command_create_playback_stream },
84 [PA_COMMAND_DELETE_PLAYBACK_STREAM] = { command_delete_playback_stream },
85 [PA_COMMAND_DRAIN_PLAYBACK_STREAM] = { command_drain_playback_stream },
86 [PA_COMMAND_CREATE_RECORD_STREAM] = { command_create_record_stream },
87 [PA_COMMAND_DELETE_RECORD_STREAM] = { command_delete_record_stream },
88 [PA_COMMAND_AUTH] = { command_auth },
89 [PA_COMMAND_REQUEST] = { NULL },
90 [PA_COMMAND_EXIT] = { command_exit },
91 [PA_COMMAND_SET_NAME] = { command_set_name },
92 [PA_COMMAND_LOOKUP_SINK] = { command_lookup },
93 [PA_COMMAND_LOOKUP_SOURCE] = { command_lookup },
96 /* structure management */
98 static struct record_stream* record_stream_new(struct connection *c, struct pa_source *source, struct pa_sample_spec *ss, const char *name, size_t maxlength, size_t fragment_size) {
99 struct record_stream *s;
100 struct pa_source_output *source_output;
102 assert(c && source && ss && name && maxlength);
104 if (!(source_output = pa_source_output_new(source, name, ss)))
107 s = malloc(sizeof(struct record_stream));
110 s->source_output = source_output;
111 s->source_output->push = source_output_push_cb;
112 s->source_output->kill = source_output_kill_cb;
113 s->source_output->userdata = s;
114 s->source_output->owner = c->protocol->module;
115 s->source_output->client = c->client;
117 s->memblockq = pa_memblockq_new(maxlength, 0, base = pa_sample_size(ss), 0, 0);
118 assert(s->memblockq);
120 s->fragment_size = (fragment_size/base)*base;
121 if (!s->fragment_size)
122 s->fragment_size = base;
124 pa_idxset_put(c->record_streams, s, &s->index);
128 static void record_stream_free(struct record_stream* r) {
129 assert(r && r->connection);
131 pa_idxset_remove_by_data(r->connection->record_streams, r, NULL);
132 pa_source_output_free(r->source_output);
133 pa_memblockq_free(r->memblockq);
137 static struct playback_stream* playback_stream_new(struct connection *c, struct pa_sink *sink, struct pa_sample_spec *ss, const char *name,
142 struct playback_stream *s;
143 struct pa_sink_input *sink_input;
144 assert(c && sink && ss && name && maxlength);
146 if (!(sink_input = pa_sink_input_new(sink, name, ss)))
149 s = malloc(sizeof(struct playback_stream));
152 s->sink_input = sink_input;
154 s->sink_input->peek = sink_input_peek_cb;
155 s->sink_input->drop = sink_input_drop_cb;
156 s->sink_input->kill = sink_input_kill_cb;
157 s->sink_input->get_latency = sink_input_get_latency_cb;
158 s->sink_input->userdata = s;
159 s->sink_input->owner = c->protocol->module;
160 s->sink_input->client = c->client;
162 s->memblockq = pa_memblockq_new(maxlength, tlength, pa_sample_size(ss), prebuf, minreq);
163 assert(s->memblockq);
165 s->requested_bytes = 0;
166 s->drain_request = 0;
168 pa_idxset_put(c->playback_streams, s, &s->index);
172 static void playback_stream_free(struct playback_stream* p) {
173 assert(p && p->connection);
175 if (p->drain_request)
176 pa_pstream_send_error(p->connection->pstream, p->drain_tag, PA_ERROR_NOENTITY);
178 pa_idxset_remove_by_data(p->connection->playback_streams, p, NULL);
179 pa_sink_input_free(p->sink_input);
180 pa_memblockq_free(p->memblockq);
184 static void connection_free(struct connection *c) {
185 struct record_stream *r;
186 struct playback_stream *p;
187 assert(c && c->protocol);
189 pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
190 while ((r = pa_idxset_first(c->record_streams, NULL)))
191 record_stream_free(r);
192 pa_idxset_free(c->record_streams, NULL, NULL);
194 while ((p = pa_idxset_first(c->playback_streams, NULL)))
195 playback_stream_free(p);
196 pa_idxset_free(c->playback_streams, NULL, NULL);
198 pa_pdispatch_free(c->pdispatch);
199 pa_pstream_free(c->pstream);
200 pa_client_free(c->client);
204 static void request_bytes(struct playback_stream *s) {
205 struct pa_tagstruct *t;
209 if (!(l = pa_memblockq_missing(s->memblockq)))
212 if (l <= s->requested_bytes)
215 l -= s->requested_bytes;
217 if (l < pa_memblockq_get_minreq(s->memblockq))
220 s->requested_bytes += l;
222 t = pa_tagstruct_new(NULL, 0);
224 pa_tagstruct_putu32(t, PA_COMMAND_REQUEST);
225 pa_tagstruct_putu32(t, (uint32_t) -1); /* tag */
226 pa_tagstruct_putu32(t, s->index);
227 pa_tagstruct_putu32(t, l);
228 pa_pstream_send_tagstruct(s->connection->pstream, t);
230 /*fprintf(stderr, "Requesting %u bytes\n", l);*/
233 static void send_memblock(struct connection *c) {
235 struct record_stream *r;
237 start = PA_IDXSET_INVALID;
239 struct pa_memchunk chunk;
241 if (!(r = pa_idxset_rrobin(c->record_streams, &c->rrobin_index)))
244 if (start == PA_IDXSET_INVALID)
245 start = c->rrobin_index;
246 else if (start == c->rrobin_index)
249 if (pa_memblockq_peek(r->memblockq, &chunk) >= 0) {
250 if (chunk.length > r->fragment_size)
251 chunk.length = r->fragment_size;
253 pa_pstream_send_memblock(c->pstream, r->index, 0, &chunk);
254 pa_memblockq_drop(r->memblockq, chunk.length);
255 pa_memblock_unref(chunk.memblock);
262 static void send_playback_stream_killed(struct playback_stream *p) {
263 struct pa_tagstruct *t;
266 t = pa_tagstruct_new(NULL, 0);
268 pa_tagstruct_putu32(t, PA_COMMAND_PLAYBACK_STREAM_KILLED);
269 pa_tagstruct_putu32(t, (uint32_t) -1); /* tag */
270 pa_tagstruct_putu32(t, p->index);
271 pa_pstream_send_tagstruct(p->connection->pstream, t);
274 static void send_record_stream_killed(struct record_stream *r) {
275 struct pa_tagstruct *t;
278 t = pa_tagstruct_new(NULL, 0);
280 pa_tagstruct_putu32(t, PA_COMMAND_RECORD_STREAM_KILLED);
281 pa_tagstruct_putu32(t, (uint32_t) -1); /* tag */
282 pa_tagstruct_putu32(t, r->index);
283 pa_pstream_send_tagstruct(r->connection->pstream, t);
287 /*** sinkinput callbacks ***/
289 static int sink_input_peek_cb(struct pa_sink_input *i, struct pa_memchunk *chunk) {
290 struct playback_stream *s;
291 assert(i && i->userdata && chunk);
294 if (pa_memblockq_peek(s->memblockq, chunk) < 0)
300 static void sink_input_drop_cb(struct pa_sink_input *i, size_t length) {
301 struct playback_stream *s;
302 assert(i && i->userdata && length);
305 pa_memblockq_drop(s->memblockq, length);
308 if (s->drain_request && !pa_memblockq_is_readable(s->memblockq)) {
309 pa_pstream_send_simple_ack(s->connection->pstream, s->drain_tag);
310 s->drain_request = 0;
314 static void sink_input_kill_cb(struct pa_sink_input *i) {
315 assert(i && i->userdata);
316 send_playback_stream_killed((struct playback_stream *) i->userdata);
317 playback_stream_free((struct playback_stream *) i->userdata);
320 static uint32_t sink_input_get_latency_cb(struct pa_sink_input *i) {
321 struct playback_stream *s;
322 assert(i && i->userdata);
325 return pa_samples_usec(pa_memblockq_get_length(s->memblockq), &s->sink_input->sample_spec);
328 /*** source_output callbacks ***/
330 static void source_output_push_cb(struct pa_source_output *o, const struct pa_memchunk *chunk) {
331 struct record_stream *s;
332 assert(o && o->userdata && chunk);
335 pa_memblockq_push(s->memblockq, chunk, 0);
336 if (!pa_pstream_is_pending(s->connection->pstream))
337 send_memblock(s->connection);
340 static void source_output_kill_cb(struct pa_source_output *o) {
341 assert(o && o->userdata);
342 send_record_stream_killed((struct record_stream *) o->userdata);
343 record_stream_free((struct record_stream *) o->userdata);
346 /*** pdispatch callbacks ***/
348 static void protocol_error(struct connection *c) {
349 fprintf(stderr, __FILE__": protocol error, kicking client\n");
353 static void command_create_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
354 struct connection *c = userdata;
355 struct playback_stream *s;
356 size_t maxlength, tlength, prebuf, minreq;
359 struct pa_sample_spec ss;
360 struct pa_tagstruct *reply;
361 struct pa_sink *sink;
362 assert(c && t && c->protocol && c->protocol->core);
364 if (pa_tagstruct_gets(t, &name) < 0 ||
365 pa_tagstruct_get_sample_spec(t, &ss) < 0 ||
366 pa_tagstruct_getu32(t, &sink_index) < 0 ||
367 pa_tagstruct_getu32(t, &maxlength) < 0 ||
368 pa_tagstruct_getu32(t, &tlength) < 0 ||
369 pa_tagstruct_getu32(t, &prebuf) < 0 ||
370 pa_tagstruct_getu32(t, &minreq) < 0 ||
371 !pa_tagstruct_eof(t)) {
376 if (!c->authorized) {
377 pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
381 if (sink_index == (uint32_t) -1)
382 sink = pa_sink_get_default(c->protocol->core);
384 sink = pa_idxset_get_by_index(c->protocol->core->sinks, sink_index);
387 pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
391 if (!(s = playback_stream_new(c, sink, &ss, name, maxlength, tlength, prebuf, minreq))) {
392 pa_pstream_send_error(c->pstream, tag, PA_ERROR_INVALID);
396 reply = pa_tagstruct_new(NULL, 0);
398 pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
399 pa_tagstruct_putu32(reply, tag);
400 pa_tagstruct_putu32(reply, s->index);
401 assert(s->sink_input);
402 pa_tagstruct_putu32(reply, s->sink_input->index);
403 pa_pstream_send_tagstruct(c->pstream, reply);
407 static void command_delete_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
408 struct connection *c = userdata;
410 struct playback_stream *s;
413 if (pa_tagstruct_getu32(t, &channel) < 0 ||
414 !pa_tagstruct_eof(t)) {
419 if (!c->authorized) {
420 pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
424 if (!(s = pa_idxset_get_by_index(c->playback_streams, channel))) {
425 pa_pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
429 playback_stream_free(s);
430 pa_pstream_send_simple_ack(c->pstream, tag);
433 static void command_create_record_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
434 struct connection *c = userdata;
435 struct record_stream *s;
436 size_t maxlength, fragment_size;
437 uint32_t source_index;
439 struct pa_sample_spec ss;
440 struct pa_tagstruct *reply;
441 struct pa_source *source;
442 assert(c && t && c->protocol && c->protocol->core);
444 if (pa_tagstruct_gets(t, &name) < 0 ||
445 pa_tagstruct_get_sample_spec(t, &ss) < 0 ||
446 pa_tagstruct_getu32(t, &source_index) < 0 ||
447 pa_tagstruct_getu32(t, &maxlength) < 0 ||
448 pa_tagstruct_getu32(t, &fragment_size) < 0 ||
449 !pa_tagstruct_eof(t)) {
454 if (!c->authorized) {
455 pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
459 if (source_index == (uint32_t) -1)
460 source = pa_source_get_default(c->protocol->core);
462 source = pa_idxset_get_by_index(c->protocol->core->sources, source_index);
465 pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
469 if (!(s = record_stream_new(c, source, &ss, name, maxlength, fragment_size))) {
470 pa_pstream_send_error(c->pstream, tag, PA_ERROR_INVALID);
474 reply = pa_tagstruct_new(NULL, 0);
476 pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
477 pa_tagstruct_putu32(reply, tag);
478 pa_tagstruct_putu32(reply, s->index);
479 assert(s->source_output);
480 pa_tagstruct_putu32(reply, s->source_output->index);
481 pa_pstream_send_tagstruct(c->pstream, reply);
484 static void command_delete_record_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
485 struct connection *c = userdata;
487 struct record_stream *s;
490 if (pa_tagstruct_getu32(t, &channel) < 0 ||
491 !pa_tagstruct_eof(t)) {
496 if (!c->authorized) {
497 pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
501 if (!(s = pa_idxset_get_by_index(c->record_streams, channel))) {
502 pa_pstream_send_error(c->pstream, tag, PA_ERROR_EXIST);
506 record_stream_free(s);
507 pa_pstream_send_simple_ack(c->pstream, tag);
510 static void command_exit(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
511 struct connection *c = userdata;
514 if (!pa_tagstruct_eof(t)) {
519 if (!c->authorized) {
520 pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
524 assert(c->protocol && c->protocol->core && c->protocol->core->mainloop);
525 c->protocol->core->mainloop->quit(c->protocol->core->mainloop, 0);
526 pa_pstream_send_simple_ack(c->pstream, tag); /* nonsense */
530 static void command_auth(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
531 struct connection *c = userdata;
535 if (pa_tagstruct_get_arbitrary(t, &cookie, PA_NATIVE_COOKIE_LENGTH) < 0 ||
536 !pa_tagstruct_eof(t)) {
541 if (memcmp(c->protocol->auth_cookie, cookie, PA_NATIVE_COOKIE_LENGTH) != 0) {
542 fprintf(stderr, "protocol-native.c: Denied access to client with invalid authorization key.\n");
543 pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
548 pa_pstream_send_simple_ack(c->pstream, tag);
552 static void command_set_name(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
553 struct connection *c = userdata;
557 if (pa_tagstruct_gets(t, &name) < 0 ||
558 !pa_tagstruct_eof(t)) {
563 pa_client_rename(c->client, name);
564 pa_pstream_send_simple_ack(c->pstream, tag);
568 static void command_lookup(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
569 struct connection *c = userdata;
571 uint32_t index = PA_IDXSET_INVALID;
574 if (pa_tagstruct_gets(t, &name) < 0 ||
575 !pa_tagstruct_eof(t)) {
580 if (!c->authorized) {
581 pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
585 if (command == PA_COMMAND_LOOKUP_SINK) {
586 struct pa_sink *sink;
587 if ((sink = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SINK)))
590 struct pa_source *source;
591 assert(command == PA_COMMAND_LOOKUP_SOURCE);
592 if ((source = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SOURCE)))
593 index = source->index;
596 if (index == PA_IDXSET_INVALID)
597 pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
599 struct pa_tagstruct *reply;
600 reply = pa_tagstruct_new(NULL, 0);
602 pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
603 pa_tagstruct_putu32(reply, tag);
604 pa_tagstruct_putu32(reply, index);
605 pa_pstream_send_tagstruct(c->pstream, reply);
609 static void command_drain_playback_stream(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
610 struct connection *c = userdata;
612 struct playback_stream *s;
615 if (pa_tagstruct_getu32(t, &index) < 0 ||
616 !pa_tagstruct_eof(t)) {
621 if (!c->authorized) {
622 pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
626 if (!(s = pa_idxset_get_by_index(c->playback_streams, index))) {
627 pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
631 s->drain_request = 0;
633 if (!pa_memblockq_is_readable(s->memblockq))
634 pa_pstream_send_simple_ack(c->pstream, tag);
636 s->drain_request = 1;
641 /*** pstream callbacks ***/
643 static void pstream_packet_callback(struct pa_pstream *p, struct pa_packet *packet, void *userdata) {
644 struct connection *c = userdata;
645 assert(p && packet && packet->data && c);
647 if (pa_pdispatch_run(c->pdispatch, packet, c) < 0) {
648 fprintf(stderr, "protocol-native: invalid packet.\n");
653 static void pstream_memblock_callback(struct pa_pstream *p, uint32_t channel, int32_t delta, const struct pa_memchunk *chunk, void *userdata) {
654 struct connection *c = userdata;
655 struct playback_stream *stream;
656 assert(p && chunk && userdata);
658 if (!(stream = pa_idxset_get_by_index(c->playback_streams, channel))) {
659 fprintf(stderr, "protocol-native: client sent block for invalid stream.\n");
664 if (chunk->length >= stream->requested_bytes)
665 stream->requested_bytes = 0;
667 stream->requested_bytes -= chunk->length;
669 pa_memblockq_push_align(stream->memblockq, chunk, delta);
670 assert(stream->sink_input);
671 pa_sink_notify(stream->sink_input->sink);
673 /*fprintf(stderr, "Recieved %u bytes.\n", chunk->length);*/
676 static void pstream_die_callback(struct pa_pstream *p, void *userdata) {
677 struct connection *c = userdata;
681 fprintf(stderr, "protocol-native: connection died.\n");
685 static void pstream_drain_callback(struct pa_pstream *p, void *userdata) {
686 struct connection *c = userdata;
692 /*** client callbacks ***/
694 static void client_kill_cb(struct pa_client *c) {
695 assert(c && c->userdata);
696 connection_free(c->userdata);
699 /*** socket server callbacks ***/
701 static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, void *userdata) {
702 struct pa_protocol_native *p = userdata;
703 struct connection *c;
704 assert(s && io && p);
706 c = malloc(sizeof(struct connection));
708 c->authorized = p->public;
711 c->client = pa_client_new(p->core, "NATIVE", "Client");
713 c->client->kill = client_kill_cb;
714 c->client->userdata = c;
715 c->client->owner = p->module;
717 c->pstream = pa_pstream_new(p->core->mainloop, io);
720 pa_pstream_set_recieve_packet_callback(c->pstream, pstream_packet_callback, c);
721 pa_pstream_set_recieve_memblock_callback(c->pstream, pstream_memblock_callback, c);
722 pa_pstream_set_die_callback(c->pstream, pstream_die_callback, c);
723 pa_pstream_set_drain_callback(c->pstream, pstream_drain_callback, c);
725 c->pdispatch = pa_pdispatch_new(p->core->mainloop, command_table, PA_COMMAND_MAX);
726 assert(c->pdispatch);
728 c->record_streams = pa_idxset_new(NULL, NULL);
729 c->playback_streams = pa_idxset_new(NULL, NULL);
730 assert(c->record_streams && c->playback_streams);
732 c->rrobin_index = PA_IDXSET_INVALID;
734 pa_idxset_put(p->connections, c, NULL);
737 /*** module entry points ***/
739 struct pa_protocol_native* pa_protocol_native_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m) {
740 struct pa_protocol_native *p;
741 assert(core && server);
743 p = malloc(sizeof(struct pa_protocol_native));
746 if (pa_authkey_load_from_home(PA_NATIVE_COOKIE_FILE, p->auth_cookie, sizeof(p->auth_cookie)) < 0) {
755 p->connections = pa_idxset_new(NULL, NULL);
756 assert(p->connections);
758 pa_socket_server_set_callback(p->server, on_connection, p);
763 void pa_protocol_native_free(struct pa_protocol_native *p) {
764 struct connection *c;
767 while ((c = pa_idxset_first(p->connections, NULL)))
769 pa_idxset_free(p->connections, NULL, NULL);
770 pa_socket_server_free(p->server);