[polypaudio-commits] r633 - in /trunk/src: modules/module-protocol-stub.c polypcore/socket-server.c polypcore/socket-server.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Tue Mar 7 08:02:35 PST 2006
Author: ossman
Date: Tue Mar 7 17:02:34 2006
New Revision: 633
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=633&root=polypaudio&view=rev
Log:
Trying to listen on an IPv6 socket by default and only do IPv4 if that fails
(which it doesn't most of the time) is terribly confusing. What the user
most likely wants is for it to listen to both IPv4 and IPv6 and gracefully
continue if only of them succeed.
Modified:
trunk/src/modules/module-protocol-stub.c
trunk/src/polypcore/socket-server.c
trunk/src/polypcore/socket-server.h
Modified: trunk/src/modules/module-protocol-stub.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-protocol-stub.c?rev=633&root=polypaudio&r1=632&r2=633&view=diff
==============================================================================
--- trunk/src/modules/module-protocol-stub.c (original)
+++ trunk/src/modules/module-protocol-stub.c Tue Mar 7 17:02:34 2006
@@ -49,6 +49,7 @@
#include <polypcore/modargs.h>
#include <polypcore/log.h>
#include <polypcore/native-common.h>
+#include <polypcore/xmalloc.h>
#ifdef USE_TCP_SOCKETS
#define SOCKET_DESCRIPTION "(TCP sockets)"
@@ -162,41 +163,71 @@
NULL
};
-static pa_socket_server *create_socket_server(pa_core *c, pa_modargs *ma) {
- pa_socket_server *s;
-#if defined(USE_TCP_SOCKETS)
+struct userdata {
+#if defined(USE_TCP_SOCKETS)
+ void *protocol_ipv4;
+ void *protocol_ipv6;
+#else
+ void *protocol_unix;
+#endif
+};
+
+int pa__init(pa_core *c, pa_module*m) {
+ pa_modargs *ma = NULL;
+ int ret = -1;
+
+ struct userdata *u = NULL;
+
+#if defined(USE_TCP_SOCKETS)
+ pa_socket_server *s_ipv4 = NULL;
+ pa_socket_server *s_ipv6 = NULL;
int loopback = 1;
uint32_t port = IPV4_PORT;
const char *listen_on;
-
- if (pa_modargs_get_value_boolean(ma, "loopback", &loopback) < 0) {
- pa_log(__FILE__": loopback= expects a boolean argument.");
- return NULL;
- }
-
- if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) {
- pa_log(__FILE__": port= expects a numerical argument between 1 and 65535.");
- return NULL;
- }
-
- listen_on = pa_modargs_get_value(ma, "listen", NULL);
-
- if (listen_on) {
- if (!(s = pa_socket_server_new_ip_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE)))
- return NULL;
- } else if (loopback) {
- if (!(s = pa_socket_server_new_ip_loopback(c->mainloop, port, TCPWRAP_SERVICE)))
- return NULL;
- } else {
- if (!(s = pa_socket_server_new_ip_any(c->mainloop, port, TCPWRAP_SERVICE)))
- return NULL;
- }
-
-#else
+#else
+ pa_socket_server *s;
int r;
const char *v;
char tmp[PATH_MAX];
-
+#endif
+
+ assert(c && m);
+
+#if defined(USE_TCP_SOCKETS)
+ if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+ pa_log(__FILE__": Failed to parse module arguments");
+ goto finish;
+ }
+
+ if (pa_modargs_get_value_boolean(ma, "loopback", &loopback) < 0) {
+ pa_log(__FILE__": loopback= expects a boolean argument.");
+ goto fail;
+ }
+
+ if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) {
+ pa_log(__FILE__": port= expects a numerical argument between 1 and 65535.");
+ goto fail;
+ }
+
+ listen_on = pa_modargs_get_value(ma, "listen", NULL);
+
+ if (listen_on) {
+ s_ipv4 = pa_socket_server_new_ipv4_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE);
+ s_ipv6 = pa_socket_server_new_ipv6_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE);
+ if (!s_ipv4 && !s_ipv6)
+ goto fail;
+ } else if (loopback) {
+ s_ipv4 = pa_socket_server_new_ipv4_loopback(c->mainloop, port, TCPWRAP_SERVICE);
+ s_ipv6 = pa_socket_server_new_ipv6_loopback(c->mainloop, port, TCPWRAP_SERVICE);
+ if (!s_ipv4 && !s_ipv6)
+ goto fail;
+ } else {
+ s_ipv4 = pa_socket_server_new_ipv4_any(c->mainloop, port, TCPWRAP_SERVICE);
+ s_ipv6 = pa_socket_server_new_ipv6_any(c->mainloop, port, TCPWRAP_SERVICE);
+ if (!s_ipv4 && !s_ipv6)
+ goto fail;
+ }
+#else
v = pa_modargs_get_value(ma, "socket", UNIX_SOCKET);
assert(v);
@@ -204,42 +235,42 @@
if (pa_make_secure_parent_dir(tmp) < 0) {
pa_log(__FILE__": Failed to create secure socket directory.");
- return NULL;
+ goto fail;
}
if ((r = pa_unix_socket_remove_stale(tmp)) < 0) {
pa_log(__FILE__": Failed to remove stale UNIX socket '%s': %s", tmp, strerror(errno));
- return NULL;
+ goto fail;
}
if (r)
pa_log(__FILE__": Removed stale UNIX socket '%s'.", tmp);
if (!(s = pa_socket_server_new_unix(c->mainloop, tmp)))
- return NULL;
-
-#endif
- return s;
-}
-
-int pa__init(pa_core *c, pa_module*m) {
- pa_socket_server *s;
- pa_modargs *ma = NULL;
- int ret = -1;
- assert(c && m);
-
- if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- pa_log(__FILE__": Failed to parse module arguments");
- goto finish;
- }
-
- if (!(s = create_socket_server(c, ma)))
- goto finish;
-
- if (!(m->userdata = protocol_new(c, s, m, ma))) {
- pa_socket_server_unref(s);
- goto finish;
- }
+ goto fail;
+#endif
+
+ u = pa_xmalloc0(sizeof(struct userdata));
+
+#if defined(USE_TCP_SOCKETS)
+ if (s_ipv4) {
+ u->protocol_ipv4 = protocol_new(c, s_ipv4, m, ma);
+ if (!u->protocol_ipv4)
+ pa_socket_server_unref(s_ipv4);
+ }
+
+ if (s_ipv6) {
+ u->protocol_ipv6 = protocol_new(c, s_ipv4, m, ma);
+ if (!u->protocol_ipv6)
+ pa_socket_server_unref(s_ipv6);
+ }
+
+ if (!u->protocol_ipv4 && !u->protocol_ipv6)
+ goto fail;
+#else
+ if (!(u->protocol_unix = protocol_new(c, s, m, ma)))
+ goto fail;
+#endif
ret = 0;
@@ -248,9 +279,36 @@
pa_modargs_free(ma);
return ret;
+
+fail:
+ if (u) {
+#if defined(USE_TCP_SOCKETS)
+ if (u->protocol_ipv4)
+ protocol_free(u->protocol_ipv4);
+ if (u->protocol_ipv6)
+ protocol_free(u->protocol_ipv6);
+#else
+ if (u->protocol_unix)
+ protocol_free(u->protocol_unix);
+#endif
+ pa_xfree(u);
+ } else {
+#if defined(USE_TCP_SOCKETS)
+ if (s_ipv4)
+ pa_socket_server_unref(s_ipv4);
+ if (s_ipv6)
+ pa_socket_server_unref(s_ipv6);
+#else
+ if (s)
+ pa_socket_server_unref(s);
+#endif
+ }
+
+ goto finish;
}
void pa__done(pa_core *c, pa_module*m) {
+ struct userdata *u;
assert(c && m);
#if defined(USE_PROTOCOL_ESOUND) && !defined(USE_TCP_SOCKETS)
@@ -260,5 +318,18 @@
pa_log("%s: Failed to remove %s : %s.", __FILE__, ESD_UNIX_SOCKET_DIR, strerror (errno));
#endif
- protocol_free(m->userdata);
+ u = m->userdata;
+ assert(u);
+
+#if defined(USE_TCP_SOCKETS)
+ if (u->protocol_ipv4)
+ protocol_free(u->protocol_ipv4);
+ if (u->protocol_ipv6)
+ protocol_free(u->protocol_ipv6);
+#else
+ if (u->protocol_unix)
+ protocol_free(u->protocol_unix);
+#endif
+
+ pa_xfree(u);
}
Modified: trunk/src/polypcore/socket-server.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/socket-server.c?rev=633&root=polypaudio&r1=632&r2=633&view=diff
==============================================================================
--- trunk/src/polypcore/socket-server.c (original)
+++ trunk/src/polypcore/socket-server.c Tue Mar 7 17:02:34 2006
@@ -314,33 +314,49 @@
return NULL;
}
-pa_socket_server* pa_socket_server_new_ip_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
- pa_socket_server *s;
-
- assert(m);
- assert(port > 0);
-
- if (!(s = pa_socket_server_new_ipv6(m, in6addr_loopback.s6_addr, port, tcpwrap_service)))
- s = pa_socket_server_new_ipv4(m, INADDR_LOOPBACK, port, tcpwrap_service);
-
- return s;
-}
-
-pa_socket_server* pa_socket_server_new_ip_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
- pa_socket_server *s;
-
- assert(m);
- assert(port > 0);
-
- if (!(s = pa_socket_server_new_ipv6(m, in6addr_any.s6_addr, port, tcpwrap_service)))
- s = pa_socket_server_new_ipv4(m, INADDR_ANY, port, tcpwrap_service);
-
- return s;
-}
-
-pa_socket_server* pa_socket_server_new_ip_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
+pa_socket_server* pa_socket_server_new_ipv4_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
+ assert(m);
+ assert(port > 0);
+
+ return pa_socket_server_new_ipv4(m, INADDR_LOOPBACK, port, tcpwrap_service);
+}
+
+pa_socket_server* pa_socket_server_new_ipv6_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
+ assert(m);
+ assert(port > 0);
+
+ return pa_socket_server_new_ipv6(m, in6addr_loopback.s6_addr, port, tcpwrap_service);
+}
+
+pa_socket_server* pa_socket_server_new_ipv4_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
+ assert(m);
+ assert(port > 0);
+
+ return pa_socket_server_new_ipv4(m, INADDR_ANY, port, tcpwrap_service);
+}
+
+pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
+ assert(m);
+ assert(port > 0);
+
+ return pa_socket_server_new_ipv6(m, in6addr_any.s6_addr, port, tcpwrap_service);
+}
+
+pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
+ struct in_addr ipv4;
+
+ assert(m);
+ assert(name);
+ assert(port > 0);
+
+ if (inet_pton(AF_INET, name, &ipv4) > 0)
+ return pa_socket_server_new_ipv4(m, ntohl(ipv4.s_addr), port, tcpwrap_service);
+
+ return NULL;
+}
+
+pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
struct in6_addr ipv6;
- struct in_addr ipv4;
assert(m);
assert(name);
@@ -348,11 +364,6 @@
if (inet_pton(AF_INET6, name, &ipv6) > 0)
return pa_socket_server_new_ipv6(m, ipv6.s6_addr, port, tcpwrap_service);
-
- if (inet_pton(AF_INET, name, &ipv4) > 0)
- return pa_socket_server_new_ipv4(m, ntohl(ipv4.s_addr), port, tcpwrap_service);
-
- pa_log_warn(__FILE__": failed to parse '%s'.", name);
return NULL;
}
Modified: trunk/src/polypcore/socket-server.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/socket-server.h?rev=633&root=polypaudio&r1=632&r2=633&view=diff
==============================================================================
--- trunk/src/polypcore/socket-server.h (original)
+++ trunk/src/polypcore/socket-server.h Tue Mar 7 17:02:34 2006
@@ -34,9 +34,12 @@
pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *filename);
pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address, uint16_t port, const char *tcpwrap_service);
pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t address[16], uint16_t port, const char *tcpwrap_service);
-pa_socket_server* pa_socket_server_new_ip_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
-pa_socket_server* pa_socket_server_new_ip_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
-pa_socket_server* pa_socket_server_new_ip_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service);
+pa_socket_server* pa_socket_server_new_ipv4_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
+pa_socket_server* pa_socket_server_new_ipv6_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
+pa_socket_server* pa_socket_server_new_ipv4_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
+pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service);
+pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service);
+pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service);
void pa_socket_server_unref(pa_socket_server*s);
pa_socket_server* pa_socket_server_ref(pa_socket_server *s);
More information about the pulseaudio-commits
mailing list