]> code.delx.au - pulseaudio/blobdiff - polyp/iochannel.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / iochannel.c
index 813347d421b76c74b888c93a8e20c9f201252fe6..b93860a586ad46fc918476ae0087e4b4c9fcb007 100644 (file)
@@ -4,17 +4,17 @@
   This file is part of polypaudio.
  
   polypaudio is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
-  or (at your option) any later version.
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1 of the
+  License, or (at your option) any later version.
  
   polypaudio is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  General Public License for more details.
+  Lesser General Public License for more details.
  
-  You should have received a copy of the GNU General Public License
-  along with polypaudio; if not, write to the Free Software
+  You should have received a copy of the GNU Lesser General Public
+  License along with polypaudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 ***/
@@ -52,7 +52,7 @@ struct pa_iochannel {
 static void enable_mainloop_sources(struct pa_iochannel *io) {
     assert(io);
 
-    if (io->input_event == io->output_event) {
+    if (io->input_event == io->output_event && io->input_event) {
         enum pa_io_event_flags f = PA_IO_EVENT_NULL;
         assert(io->input_event);
         
@@ -78,18 +78,29 @@ static void callback(struct pa_mainloop_api* m, struct pa_io_event *e, int fd, e
     if ((f & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) && !io->hungup) {
         io->hungup = 1;
         changed = 1;
-    }
-    
-    if ((f & PA_IO_EVENT_INPUT) && !io->readable) {
-        io->readable = 1;
-        changed = 1;
-        assert(e == io->input_event);
-    }
-    
-    if ((f & PA_IO_EVENT_OUTPUT) && !io->writable) {
-        io->writable = 1;
-        changed = 1;
-        assert(e == io->output_event);
+
+        if (e == io->input_event) {
+            io->mainloop->io_free(io->input_event);
+            io->input_event = NULL;
+        }
+
+        if (e == io->output_event) {
+            io->mainloop->io_free(io->output_event);
+            io->output_event = NULL;
+        }
+    } else {
+
+        if ((f & PA_IO_EVENT_INPUT) && !io->readable) {
+            io->readable = 1;
+            changed = 1;
+            assert(e == io->input_event);
+        }
+        
+        if ((f & PA_IO_EVENT_OUTPUT) && !io->writable) {
+            io->writable = 1;
+            changed = 1;
+            assert(e == io->output_event);
+        }
     }
 
     if (changed) {
@@ -158,12 +169,12 @@ void pa_iochannel_free(struct pa_iochannel*io) {
 
 int pa_iochannel_is_readable(struct pa_iochannel*io) {
     assert(io);
-    return io->readable;
+    return io->readable || io->hungup;
 }
 
 int pa_iochannel_is_writable(struct pa_iochannel*io) {
     assert(io);
-    return io->writable;
+    return io->writable && !io->hungup;
 }
 
 int pa_iochannel_is_hungup(struct pa_iochannel*io) {
@@ -185,7 +196,6 @@ ssize_t pa_iochannel_write(struct pa_iochannel*io, const void*data, size_t l) {
 
 ssize_t pa_iochannel_read(struct pa_iochannel*io, void*data, size_t l) {
     ssize_t r;
-    
     assert(io && data && io->ifd >= 0);
     
     if ((r = read(io->ifd, data, l)) >= 0) {
@@ -221,3 +231,4 @@ int pa_iochannel_socket_set_sndbuf(struct pa_iochannel *io, size_t l) {
     assert(io);
     return pa_socket_set_sndbuf(io->ofd, l);
 }
+