[Spice-commits] 3 commits - server/red_channel.c server/reds.c server/reds_stream.c server/reds_stream.h server/spice-server.h

Marc-André Lureau elmarco at kemper.freedesktop.org
Thu Jan 15 09:30:10 PST 2015


 server/red_channel.c  |    2 +-
 server/reds.c         |   42 +++++++++++++++++++++++++++++++++++-------
 server/reds_stream.c  |   10 ++++++++++
 server/reds_stream.h  |    1 +
 server/spice-server.h |    1 +
 5 files changed, 48 insertions(+), 8 deletions(-)

New commits:
commit 72cc0cff710f8be3e721fed82ab2ce519f03ccb4
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Mon Jan 12 17:24:44 2015 +0100

    Do not perform network tests on UNIX socket
    
    By default, stream latency is 0 and bandwidth is infinite. On UNIX
    socket do not perform unnecessary testing and keep those values.

diff --git a/server/red_channel.c b/server/red_channel.c
index b06efbf..a968309 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -928,7 +928,7 @@ RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedCl
     red_channel_ref(channel);
     pthread_mutex_unlock(&client->lock);
 
-    if (monitor_latency) {
+    if (monitor_latency && reds_stream_get_family(stream) != AF_UNIX) {
         rcc->latency_monitor.timer = channel->core->timer_add(
             red_channel_client_ping_timer, rcc);
         if (!client->during_target_migrate) {
diff --git a/server/reds.c b/server/reds.c
index efc6b2b..a351b88 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1648,7 +1648,9 @@ static void reds_handle_main_link(RedLinkInfo *link)
     } else {
         reds_mig_target_client_add(client);
     }
-    main_channel_client_start_net_test(mcc, !mig_target);
+
+    if (reds_stream_get_family(stream) != AF_UNIX)
+        main_channel_client_start_net_test(mcc, !mig_target);
 }
 
 #define RED_MOUSE_STATE_TO_LOCAL(state)     \
commit 3dcd287fcbe1ec8a6c19364886a93ef222d472bf
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Sun Nov 2 15:52:47 2014 +0100

    reds-stream: add reds_stream_get_family() function

diff --git a/server/reds_stream.c b/server/reds_stream.c
index 4b61e31..1a595b2 100644
--- a/server/reds_stream.c
+++ b/server/reds_stream.c
@@ -226,6 +226,16 @@ ssize_t reds_stream_write(RedsStream *s, const void *buf, size_t nbyte)
     return ret;
 }
 
+int reds_stream_get_family(RedsStream *s)
+{
+    spice_return_val_if_fail(s != NULL, -1);
+
+    if (s->socket == -1)
+        return -1;
+
+    return s->priv->info->laddr_ext.ss_family;
+}
+
 ssize_t reds_stream_writev(RedsStream *s, const struct iovec *iov, int iovcnt)
 {
     int i;
diff --git a/server/reds_stream.h b/server/reds_stream.h
index 6cbbbbb..b5889e3 100644
--- a/server/reds_stream.h
+++ b/server/reds_stream.h
@@ -72,6 +72,7 @@ bool reds_stream_is_ssl(RedsStream *stream);
 RedsStreamSslStatus reds_stream_ssl_accept(RedsStream *stream);
 int reds_stream_enable_ssl(RedsStream *stream, SSL_CTX *ctx);
 void reds_stream_set_info_flag(RedsStream *stream, unsigned int flag);
+int reds_stream_get_family(RedsStream *stream);
 
 typedef enum {
     REDS_SASL_ERROR_OK,
commit 5365caeaae537f564d160936e60f71b2dc964ad1
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Thu Jan 8 16:05:57 2015 +0100

    reds: add Unix socket support
    
    Learn to listen on a Unix address. In this case, the connection is plain
    only (non-tls).

diff --git a/server/reds.c b/server/reds.c
index e34433b..efc6b2b 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -44,6 +44,7 @@
 #endif
 
 #include <glib.h>
+#include <sys/un.h>
 
 #include <spice/protocol.h>
 #include <spice/vd_agent.h>
@@ -2351,7 +2352,27 @@ static int reds_init_socket(const char *addr, int portnr, int family)
     static const int on=1, off=0;
     struct addrinfo ai,*res,*e;
     char port[33];
-    int slisten,rc;
+    int slisten, rc, len;
+
+    if (family == AF_UNIX) {
+        struct sockaddr_un local = { 0, };
+
+        if ((slisten = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+            perror("socket");
+            return -1;
+        }
+
+        local.sun_family = AF_UNIX;
+        strncpy(local.sun_path, addr, sizeof(local.sun_path) -1);
+        unlink(local.sun_path);
+        len = SUN_LEN(&local);
+        if (bind(slisten, (struct sockaddr *)&local, len) == -1) {
+            perror("bind");
+            return -1;
+        }
+
+        goto listen;
+    }
 
     memset(&ai,0, sizeof(ai));
     ai.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
@@ -2391,6 +2412,7 @@ static int reds_init_socket(const char *addr, int portnr, int family)
             } else {
                 spice_info("cannot resolve address spice-server is bound to");
             }
+            freeaddrinfo(res);
             goto listen;
         }
         close(slisten);
@@ -2401,7 +2423,6 @@ static int reds_init_socket(const char *addr, int portnr, int family)
     return -1;
 
 listen:
-    freeaddrinfo(res);
     if (listen(slisten,1) != 0) {
         spice_warning("listen: %s", strerror(errno));
         close(slisten);
@@ -2439,7 +2460,7 @@ void reds_set_client_mm_time_latency(RedClient *client, uint32_t latency)
 
 static int reds_init_net(void)
 {
-    if (spice_port != -1) {
+    if (spice_port != -1 || spice_family == AF_UNIX) {
         reds->listen_socket = reds_init_socket(spice_addr, spice_port, spice_family);
         if (-1 == reds->listen_socket) {
             return -1;
@@ -3360,12 +3381,17 @@ SPICE_GNUC_VISIBLE int spice_server_set_port(SpiceServer *s, int port)
 SPICE_GNUC_VISIBLE void spice_server_set_addr(SpiceServer *s, const char *addr, int flags)
 {
     spice_assert(reds == s);
+
     g_strlcpy(spice_addr, addr, sizeof(spice_addr));
-    if (flags & SPICE_ADDR_FLAG_IPV4_ONLY) {
+
+    if (flags == SPICE_ADDR_FLAG_IPV4_ONLY) {
         spice_family = PF_INET;
-    }
-    if (flags & SPICE_ADDR_FLAG_IPV6_ONLY) {
+    } else if (flags == SPICE_ADDR_FLAG_IPV6_ONLY) {
         spice_family = PF_INET6;
+    } else if (flags == SPICE_ADDR_FLAG_UNIX_ONLY) {
+        spice_family = AF_UNIX;
+    } else if (flags != 0) {
+        spice_warning("unknown address flag: 0x%X", flags);
     }
 }
 
diff --git a/server/spice-server.h b/server/spice-server.h
index c97b221..bca0da6 100644
--- a/server/spice-server.h
+++ b/server/spice-server.h
@@ -42,6 +42,7 @@ void spice_server_destroy(SpiceServer *s);
 
 #define SPICE_ADDR_FLAG_IPV4_ONLY (1 << 0)
 #define SPICE_ADDR_FLAG_IPV6_ONLY (1 << 1)
+#define SPICE_ADDR_FLAG_UNIX_ONLY (1 << 2)
 
 int spice_server_set_compat_version(SpiceServer *s,
                                     spice_compat_version_t version);


More information about the Spice-commits mailing list