]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/socket-client.c
ladspa/remap: make sure we process all requested rewinds unconditionally
[pulseaudio] / src / pulsecore / socket-client.c
index f8f2ff2f0a69463ad1e8d72668c04d1b49963c7f..2453515785f86caac832182110b451d28b779e6e 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
     This file is part of PulseAudio.
 
 #include <asyncns.h>
 #endif
 
+#include <pulse/rtclock.h>
 #include <pulse/timeval.h>
 #include <pulse/xmalloc.h>
 
 #include <pulsecore/winsock.h>
 #include <pulsecore/core-error.h>
 #include <pulsecore/socket-util.h>
+#include <pulsecore/core-rtclock.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/socket-util.h>
 #include <pulsecore/log.h>
@@ -189,7 +189,7 @@ static void connect_defer_cb(pa_mainloop_api *m, pa_defer_event *e, void *userda
     do_call(c);
 }
 
-static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
+static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
     pa_socket_client *c = userdata;
 
     pa_assert(m);
@@ -280,12 +280,16 @@ static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size
 
     pa_make_fd_cloexec(c->fd);
 
+#ifdef HAVE_IPV6
     if (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)
+#else
+    if (sa->sa_family == AF_INET)
+#endif
         pa_make_tcp_socket_low_delay(c->fd);
     else
         pa_make_socket_low_delay(c->fd);
 
-    if (do_connect(c, sa, salen) < 0)
+    if (do_connect(c, sa, (socklen_t) salen) < 0)
         return -1;
 
     return 0;
@@ -355,6 +359,7 @@ void pa_socket_client_set_callback(pa_socket_client *c, pa_socket_client_cb_t on
     c->userdata = userdata;
 }
 
+#ifdef HAVE_IPV6
 pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[16], uint16_t port) {
     struct sockaddr_in6 sa;
 
@@ -369,10 +374,11 @@ pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[
 
     return pa_socket_client_new_sockaddr(m, (struct sockaddr*) &sa, sizeof(sa));
 }
+#endif
 
 #ifdef HAVE_LIBASYNCNS
 
-static void asyncns_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
+static void asyncns_cb(pa_mainloop_api*m, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) {
     pa_socket_client *c = userdata;
     struct addrinfo *res = NULL;
     int ret;
@@ -416,12 +422,11 @@ fail:
 
 #endif
 
-static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeval *tv, void *userdata) {
+static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) {
     pa_socket_client *c = userdata;
 
     pa_assert(m);
     pa_assert(e);
-    pa_assert(tv);
     pa_assert(c);
 
     if (c->fd >= 0) {
@@ -433,17 +438,16 @@ static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeva
     do_call(c);
 }
 
-static void start_timeout(pa_socket_client *c) {
+static void start_timeout(pa_socket_client *c, pa_bool_t use_rtclock) {
     struct timeval tv;
+
     pa_assert(c);
     pa_assert(!c->timeout_event);
 
-    pa_gettimeofday(&tv);
-    pa_timeval_add(&tv, CONNECT_TIMEOUT * 1000000);
-    c->timeout_event = c->mainloop->time_new(c->mainloop, &tv, timeout_cb, c);
+    c->timeout_event = c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, pa_rtclock_now() + CONNECT_TIMEOUT * PA_USEC_PER_SEC, use_rtclock), timeout_cb, c);
 }
 
-pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*name, uint16_t default_port) {
+pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, pa_bool_t use_rtclock, const char*name, uint16_t default_port) {
     pa_socket_client *c = NULL;
     pa_parsed_address a;
 
@@ -459,7 +463,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
     switch (a.type) {
         case PA_PARSED_ADDRESS_UNIX:
             if ((c = pa_socket_client_new_unix(m, a.path_or_host)))
-                start_timeout(c);
+                start_timeout(c, use_rtclock);
             break;
 
         case PA_PARSED_ADDRESS_TCP4:  /* Fallthrough */
@@ -472,7 +476,15 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
             pa_snprintf(port, sizeof(port), "%u", (unsigned) a.port);
 
             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);
+            if (a.type == PA_PARSED_ADDRESS_TCP4)
+                hints.ai_family = PF_INET;
+#ifdef HAVE_IPV6
+            else if (a.type == PA_PARSED_ADDRESS_TCP6)
+                hints.ai_family = PF_INET6;
+#endif
+            else
+                hints.ai_family = PF_UNSPEC;
+
             hints.ai_socktype = SOCK_STREAM;
 
 #if defined(HAVE_LIBASYNCNS)
@@ -487,7 +499,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
                 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);
                 pa_assert(c->asyncns_query);
-                start_timeout(c);
+                start_timeout(c, use_rtclock);
             }
 #elif defined(HAVE_GETADDRINFO)
             {
@@ -501,7 +513,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
 
                 if (res->ai_addr) {
                     if ((c = pa_socket_client_new_sockaddr(m, res->ai_addr, res->ai_addrlen)))
-                        start_timeout(c);
+                        start_timeout(c, use_rtclock);
                 }
 
                 freeaddrinfo(res);
@@ -511,11 +523,13 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
                 struct hostent *host = NULL;
                 struct sockaddr_in s;
 
+#ifdef HAVE_IPV6
                 /* FIXME: PF_INET6 support */
                 if (hints.ai_family == PF_INET6) {
                     pa_log_error("IPv6 is not supported on Windows");
                     goto finish;
                 }
+#endif
 
                 host = gethostbyname(a.path_or_host);
                 if (!host) {
@@ -532,7 +546,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
                 s.sin_port = htons(a.port);
 
                 if ((c = pa_socket_client_new_sockaddr(m, (struct sockaddr*)&s, sizeof(s))))
-                    start_timeout(c);
+                    start_timeout(c, use_rtclock);
             }
 #endif /* HAVE_LIBASYNCNS */
         }