[Spice-devel] [RFCv5 15/47] server/main_channel: move ping here from reds.

Alon Levy alevy at redhat.com
Sun May 8 06:11:11 PDT 2011


cleanup only. Note that the ping function is half used since the opt parameter
stopped being called with anything but NULL, should be returned at some point,
specifically when we drop the 250kbyte ping on start and do a continuous check
for latency and bandwidth.

See:
 81945d897 - server: add new vd interface QTerm2Interface, Yaniv Kamay
  introducing the usage of ping with a non NULL opt
 3f7ea8e7a - zap qterm interfaces, Gerd Hoffman
  removing it
---
 server/main_channel.c |   62 ++++++++++++++++++++++++++++++++++++++++++------
 server/red_channel.h  |    2 +
 server/reds.c         |   43 ----------------------------------
 3 files changed, 56 insertions(+), 51 deletions(-)

diff --git a/server/main_channel.c b/server/main_channel.c
index 3f6149c..1d0b6c3 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -55,6 +55,8 @@
 #define NET_TEST_WARMUP_BYTES 0
 #define NET_TEST_BYTES (1024 * 250)
 
+#define PING_INTERVAL (1000 * 10)
+
 static uint8_t zero_page[ZERO_BUF_SIZE] = {0};
 
 typedef struct RedsOutItem RedsOutItem;
@@ -124,6 +126,10 @@ struct MainChannelClient {
     int net_test_stage;
     uint64_t latency;
     uint64_t bitrate_per_sec;
+#ifdef RED_STATISTICS
+    SpiceTimer *ping_timer;
+    int ping_interval;
+#endif
 };
 
 struct MainChannel {
@@ -148,16 +154,16 @@ static void main_disconnect(MainChannel *main_chan)
     red_channel_destroy(&main_chan->base);
 }
 
-static int main_channel_client_push_ping(RedChannelClient *rcc, int size);
+static int main_channel_client_push_ping(MainChannelClient *rcc, int size);
 
 void main_channel_start_net_test(MainChannelClient *mcc)
 {
     if (!mcc) {
         return;
     }
-    if (main_channel_client_push_ping(&mcc->base, NET_TEST_WARMUP_BYTES)
-        && main_channel_client_push_ping(&mcc->base, 0)
-        && main_channel_client_push_ping(&mcc->base, NET_TEST_BYTES)) {
+    if (main_channel_client_push_ping(mcc, NET_TEST_WARMUP_BYTES)
+        && main_channel_client_push_ping(mcc, 0)
+        && main_channel_client_push_ping(mcc, NET_TEST_BYTES)) {
         mcc->net_test_id = mcc->ping_id - 2;
         mcc->net_test_stage = NET_TEST_STAGE_WARMUP;
     }
@@ -284,12 +290,12 @@ static void main_channel_marshall_channels(SpiceMarshaller *m)
     free(channels_info);
 }
 
-int main_channel_client_push_ping(RedChannelClient *rcc, int size)
+int main_channel_client_push_ping(MainChannelClient *mcc, int size)
 {
     PingPipeItem *item;
 
-    item = main_ping_item_new(rcc, size);
-    red_channel_client_pipe_add_push(rcc, &item->base);
+    item = main_ping_item_new(&mcc->base, size);
+    red_channel_client_pipe_add_push(&mcc->base, &item->base);
     return TRUE;
 }
 
@@ -298,7 +304,8 @@ int main_channel_push_ping(MainChannel *main_chan, int size)
     if (main_chan->base.rcc == NULL) {
         return FALSE;
     }
-    return main_channel_client_push_ping(main_chan->base.rcc, size);
+    return main_channel_client_push_ping(
+        SPICE_CONTAINEROF(main_chan->base.rcc, MainChannelClient, base), size);
 }
 
 static void main_channel_marshall_ping(SpiceMarshaller *m, int size, int ping_id)
@@ -820,6 +827,39 @@ static int main_channel_handle_migrate_flush_mark(RedChannelClient *rcc)
     return TRUE;
 }
 
+#ifdef RED_STATISTICS
+static void do_ping_client(MainChannelClient *mcc,
+    const char *opt, int has_interval, int interval)
+{
+    red_printf("");
+    if (!opt) {
+        main_channel_client_push_ping(mcc, 0);
+    } else if (!strcmp(opt, "on")) {
+        if (has_interval && interval > 0) {
+            mcc->ping_interval = interval * 1000;
+        }
+        core->timer_start(mcc->ping_timer, mcc->ping_interval);
+    } else if (!strcmp(opt, "off")) {
+        core->timer_cancel(mcc->ping_timer);
+    } else {
+        return;
+    }
+}
+
+static void ping_timer_cb(void *opaque)
+{
+    MainChannelClient *mcc = opaque;
+
+    if (!red_channel_client_is_connected(&mcc->base)) {
+        red_printf("not connected to peer, ping off");
+        core->timer_cancel(mcc->ping_timer);
+        return;
+    }
+    do_ping_client(mcc, NULL, 0, 0);
+    core->timer_start(mcc->ping_timer, mcc->ping_interval);
+}
+#endif /* RED_STATISTICS */
+
 MainChannelClient *main_channel_client_create(MainChannel *main_chan,
     RedClient *client, RedsStream *stream)
 {
@@ -827,6 +867,12 @@ MainChannelClient *main_channel_client_create(MainChannel *main_chan,
         sizeof(MainChannelClient), &main_chan->base, client, stream);
 
     mcc->bitrate_per_sec = ~0;
+#ifdef RED_STATISTICS
+    if (!(mcc->ping_timer = core->timer_add(ping_timer_cb, NULL))) {
+        red_error("ping timer create failed");
+    }
+    mcc->ping_interval = PING_INTERVAL;
+#endif
     return mcc;
 }
 
diff --git a/server/red_channel.h b/server/red_channel.h
index 60dcf69..09a613a 100644
--- a/server/red_channel.h
+++ b/server/red_channel.h
@@ -237,7 +237,9 @@ RedChannel *red_channel_create_parser(int size,
                                channel_handle_migrate_data_get_serial_proc handle_migrate_data_get_serial);
 RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedClient *client,
                                             RedsStream *stream);
+
 int red_channel_is_connected(RedChannel *channel);
+int red_channel_client_is_connected(RedChannelClient *rcc);
 
 void red_channel_client_destroy(RedChannelClient *rcc);
 void red_channel_destroy(RedChannel *channel);
diff --git a/server/reds.c b/server/reds.c
index 5b1dfd3..8a2b532 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -110,7 +110,6 @@ int agent_copypaste = TRUE;
 static void openssl_init();
 
 #define MIGRATE_TIMEOUT (1000 * 10) /* 10sec */
-#define PING_INTERVAL (1000 * 10)
 #define MM_TIMER_GRANULARITY_MS (1000 / 30)
 #define MM_TIME_DELTA 400 /*ms*/
 #define VDI_PORT_WRITE_RETRY_TIMEOUT 100 /*ms*/
@@ -229,8 +228,6 @@ typedef struct RedsState {
     SpiceStat *stat;
     pthread_mutex_t stat_lock;
     RedsStatValue roundtrip_stat;
-    SpiceTimer *ping_timer;
-    int ping_interval;
 #endif
     int peer_minor_version;
 } RedsState;
@@ -638,42 +635,6 @@ static void reds_mig_disconnect()
     }
 }
 
-#ifdef RED_STATISTICS
-
-static void do_ping_client(const char *opt, int has_interval, int interval)
-{
-    if (!reds_main_channel_connected()) {
-        red_printf("not connected to peer");
-        return;
-    }
-
-    if (!opt) {
-        main_channel_push_ping(reds->main_channel, 0);
-    } else if (!strcmp(opt, "on")) {
-        if (has_interval && interval > 0) {
-            reds->ping_interval = interval * 1000;
-        }
-        core->timer_start(reds->ping_timer, reds->ping_interval);
-    } else if (!strcmp(opt, "off")) {
-        core->timer_cancel(reds->ping_timer);
-    } else {
-        return;
-    }
-}
-
-static void ping_timer_cb()
-{
-    if (!reds_main_channel_connected()) {
-        red_printf("not connected to peer, ping off");
-        core->timer_cancel(reds->ping_timer);
-        return;
-    }
-    do_ping_client(NULL, 0, 0);
-    core->timer_start(reds->ping_timer, reds->ping_interval);
-}
-
-#endif
-
 int reds_get_mouse_mode(void)
 {
     return reds->mouse_mode;
@@ -3544,10 +3505,6 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
     if (pthread_mutex_init(&reds->stat_lock, NULL)) {
         red_error("mutex init failed");
     }
-    if (!(reds->ping_timer = core->timer_add(ping_timer_cb, NULL))) {
-        red_error("ping timer create failed");
-    }
-    reds->ping_interval = PING_INTERVAL;
 #endif
 
     if (!(reds->mm_timer = core->timer_add(mm_timer_proc, NULL))) {
-- 
1.7.5.1



More information about the Spice-devel mailing list