]> code.delx.au - pulseaudio/commitdiff
Add a wrapper around close() to work around Windows' ass backwards way of
authorPierre Ossman <ossman@cendio.se>
Wed, 14 Feb 2007 12:13:49 +0000 (12:13 +0000)
committerPierre Ossman <ossman@cendio.se>
Wed, 14 Feb 2007 12:13:49 +0000 (12:13 +0000)
handling sockets.

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1429 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/pulsecore/core-util.c
src/pulsecore/core-util.h
src/pulsecore/iochannel.c
src/pulsecore/pipe.c
src/pulsecore/socket-client.c
src/pulsecore/socket-server.c
src/pulsecore/socket-util.c

index ac1023a0d4adca7919ee945efa8d0b988a5c6ed2..cc0fb205d88a17ee8945680d5e3bbd0925a4bc88 100644 (file)
@@ -5,7 +5,7 @@
 
   Copyright 2004-2006 Lennart Poettering
   Copyright 2004 Joe Marcus Clarke
-  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+  Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
@@ -348,6 +348,26 @@ ssize_t pa_loop_write(int fd, const void*data, size_t size, int *type) {
     return ret;
 }
 
+/** Platform independent read function. Necessary since not all
+ * systems treat all file descriptors equal. */
+int pa_close(int fd)
+{
+#ifdef OS_IS_WIN32
+    int ret;
+
+    ret = closesocket(fd);
+    if (ret == 0)
+        return 0;
+
+    if (WSAGetLastError() != WSAENOTSOCK) {
+        errno = WSAGetLastError();
+        return ret;
+    }
+#endif
+
+    return close(fd);
+}
+
 /* Print a warning messages in case that the given signal is not
  * blocked or trapped */
 void pa_check_signal_is_blocked(int sig) {
index a1da3e2875c22bd0a1f245cbd8c1baa07c75a736..1d921e036c982566880543f1fe3f4c5d750067d0 100644 (file)
@@ -7,7 +7,7 @@
   This file is part of PulseAudio.
 
   Copyright 2004-2006 Lennart Poettering
-  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+  Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
@@ -44,6 +44,8 @@ ssize_t pa_write(int fd, const void *buf, size_t count, int *type);
 ssize_t pa_loop_read(int fd, void*data, size_t size, int *type);
 ssize_t pa_loop_write(int fd, const void*data, size_t size, int *type);
 
+int pa_close(int fd);
+
 void pa_check_signal_is_blocked(int sig);
 
 char *pa_sprintf_malloc(const char *format, ...) PA_GCC_PRINTF_ATTR(1,2);
index 2f6fdd39f6f07ed1d35dfca47dd00b9f7038141e..6f58ae755ac4639212fb9a47e414fa021733964e 100644 (file)
@@ -4,7 +4,7 @@
   This file is part of PulseAudio.
 
   Copyright 2004-2006 Lennart Poettering
-  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+  Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
@@ -174,10 +174,9 @@ void pa_iochannel_free(pa_iochannel*io) {
 
     if (!io->no_close) {
         if (io->ifd >= 0)
-
-            close(io->ifd);
+            pa_close(io->ifd);
         if (io->ofd >= 0 && io->ofd != io->ifd)
-            close(io->ofd);
+            pa_close(io->ofd);
     }
 
     pa_xfree(io);
index a659915e90bf602ff6d17f1b0f7ca4f9b829ead7..7f6bb2e9e3dd6201dbfd01bc5319c8ed813d6913 100644 (file)
@@ -3,7 +3,7 @@
 /***
   This file is part of PulseAudio.
 
-  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+  Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
@@ -144,17 +144,17 @@ int pipe(int filedes[2]) {
     if ((addr.sin_port != peer.sin_port) || (addr.sin_addr.s_addr != peer.sin_addr.s_addr))
         goto error;
 
-    close(listener);
+    pa_close(listener);
 
     return 0;
 
 error:
        if (listener >= 0)
-               close(listener);
+               pa_close(listener);
        if (filedes[0] >= 0)
-               close(filedes[0]);
+               pa_close(filedes[0]);
        if (filedes[1] >= 0)
-               close(filedes[0]);
+               pa_close(filedes[0]);
 
        return -1;
 }
index 4ea81113342094ec911d412ebf7ed779796f9a34..b99c8025d3584057c539516d0bfd406b8ea34106 100644 (file)
@@ -4,7 +4,7 @@
   This file is part of PulseAudio.
 
   Copyright 2004-2006 Lennart Poettering
-  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+  Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
@@ -163,7 +163,7 @@ static void do_call(pa_socket_client *c) {
 
 finish:
     if (!io && c->fd >= 0)
-        close(c->fd);
+        pa_close(c->fd);
     c->fd = -1;
 
     free_events(c);
@@ -310,7 +310,7 @@ static void socket_client_free(pa_socket_client *c) {
     free_events(c);
 
     if (c->fd >= 0)
-        close(c->fd);
+        pa_close(c->fd);
 
 #ifdef HAVE_LIBASYNCNS
     if (c->asyncns_query)
@@ -403,7 +403,7 @@ static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeva
     assert(c);
 
     if (c->fd >= 0) {
-        close(c->fd);
+        pa_close(c->fd);
         c->fd = -1;
     }
 
index eaa8eb910d1d8a1fbe9538fcf2f7dfed5ad4b879..b5a6dc3177ba083a670ff3aba040cf70ca9d1013 100644 (file)
@@ -4,7 +4,7 @@
   This file is part of PulseAudio.
 
   Copyright 2004-2006 Lennart Poettering
-  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+  Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
@@ -106,7 +106,7 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
     pa_fd_set_cloexec(nfd, 1);
 
     if (!s->on_connection) {
-        close(nfd);
+        pa_close(nfd);
         goto finish;
     }
 
@@ -119,7 +119,7 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
         fromhost(&req);
         if (!hosts_access(&req)) {
             pa_log_warn("TCP connection refused by tcpwrap.");
-            close(nfd);
+            pa_close(nfd);
             goto finish;
         }
 
@@ -216,7 +216,7 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
 
 fail:
     if (fd >= 0)
-        close(fd);
+        pa_close(fd);
 
     return NULL;
 }
@@ -275,7 +275,7 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
 
 fail:
     if (fd >= 0)
-        close(fd);
+        pa_close(fd);
 
     return NULL;
 }
@@ -331,7 +331,7 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
 
 fail:
     if (fd >= 0)
-        close(fd);
+        pa_close(fd);
 
     return NULL;
 }
@@ -398,7 +398,7 @@ static void socket_server_free(pa_socket_server*s) {
         pa_xfree(s->filename);
     }
 
-    close(s->fd);
+    pa_close(s->fd);
 
     pa_xfree(s->tcpwrap_service);
 
index 5e2cfe037918568ac5cc9f41f8202691529f5196..673058e2a994638922a94ebbac23f4c74a9bbc56 100644 (file)
@@ -5,7 +5,7 @@
 
   Copyright 2004-2006 Lennart Poettering
   Copyright 2004 Joe Marcus Clarke
-  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
+  Copyright 2006-2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
@@ -236,7 +236,7 @@ int pa_unix_socket_is_stale(const char *fn) {
 
 finish:
     if (fd >= 0)
-        close(fd);
+        pa_close(fd);
 
     return ret;
 }