[Spice-devel] [RFC v4 15/62] server/main_channel: move ping here from reds.
Alon Levy
alevy at redhat.com
Tue Apr 26 03:54:40 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 121bdaa..066b437 100644
--- a/server/main_channel.c
+++ b/server/main_channel.c
@@ -52,6 +52,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;
@@ -121,6 +123,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 {
@@ -145,16 +151,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;
}
@@ -292,12 +298,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;
}
@@ -306,7 +312,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)
@@ -825,6 +832,39 @@ static int main_channel_handle_migrate_flush_mark_proc(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)
{
@@ -832,6 +872,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 2255f7d..877c567 100644
--- a/server/red_channel.h
+++ b/server/red_channel.h
@@ -238,7 +238,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 5017de1..a9eaf4c 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -109,7 +109,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*/
@@ -228,8 +227,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;
@@ -637,42 +634,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;
@@ -3521,10 +3482,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.4.4
More information about the Spice-devel
mailing list