[pulseaudio-discuss] [PATCH 02/10] Use <pulsecore/socket.h> instead of <sys/socket.h>
Maarten Bosmans
mkbosmans at gmail.com
Wed Jan 5 17:39:49 PST 2011
The check whether POSIX socket.h or WIN32 winsock2.h must be included can be
made centrally. The downside is that some functionality of e.g. arpa/inet.h is
also implemented in winsock.h, so that some files that don't use socket
functions, but do use inet.h functions, must also include pulsecore/socket.h.
(as well as arpa/inet.h)
---
src/Makefile.am | 2 +-
src/daemon/main.c | 2 +-
src/modules/module-esound-sink.c | 2 +-
src/modules/module-protocol-stub.c | 5 +----
src/pulse/context.c | 6 +-----
src/pulse/mainloop.c | 2 +-
src/pulse/timeval.c | 1 -
src/pulse/util.c | 6 +-----
src/pulsecore/core-util.c | 3 +--
src/pulsecore/core-util.h | 2 +-
src/pulsecore/creds.h | 4 +---
src/pulsecore/inet_ntop.c | 6 +-----
src/pulsecore/inet_ntop.h | 6 +-----
src/pulsecore/inet_pton.c | 7 +------
src/pulsecore/inet_pton.h | 6 +-----
src/pulsecore/iochannel.c | 7 ++-----
src/pulsecore/ioline.c | 2 +-
src/pulsecore/ipacl.c | 5 +----
src/pulsecore/parseaddr.c | 4 +++-
src/pulsecore/pipe.c | 6 +-----
src/pulsecore/poll.c | 3 +--
src/pulsecore/pstream.c | 6 +-----
src/pulsecore/rtpoll.c | 1 -
src/pulsecore/socket-client.c | 7 ++-----
src/pulsecore/socket-server.c | 6 +-----
src/pulsecore/socket-util.c | 6 +-----
src/pulsecore/socket-util.h | 2 +-
src/pulsecore/socket.h | 31 +++++++++++++++++++++++++++++++
src/pulsecore/tagstruct.c | 2 +-
src/pulsecore/winsock.h | 26 --------------------------
src/tests/ipacl-test.c | 8 ++------
31 files changed, 63 insertions(+), 119 deletions(-)
create mode 100644 src/pulsecore/socket.h
delete mode 100644 src/pulsecore/winsock.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 15a4644..52e4219 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -636,7 +636,7 @@ libpulsecommon_ at PA_MAJORMINOR@_la_SOURCES = \
pulsecore/tokenizer.c pulsecore/tokenizer.h \
pulsecore/usergroup.c pulsecore/usergroup.h \
pulsecore/sndfile-util.c pulsecore/sndfile-util.h \
- pulsecore/winsock.h
+ pulsecore/socket.h
libpulsecommon_ at PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS)
libpulsecommon_ at PA_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 0db794b..de809b1 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -70,7 +70,7 @@
#include <pulse/i18n.h>
#include <pulsecore/lock-autospawn.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core.h>
diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c
index 0d04fff..9eba8ac 100644
--- a/src/modules/module-esound-sink.c
+++ b/src/modules/module-esound-sink.c
@@ -31,7 +31,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
-#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/ioctl.h>
@@ -44,6 +43,7 @@
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/iochannel.h>
#include <pulsecore/sink.h>
diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c
index e21186b..7ba5405 100644
--- a/src/modules/module-protocol-stub.c
+++ b/src/modules/module-protocol-stub.c
@@ -30,9 +30,6 @@
#include <unistd.h>
#include <limits.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
@@ -42,9 +39,9 @@
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
#include <pulsecore/module.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-server.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/core-util.h>
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 7a539b4..ca81650 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -39,9 +39,6 @@
#include <sys/wait.h>
#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -57,9 +54,7 @@
#include <pulse/mainloop.h>
#include <pulse/timeval.h>
-#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
-
#include <pulsecore/native-common.h>
#include <pulsecore/pdispatch.h>
#include <pulsecore/pstream.h>
@@ -69,6 +64,7 @@
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/creds.h>
#include <pulsecore/macro.h>
diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 8f743ec..8c26138 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -47,7 +47,7 @@
#include <pulsecore/llist.h>
#include <pulsecore/log.h>
#include <pulsecore/core-error.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
#include "mainloop.h"
diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c
index cde4417..c4a0841 100644
--- a/src/pulse/timeval.c
+++ b/src/pulse/timeval.c
@@ -31,7 +31,6 @@
#include <windows.h>
#endif
-#include <pulsecore/winsock.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-util.h>
diff --git a/src/pulse/util.c b/src/pulse/util.c
index ca766da..4924bf5 100644
--- a/src/pulse/util.c
+++ b/src/pulse/util.c
@@ -37,10 +37,6 @@
#include <pwd.h>
#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
@@ -56,7 +52,7 @@
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/log.h>
#include <pulsecore/core-util.h>
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index effc598..ecbbd3b 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -43,7 +43,6 @@
#include <regex.h>
#include <langinfo.h>
#include <sys/utsname.h>
-#include <sys/socket.h>
#ifdef HAVE_STRTOF_L
#include <locale.h>
@@ -110,7 +109,7 @@
#include <pulse/utf8.h>
#include <pulsecore/core-error.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/thread.h>
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 0d63cfc..8619330 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -28,7 +28,6 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
-#include <sys/socket.h>
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
@@ -36,6 +35,7 @@
#include <pulse/gccmacro.h>
#include <pulsecore/macro.h>
+#include <pulsecore/socket.h>
#ifndef PACKAGE
#error "Please include config.h before including this file!"
diff --git a/src/pulsecore/creds.h b/src/pulsecore/creds.h
index c15c469..b5c1c53 100644
--- a/src/pulsecore/creds.h
+++ b/src/pulsecore/creds.h
@@ -28,9 +28,7 @@
#error "Please include config.h before including this file!"
#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
+#include "socket.h"
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
diff --git a/src/pulsecore/inet_ntop.c b/src/pulsecore/inet_ntop.c
index 012a1a0..1948f0f 100644
--- a/src/pulsecore/inet_ntop.c
+++ b/src/pulsecore/inet_ntop.c
@@ -28,11 +28,7 @@
#ifndef HAVE_INET_NTOP
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include "winsock.h"
+#include "socket.h"
#include "inet_ntop.h"
diff --git a/src/pulsecore/inet_ntop.h b/src/pulsecore/inet_ntop.h
index 7fb67b4..f730049 100644
--- a/src/pulsecore/inet_ntop.h
+++ b/src/pulsecore/inet_ntop.h
@@ -1,11 +1,7 @@
#ifndef fooinet_ntophfoo
#define fooinet_ntophfoo
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include "winsock.h"
+#include "socket.h"
const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
diff --git a/src/pulsecore/inet_pton.c b/src/pulsecore/inet_pton.c
index abdfa46..041902a 100644
--- a/src/pulsecore/inet_pton.c
+++ b/src/pulsecore/inet_pton.c
@@ -28,12 +28,7 @@
#ifndef HAVE_INET_PTON
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include "winsock.h"
-
+#include "socket.h"
#include "inet_pton.h"
int inet_pton(int af, const char *src, void *dst) {
diff --git a/src/pulsecore/inet_pton.h b/src/pulsecore/inet_pton.h
index 111b4a0..bc3041d 100644
--- a/src/pulsecore/inet_pton.h
+++ b/src/pulsecore/inet_pton.h
@@ -1,11 +1,7 @@
#ifndef fooinet_ptonhfoo
#define fooinet_ptonhfoo
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include "winsock.h"
+#include "socket.h"
int inet_pton(int af, const char *src, void *dst);
diff --git a/src/pulsecore/iochannel.c b/src/pulsecore/iochannel.c
index f85c989..f89b067 100644
--- a/src/pulsecore/iochannel.c
+++ b/src/pulsecore/iochannel.c
@@ -28,19 +28,16 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
+
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
-#include "winsock.h"
-
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
diff --git a/src/pulsecore/ioline.c b/src/pulsecore/ioline.c
index 7afdb08..963f7d2 100644
--- a/src/pulsecore/ioline.c
+++ b/src/pulsecore/ioline.c
@@ -30,7 +30,7 @@
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
diff --git a/src/pulsecore/ipacl.c b/src/pulsecore/ipacl.c
index 312e040..de31a83 100644
--- a/src/pulsecore/ipacl.c
+++ b/src/pulsecore/ipacl.c
@@ -28,9 +28,6 @@
#include <sys/types.h>
#include <string.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -50,7 +47,7 @@
#include <pulsecore/llist.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#ifndef HAVE_INET_PTON
#include "inet_pton.h"
diff --git a/src/pulsecore/parseaddr.c b/src/pulsecore/parseaddr.c
index 44cd9a0..7f6cd90 100644
--- a/src/pulsecore/parseaddr.c
+++ b/src/pulsecore/parseaddr.c
@@ -25,8 +25,10 @@
#include <string.h>
#include <stdlib.h>
+
+#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
-#include <sys/socket.h>
+#endif
#include <pulse/xmalloc.h>
#include <pulse/util.h>
diff --git a/src/pulsecore/pipe.c b/src/pulsecore/pipe.c
index c21e4b1..db8e16f 100644
--- a/src/pulsecore/pipe.c
+++ b/src/pulsecore/pipe.c
@@ -29,11 +29,7 @@
#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include "winsock.h"
+#include <pulsecore/socket.h>
#include "pipe.h"
diff --git a/src/pulsecore/poll.c b/src/pulsecore/poll.c
index b98fb16..6053a41 100644
--- a/src/pulsecore/poll.c
+++ b/src/pulsecore/poll.c
@@ -45,8 +45,7 @@
#include <sys/select.h>
#endif
-#include "winsock.h"
-
+#include <pulsecore/socket.h>
#include <pulsecore/core-util.h>
#include <pulse/util.h>
diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c
index 1d4ac17..3b1ecff 100644
--- a/src/pulsecore/pstream.c
+++ b/src/pulsecore/pstream.c
@@ -28,9 +28,6 @@
#include <stdlib.h>
#include <unistd.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -38,10 +35,9 @@
#include <netinet/in.h>
#endif
-
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/queue.h>
#include <pulsecore/log.h>
#include <pulsecore/core-scache.h>
diff --git a/src/pulsecore/rtpoll.c b/src/pulsecore/rtpoll.c
index 2ef7873..98d7d62 100644
--- a/src/pulsecore/rtpoll.c
+++ b/src/pulsecore/rtpoll.c
@@ -40,7 +40,6 @@
#include <pulsecore/llist.h>
#include <pulsecore/flist.h>
#include <pulsecore/core-util.h>
-#include <pulsecore/winsock.h>
#include <pulsecore/ratelimit.h>
#include <pulse/rtclock.h>
diff --git a/src/pulsecore/socket-client.c b/src/pulsecore/socket-client.c
index 7c449be..31acfd2 100644
--- a/src/pulsecore/socket-client.c
+++ b/src/pulsecore/socket-client.c
@@ -32,9 +32,6 @@
#include <string.h>
#include <stdlib.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -56,9 +53,9 @@
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
-#include <pulsecore/core-error.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
+#include <pulsecore/core-error.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
#include <pulsecore/socket-util.h>
diff --git a/src/pulsecore/socket-server.c b/src/pulsecore/socket-server.c
index 3b7c697..9ab07ba 100644
--- a/src/pulsecore/socket-server.c
+++ b/src/pulsecore/socket-server.c
@@ -32,9 +32,6 @@
#include <unistd.h>
#include <sys/stat.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#ifndef SUN_LEN
@@ -61,11 +58,10 @@
#include "inet_pton.h"
#endif
-#include "winsock.h"
-
#include <pulse/xmalloc.h>
#include <pulse/util.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c
index 2cc9882..47336a2 100644
--- a/src/pulsecore/socket-util.c
+++ b/src/pulsecore/socket-util.c
@@ -36,9 +36,6 @@
#include <unistd.h>
#include <sys/stat.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -65,14 +62,13 @@
#include "inet_ntop.h"
#endif
-#include "winsock.h"
-
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
+#include <pulsecore/socket.h>
#include "socket-util.h"
diff --git a/src/pulsecore/socket-util.h b/src/pulsecore/socket-util.h
index f6d1637..154afd4 100644
--- a/src/pulsecore/socket-util.h
+++ b/src/pulsecore/socket-util.h
@@ -24,8 +24,8 @@
***/
#include <sys/types.h>
-#include <sys/socket.h>
+#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
void pa_socket_peer_to_string(int fd, char *c, size_t l);
diff --git a/src/pulsecore/socket.h b/src/pulsecore/socket.h
new file mode 100644
index 0000000..0d38bee
--- /dev/null
+++ b/src/pulsecore/socket.h
@@ -0,0 +1,31 @@
+#ifndef foopulsecoresockethfoo
+#define foopulsecoresockethfoo
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+
+#define ESHUTDOWN WSAESHUTDOWN
+#define ECONNRESET WSAECONNRESET
+#define ECONNABORTED WSAECONNABORTED
+#define ENETRESET WSAENETRESET
+#define EINPROGRESS WSAEINPROGRESS
+#define EAFNOSUPPORT WSAEAFNOSUPPORT
+#define ETIMEDOUT WSAETIMEDOUT
+#define ECONNREFUSED WSAECONNREFUSED
+#define EHOSTUNREACH WSAEHOSTUNREACH
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#define EADDRINUSE WSAEADDRINUSE
+
+typedef long suseconds_t;
+
+#endif
+
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+
+#endif
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
index 330b759..804b9f9 100644
--- a/src/pulsecore/tagstruct.c
+++ b/src/pulsecore/tagstruct.c
@@ -35,7 +35,7 @@
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
#include "tagstruct.h"
diff --git a/src/pulsecore/winsock.h b/src/pulsecore/winsock.h
deleted file mode 100644
index 0352bf4..0000000
--- a/src/pulsecore/winsock.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef foowinsockhfoo
-#define foowinsockhfoo
-
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-
-#define ESHUTDOWN WSAESHUTDOWN
-#define ECONNRESET WSAECONNRESET
-#define ECONNABORTED WSAECONNABORTED
-#define ENETRESET WSAENETRESET
-#define EINPROGRESS WSAEINPROGRESS
-#define EAFNOSUPPORT WSAEAFNOSUPPORT
-#define ETIMEDOUT WSAETIMEDOUT
-#define ECONNREFUSED WSAECONNREFUSED
-#define EHOSTUNREACH WSAEHOSTUNREACH
-#define EWOULDBLOCK WSAEWOULDBLOCK
-
-typedef long suseconds_t;
-
-#endif
-
-#ifdef HAVE_WS2TCPIP_H
-#include <ws2tcpip.h>
-#endif
-
-#endif
diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c
index 57b7068..88bd6c6 100644
--- a/src/tests/ipacl-test.c
+++ b/src/tests/ipacl-test.c
@@ -8,9 +8,6 @@
#include <assert.h>
#include <string.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -24,9 +21,8 @@
#include <arpa/inet.h>
#endif
-#include "../pulsecore/winsock.h"
-#include "../pulsecore/macro.h"
-
+#include <pulsecore/socket.h>
+#include <pulsecore/macro.h>
#include <pulsecore/ipacl.h>
int main(int argc, char *argv[]) {
--
1.7.1
More information about the pulseaudio-discuss
mailing list