[Spice-devel] [spice-server v4 5/6] reds-stream: Introduce reds_stream_get_no_delay() helper

Christophe Fergeau cfergeau at redhat.com
Fri Mar 31 09:21:35 UTC 2017


This new function removes one place outside of RedsStream which needs to
access RedsStream::socket

Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
Acked-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/net-utils.c          | 20 ++++++++++++++++++++
 server/net-utils.h          |  1 +
 server/red-channel-client.c |  7 ++-----
 server/reds-stream.c        |  5 +++++
 server/reds-stream.h        |  1 +
 5 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/server/net-utils.c b/server/net-utils.c
index ae7fa91..209c298 100644
--- a/server/net-utils.c
+++ b/server/net-utils.c
@@ -114,3 +114,23 @@ bool red_socket_set_non_blocking(int fd, bool non_blocking)
 
     return true;
 }
+
+/**
+ * red_socket_get_no_delay:
+ * @fd: a socket file descriptor
+ *
+ * Returns: The current value of TCP_NODELAY for @fd, -1 if an error occurred
+ */
+int red_socket_get_no_delay(int fd)
+{
+    int delay_val;
+    socklen_t opt_size = sizeof(delay_val);
+
+    if (getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &delay_val,
+                   &opt_size) == -1) {
+            spice_warning("getsockopt failed, %s", strerror(errno));
+            return -1;
+    }
+
+    return delay_val;
+}
diff --git a/server/net-utils.h b/server/net-utils.h
index d56b479..e0f918d 100644
--- a/server/net-utils.h
+++ b/server/net-utils.h
@@ -22,6 +22,7 @@
 
 bool red_socket_set_keepalive(int fd, bool enable, int timeout);
 bool red_socket_set_no_delay(int fd, bool no_delay);
+int red_socket_get_no_delay(int fd);
 bool red_socket_set_non_blocking(int fd, bool non_blocking);
 
 #endif
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 9fca8c1..ffebc6a 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -556,7 +556,6 @@ static void red_channel_client_send_ping(RedChannelClient *rcc)
 
     if (!rcc->priv->latency_monitor.warmup_was_sent) { // latency test start
         int delay_val;
-        socklen_t opt_size = sizeof(delay_val);
 
         rcc->priv->latency_monitor.warmup_was_sent = TRUE;
         /*
@@ -565,10 +564,8 @@ static void red_channel_client_send_ping(RedChannelClient *rcc)
          * roundtrip measurement is less accurate (bigger).
          */
         rcc->priv->latency_monitor.tcp_nodelay = 1;
-        if (getsockopt(rcc->priv->stream->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val,
-                       &opt_size) == -1) {
-            spice_warning("getsockopt failed, %s", strerror(errno));
-        }  else {
+        delay_val = reds_stream_get_no_delay(rcc->priv->stream);
+        if (delay_val != -1) {
             rcc->priv->latency_monitor.tcp_nodelay = delay_val;
             if (!delay_val) {
                 reds_stream_set_no_delay(rcc->priv->stream, TRUE);
diff --git a/server/reds-stream.c b/server/reds-stream.c
index dbe6962..fdd0086 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -273,6 +273,11 @@ bool reds_stream_set_no_delay(RedsStream *stream, bool no_delay)
     return red_socket_set_no_delay(stream->socket, no_delay);
 }
 
+int reds_stream_get_no_delay(RedsStream *stream)
+{
+    return red_socket_get_no_delay(stream->socket);
+}
+
 int reds_stream_send_msgfd(RedsStream *stream, int fd)
 {
     struct msghdr msgh = { 0, };
diff --git a/server/reds-stream.h b/server/reds-stream.h
index 37ba87c..b4fc8b2 100644
--- a/server/reds-stream.h
+++ b/server/reds-stream.h
@@ -73,6 +73,7 @@ int reds_stream_enable_ssl(RedsStream *stream, SSL_CTX *ctx);
 int reds_stream_get_family(const RedsStream *stream);
 bool reds_stream_is_plain_unix(const RedsStream *stream);
 bool reds_stream_set_no_delay(RedsStream *stream, bool no_delay);
+int reds_stream_get_no_delay(RedsStream *stream);
 int reds_stream_send_msgfd(RedsStream *stream, int fd);
 
 typedef enum {
-- 
2.9.3



More information about the Spice-devel mailing list