From c8cf0c1ce9cf1b38b302ae4a2a6fa798fef85f08 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 14 Jun 2004 18:38:50 +0000 Subject: a bunch of fixes git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@10 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/idxset.c | 7 +++++-- src/iochannel.c | 8 ++++---- src/mainloop.c | 6 ++++-- src/memblockq.c | 4 ++-- src/protocol-simple.c | 9 ++++++--- src/sink.c | 2 ++ src/socket-server.c | 6 +++++- src/source.c | 7 ------- 8 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/idxset.c b/src/idxset.c index f0d7ad87..fe447ac6 100644 --- a/src/idxset.c +++ b/src/idxset.c @@ -152,8 +152,8 @@ int idxset_put(struct idxset*s, void *p, uint32_t *index) { s->hash_table[h] = e; /* Insert into array */ - extend_array(s, s->index); - a = array_index(s, s->index); + extend_array(s, e->index); + a = array_index(s, e->index); assert(a && !*a); *a = e; @@ -185,6 +185,9 @@ void* idxset_get_by_index(struct idxset*s, uint32_t index) { if (!(a = array_index(s, index))) return NULL; + if (!*a) + return NULL; + return (*a)->data; } diff --git a/src/iochannel.c b/src/iochannel.c index aa7de714..2044d561 100644 --- a/src/iochannel.c +++ b/src/iochannel.c @@ -41,15 +41,15 @@ static void enable_mainloop_sources(struct iochannel *io) { static void callback(struct mainloop_source*s, int fd, enum mainloop_io_event events, void *userdata) { struct iochannel *io = userdata; - int changed; + int changed = 0; assert(s && fd >= 0 && userdata); - if (events & MAINLOOP_IO_EVENT_IN && !io->readable) { + if ((events & MAINLOOP_IO_EVENT_IN) && !io->readable) { io->readable = 1; changed = 1; } - if (events & MAINLOOP_IO_EVENT_OUT && !io->writable) { + if ((events & MAINLOOP_IO_EVENT_OUT) && !io->writable) { io->writable = 1; changed = 1; } @@ -116,7 +116,7 @@ void iochannel_free(struct iochannel*io) { if (io->input_source) mainloop_source_free(io->input_source); - if (io->output_source) + if (io->output_source && io->output_source != io->input_source) mainloop_source_free(io->output_source); free(io); diff --git a/src/mainloop.c b/src/mainloop.c index 0f5811f2..2992673a 100644 --- a/src/mainloop.c +++ b/src/mainloop.c @@ -248,8 +248,10 @@ int mainloop_iterate(struct mainloop *m, int block) { } } - if (m->rebuild_pollfds) + if (m->rebuild_pollfds) { rebuild_pollfds(m); + m->rebuild_pollfds = 0; + } m->running = 1; @@ -431,7 +433,7 @@ void mainloop_source_enable(struct mainloop_source*s, int b) { void mainloop_source_io_set_events(struct mainloop_source*s, enum mainloop_io_event events) { assert(s && !s->dead && s->type == MAINLOOP_SOURCE_TYPE_IO); - if ((s->io.events && !events) || (!s->io.events && events)) { + if (s->io.events != events) { assert(s->mainloop); s->mainloop->rebuild_pollfds = 1; } diff --git a/src/memblockq.c b/src/memblockq.c index 1424c556..a422cf09 100644 --- a/src/memblockq.c +++ b/src/memblockq.c @@ -46,7 +46,7 @@ void memblockq_free(struct memblockq* bq) { void memblockq_push(struct memblockq* bq, struct memchunk *chunk, size_t delta) { struct memblock_list *q; - assert(bq && chunk && chunk->memblock && chunk->index); + assert(bq && chunk && chunk->memblock && chunk->length); q = malloc(sizeof(struct memblock_list)); assert(q); @@ -152,5 +152,5 @@ void memblockq_empty(struct memblockq *bq) { int memblockq_is_empty(struct memblockq *bq) { assert(bq); - return bq->total_length >= bq->base; + return bq->total_length < bq->base; } diff --git a/src/protocol-simple.c b/src/protocol-simple.c index 3335bc14..e930f9ae 100644 --- a/src/protocol-simple.c +++ b/src/protocol-simple.c @@ -103,7 +103,10 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us c->istream = NULL; c->ostream = NULL; c->protocol = p; - + + c->client = client_new(p->core, "SIMPLE", "Client"); + assert(c->client); + if (p->mode & PROTOCOL_SIMPLE_RECORD) { struct source *source; @@ -128,8 +131,6 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us assert(c->istream); } - c->client = client_new(p->core, "SIMPLE", "Client"); - assert(c->client); iochannel_set_callback(c->io, io_callback, c); idxset_put(p->connections, c, NULL); @@ -137,6 +138,8 @@ static void on_connection(struct socket_server*s, struct iochannel *io, void *us fail: if (c) { + if (c->client) + client_free(c->client); if (c->istream) input_stream_free(c->istream); if (c->ostream) diff --git a/src/sink.c b/src/sink.c index 0e68cf8b..02ca3468 100644 --- a/src/sink.c +++ b/src/sink.c @@ -77,6 +77,8 @@ static int get_max_length(void *p, uint32_t index, int *del, void*userdata) { info->count++; info->last_input_stream = i; + memblock_unref(chunk.memblock); + return 0; } diff --git a/src/socket-server.c b/src/socket-server.c index 2a1db9a0..6ad225e3 100644 --- a/src/socket-server.c +++ b/src/socket-server.c @@ -104,6 +104,7 @@ fail: struct socket_server* socket_server_new_ipv4(struct mainloop *m, uint32_t address, uint16_t port) { int fd = -1; struct sockaddr_in sa; + int on = 1; assert(m && port); @@ -112,10 +113,13 @@ struct socket_server* socket_server_new_ipv4(struct mainloop *m, uint32_t addres goto fail; } + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) + fprintf(stderr, "setsockopt(): %s\n", strerror(errno)); + sa.sin_family = AF_INET; sa.sin_port = htons(port); sa.sin_addr.s_addr = htonl(address); - + if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) { fprintf(stderr, "bind(): %s\n", strerror(errno)); goto fail; diff --git a/src/source.c b/src/source.c index 98df2447..a1e7b245 100644 --- a/src/source.c +++ b/src/source.c @@ -27,12 +27,6 @@ struct source* source_new(struct core *core, const char *name, const struct samp return s; } -static void do_free(void *p, void *userdata) { - struct output_stream *o = p; - assert(o); - output_stream_free(o); -}; - void source_free(struct source *s) { struct output_stream *o; assert(s); @@ -42,7 +36,6 @@ void source_free(struct source *s) { idxset_free(s->output_streams, NULL, NULL); idxset_remove_by_data(s->core->sources, s, NULL); - idxset_free(s->output_streams, do_free, NULL); free(s->name); free(s); -- cgit