]> code.delx.au - pulseaudio/commitdiff
a bunch of fixes
authorLennart Poettering <lennart@poettering.net>
Mon, 14 Jun 2004 18:38:50 +0000 (18:38 +0000)
committerLennart Poettering <lennart@poettering.net>
Mon, 14 Jun 2004 18:38:50 +0000 (18:38 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@10 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/idxset.c
src/iochannel.c
src/mainloop.c
src/memblockq.c
src/protocol-simple.c
src/sink.c
src/socket-server.c
src/source.c

index f0d7ad879522d519cfbce55ce7eca90d8360cc19..fe447ac6dc5c12f6b187450ffb6e8503aa7a17dd 100644 (file)
@@ -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;
 }
 
index aa7de714e4e8df0aa43eee547b7f5c2d7cf52b84..2044d561561a6dc9aa89f84e69997b6ae5248151 100644 (file)
@@ -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);
index 0f5811f2fd22970142e6f5e76f0fe04bacb4b8d3..2992673ac549182ffa3f7a3e6390d34f1186ff51 100644 (file)
@@ -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;
     }
index 1424c556769ea918f40be04f815bbd3eeea64284..a422cf093680a6610fb9af6d0dade3311e59098a 100644 (file)
@@ -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;
 }
index 3335bc1499c50d8ff4c1d32193736a8029f1aa44..e930f9aeec53a0278e58d89e8dd9d44a5c54151b 100644 (file)
@@ -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)
index 0e68cf8b2def12ac8f6b8517d6d9fba1f1d6bf14..02ca3468a567038f0246b5c87a040355b9a015b6 100644 (file)
@@ -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;
 }
 
index 2a1db9a03f7227a975fadac8f1c76726f9474e3d..6ad225e395bc122e39e3181fbfbd50ec2e24338f 100644 (file)
@@ -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;
index 98df2447b5da76886f974ab8430af6f91e738d31..a1e7b2458548759e9752ca700b69bd0cba86d8a2 100644 (file)
@@ -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);