summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac10
-rw-r--r--doxygen/doxygen.conf.in3
-rw-r--r--polyp/Makefile.am8
-rw-r--r--polyp/socket-client.c142
4 files changed, 135 insertions, 28 deletions
diff --git a/configure.ac b/configure.ac
index dda1f4c6..e287f279 100644
--- a/configure.ac
+++ b/configure.ac
@@ -133,6 +133,16 @@ AC_SUBST(HOWL_LIBS)
AC_SUBST(HAVE_HOWL)
AM_CONDITIONAL([HAVE_HOWL], [test "x$HAVE_HOWL" = x1])
+PKG_CHECK_MODULES(LIBASYNCNS, [ libasyncns >= 0.1 ], HAVE_LIBASYNCNS=1, HAVE_LIBASYNCNS=0)
+AC_SUBST(LIBASYNCNS_CFLAGS)
+AC_SUBST(LIBASYNCNS_LIBS)
+AC_SUBST(HAVE_LIBASYNCNS)
+AM_CONDITIONAL([HAVE_LIBASYNCNS], [test "x$HAVE_LIBASYNCNS" = x1])
+
+if test "x$HAVE_LIBASYNCNS" != "x0" ; then
+ AC_DEFINE([HAVE_LIBASYNCNS], 1, [Have libasyncns?])
+fi
+
AC_PATH_PROG([M4], [m4 gm4], [no])
if test "x$M4" = xno ; then
AC_MSG_ERROR([m4 missing])
diff --git a/doxygen/doxygen.conf.in b/doxygen/doxygen.conf.in
index 51b2a113..c0e122ea 100644
--- a/doxygen/doxygen.conf.in
+++ b/doxygen/doxygen.conf.in
@@ -1151,3 +1151,6 @@ DOT_CLEANUP = YES
# used. If set to NO the values of all tags below this one will be ignored.
SEARCHENGINE = NO
+
+SHOW_DIRECTORIES=NO
+
diff --git a/polyp/Makefile.am b/polyp/Makefile.am
index 0c491ce5..352e6a7a 100644
--- a/polyp/Makefile.am
+++ b/polyp/Makefile.am
@@ -470,6 +470,7 @@ libpolyp_@PA_MAJORMINOR@_la_SOURCES = polyplib.h \
libpolyp_@PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS)
libpolyp_@PA_MAJORMINOR@_la_LDFLAGS = -version-info 0:0:0
+libpolyp_@PA_MAJORMINOR@_la_LIBADD = $(AM_LIBADD)
libpolyp_mainloop_@PA_MAJORMINOR@_la_SOURCES = mainloop-api.h mainloop-api.c \
mainloop.c mainloop.h \
@@ -581,6 +582,13 @@ libpolyp_@PA_MAJORMINOR@_la_SOURCES += x11prop.c x11prop.h client-conf-x11.c cli
endif
+### libasyncns stuff
+
+if HAVE_LIBASYNCNS
+libpolyp_@PA_MAJORMINOR@_la_CFLAGS += $(LIBASYNCNS_CFLAGS)
+libpolyp_@PA_MAJORMINOR@_la_LIBADD += $(LIBASYNCNS_LIBS)
+endif
+
### ALSA modules
if HAVE_ALSA
diff --git a/polyp/socket-client.c b/polyp/socket-client.c
index 4ec42dab..8ac04a8b 100644
--- a/polyp/socket-client.c
+++ b/polyp/socket-client.c
@@ -23,6 +23,8 @@
#include <config.h>
#endif
+/* #undef HAVE_LIBASYNCNS */
+
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
@@ -33,6 +35,9 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
+#ifdef HAVE_LIBASYNCNS
+#include <asyncns.h>
+#endif
#include "socket-client.h"
#include "socket-util.h"
@@ -50,6 +55,11 @@ struct pa_socket_client {
void (*callback)(struct pa_socket_client*c, struct pa_iochannel *io, void *userdata);
void *userdata;
int local;
+#ifdef HAVE_LIBASYNCNS
+ asyncns_t *asyncns;
+ asyncns_query_t * asyncns_query;
+ struct pa_io_event *asyncns_io_event;
+#endif
};
static struct pa_socket_client*pa_socket_client_new(struct pa_mainloop_api *m) {
@@ -65,6 +75,13 @@ static struct pa_socket_client*pa_socket_client_new(struct pa_mainloop_api *m) {
c->callback = NULL;
c->userdata = NULL;
c->local = 0;
+
+#ifdef HAVE_LIBASYNCNS
+ c->asyncns = NULL;
+ c->asyncns_io_event = NULL;
+ c->asyncns_query = NULL;
+#endif
+
return c;
}
@@ -75,6 +92,9 @@ static void do_call(struct pa_socket_client *c) {
assert(c && c->callback);
pa_socket_client_ref(c);
+
+ if (c->fd < 0)
+ goto finish;
lerror = sizeof(error);
if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, &error, &lerror) < 0) {
@@ -97,7 +117,7 @@ static void do_call(struct pa_socket_client *c) {
assert(io);
finish:
- if (!io)
+ if (!io && c->fd >= 0)
close(c->fd);
c->fd = -1;
@@ -169,12 +189,11 @@ struct pa_socket_client* pa_socket_client_new_unix(struct pa_mainloop_api *m, co
return pa_socket_client_new_sockaddr(m, (struct sockaddr*) &sa, sizeof(sa));
}
-struct pa_socket_client* pa_socket_client_new_sockaddr(struct pa_mainloop_api *m, const struct sockaddr *sa, size_t salen) {
- struct pa_socket_client *c;
- assert(m && sa);
- c = pa_socket_client_new(m);
+static int sockaddr_prepare(struct pa_socket_client *c, const struct sockaddr *sa, size_t salen) {
assert(c);
-
+ assert(sa);
+ assert(salen);
+
switch (sa->sa_family) {
case AF_UNIX:
c->local = 1;
@@ -194,7 +213,7 @@ struct pa_socket_client* pa_socket_client_new_sockaddr(struct pa_mainloop_api *m
if ((c->fd = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) {
pa_log(__FILE__": socket(): %s\n", strerror(errno));
- goto fail;
+ return -1;
}
pa_fd_set_cloexec(c->fd, 1);
@@ -204,6 +223,18 @@ struct pa_socket_client* pa_socket_client_new_sockaddr(struct pa_mainloop_api *m
pa_socket_low_delay(c->fd);
if (do_connect(c, sa, salen) < 0)
+ return -1;
+
+ return 0;
+}
+
+struct pa_socket_client* pa_socket_client_new_sockaddr(struct pa_mainloop_api *m, const struct sockaddr *sa, size_t salen) {
+ struct pa_socket_client *c;
+ assert(m && sa);
+ c = pa_socket_client_new(m);
+ assert(c);
+
+ if (sockaddr_prepare(c, sa, salen) < 0)
goto fail;
return c;
@@ -222,6 +253,16 @@ void socket_client_free(struct pa_socket_client *c) {
c->mainloop->defer_free(c->defer_event);
if (c->fd >= 0)
close(c->fd);
+
+#ifdef HAVE_LIBASYNCNS
+ if (c->asyncns_query)
+ asyncns_cancel(c->asyncns, c->asyncns_query);
+ if (c->asyncns)
+ asyncns_free(c->asyncns);
+ if (c->asyncns_io_event)
+ c->mainloop->io_free(c->asyncns_io_event);
+#endif
+
pa_xfree(c);
}
@@ -255,6 +296,40 @@ struct pa_socket_client* pa_socket_client_new_ipv6(struct pa_mainloop_api *m, ui
return pa_socket_client_new_sockaddr(m, (struct sockaddr*) &sa, sizeof(sa));
}
+#ifdef HAVE_LIBASYNCNS
+
+static void asyncns_cb(struct pa_mainloop_api*m, struct pa_io_event *e, int fd, enum pa_io_event_flags f, void *userdata) {
+ struct pa_socket_client *c = userdata;
+ struct addrinfo *res = NULL;
+ int ret;
+ assert(m && c && c->asyncns_io_event == e && fd >= 0);
+
+ if (asyncns_wait(c->asyncns, 0) < 0)
+ goto finish;
+
+ if (!asyncns_isdone(c->asyncns, c->asyncns_query))
+ return;
+
+ ret = asyncns_getaddrinfo_done(c->asyncns, c->asyncns_query, &res);
+ c->asyncns_query = NULL;
+
+ if (ret != 0 || !res)
+ goto finish;
+
+ if (res->ai_addr)
+ sockaddr_prepare(c, res->ai_addr, res->ai_addrlen);
+
+ asyncns_freeaddrinfo(res);
+
+finish:
+
+ m->io_free(c->asyncns_io_event);
+ c->asyncns_io_event = NULL;
+ do_call(c);
+}
+
+#endif
+
struct pa_socket_client* pa_socket_client_new_string(struct pa_mainloop_api *m, const char*name, uint16_t default_port) {
struct pa_socket_client *c = NULL;
struct pa_parsed_address a;
@@ -274,34 +349,45 @@ struct pa_socket_client* pa_socket_client_new_string(struct pa_mainloop_api *m,
case PA_PARSED_ADDRESS_TCP4: /* Fallthrough */
case PA_PARSED_ADDRESS_TCP6: /* Fallthrough */
case PA_PARSED_ADDRESS_TCP_AUTO:{
- int ret;
- struct addrinfo hints, *res;
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = a.type == PA_PARSED_ADDRESS_TCP4 ? AF_INET : (a.type == PA_PARSED_ADDRESS_TCP6 ? AF_INET6 : AF_UNSPEC);
-
- ret = getaddrinfo(a.path_or_host, NULL, &hints, &res);
+ struct addrinfo hints;
+ char port[12];
- if (ret < 0 || !res || !res->ai_addr)
- goto finish;
+ snprintf(port, sizeof(port), "%u", (unsigned) a.port);
- if (res->ai_family == AF_INET) {
- if (res->ai_addrlen != sizeof(struct sockaddr_in))
- goto finish;
- assert(res->ai_addr->sa_family == res->ai_family);
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = a.type == PA_PARSED_ADDRESS_TCP4 ? PF_INET : (a.type == PA_PARSED_ADDRESS_TCP6 ? PF_INET6 : PF_UNSPEC);
+ hints.ai_socktype = SOCK_STREAM;
+
+#ifdef HAVE_LIBASYNCNS
+ {
+ asyncns_t *asyncns;
- ((struct sockaddr_in*) res->ai_addr)->sin_port = htons(a.port);
- } else if (res->ai_family == AF_INET6) {
- if (res->ai_addrlen != sizeof(struct sockaddr_in6))
+ if (!(asyncns = asyncns_new(1)))
goto finish;
- assert(res->ai_addr->sa_family == res->ai_family);
+
+ c = pa_socket_client_new(m);
+ c->asyncns = asyncns;
+ c->asyncns_io_event = m->io_new(m, asyncns_fd(c->asyncns), PA_IO_EVENT_INPUT, asyncns_cb, c);
+ c->asyncns_query = asyncns_getaddrinfo(c->asyncns, a.path_or_host, port, &hints);
+ assert(c->asyncns_query);
+ }
+#else
+ {
+ int ret;
+ struct addrinfo *res = NULL;
+
+ ret = getaddrinfo(a.path_or_host, port, &hints, &res);
- ((struct sockaddr_in6*) res->ai_addr)->sin6_port = htons(a.port);
- } else
- goto finish;
+ if (ret < 0 || !res)
+ goto finish;
- c = pa_socket_client_new_sockaddr(m, res->ai_addr, res->ai_addrlen);
- freeaddrinfo(res);
+ if (res->ai_addr)
+ c = pa_socket_client_new_sockaddr(m, res->ai_addr, res->ai_addrlen);
+
+ freeaddrinfo(res);
+ }
+#endif
}
}