[Spice-devel] [PATCH spice-server 10/18] sound: Implements config_socket RedChannel callback

Frediano Ziglio fziglio at redhat.com
Wed Nov 23 18:07:24 UTC 2016


This code is the same inside __new_channel but will set the
RedsStream from RedChannel.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/sound.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/server/sound.c b/server/sound.c
index 3d3c0b8..ac11106 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -998,6 +998,55 @@ error1:
     return NULL;
 }
 
+static int snd_channel_config_socket(RedChannelClient *rcc)
+{
+    int delay_val;
+    int flags;
+#ifdef SO_PRIORITY
+    int priority;
+#endif
+    int tos;
+    RedsStream *stream = red_channel_client_get_stream(rcc);
+    RedClient *red_client = red_channel_client_get_client(rcc);
+    MainChannelClient *mcc = red_client_get_main(red_client);
+
+    if ((flags = fcntl(stream->socket, F_GETFL)) == -1) {
+        spice_printerr("accept failed, %s", strerror(errno));
+        return FALSE;
+    }
+
+#ifdef SO_PRIORITY
+    priority = 6;
+    if (setsockopt(stream->socket, SOL_SOCKET, SO_PRIORITY, (void*)&priority,
+                   sizeof(priority)) == -1) {
+        if (errno != ENOTSUP) {
+            spice_printerr("setsockopt failed, %s", strerror(errno));
+        }
+    }
+#endif
+
+    tos = IPTOS_LOWDELAY;
+    if (setsockopt(stream->socket, IPPROTO_IP, IP_TOS, (void*)&tos, sizeof(tos)) == -1) {
+        if (errno != ENOTSUP) {
+            spice_printerr("setsockopt failed, %s", strerror(errno));
+        }
+    }
+
+    delay_val = main_channel_client_is_low_bandwidth(mcc) ? 0 : 1;
+    if (setsockopt(stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, sizeof(delay_val)) == -1) {
+        if (errno != ENOTSUP) {
+            spice_printerr("setsockopt failed, %s", strerror(errno));
+        }
+    }
+
+    if (fcntl(stream->socket, F_SETFL, flags | O_NONBLOCK) == -1) {
+        spice_printerr("accept failed, %s", strerror(errno));
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 static void snd_disconnect_channel_client(RedChannelClient *rcc)
 {
     SndChannel *channel;
@@ -1542,6 +1591,8 @@ snd_channel_init(SndChannel *self)
 static void
 snd_channel_class_init(SndChannelClass *klass)
 {
+    RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
+    channel_class->config_socket = snd_channel_config_socket;
 }
 
 static void
-- 
2.7.4



More information about the Spice-devel mailing list