[Spice-commits] 2 commits - server/main-channel-client.c
Frediano Ziglio
fziglio at kemper.freedesktop.org
Thu Sep 8 09:04:40 UTC 2016
server/main-channel-client.c | 112 +++++++++++++++++++++----------------------
1 file changed, 57 insertions(+), 55 deletions(-)
New commits:
commit f9c4f6da0e94261292609447acf5517c7698bdaa
Author: Victor Toso <victortoso at redhat.com>
Date: Wed Sep 7 15:15:24 2016 +0200
mcc: early return and lower indentation
main_channel_client_start_net_test() checks MainChannelClient already
which is the single reason why main_channel_client_push_ping() could
fail. Reorganizing this code a little bit.
Acked-by: Frediano Ziglio <fziglio at redhat.com
diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index e94aeee..50fa599 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -150,16 +150,18 @@ void main_channel_client_start_net_test(MainChannelClient *mcc, int test_rate)
if (!mcc || mcc->priv->net_test_id) {
return;
}
- if (test_rate) {
- 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->priv->net_test_id = mcc->priv->ping_id - 2;
- mcc->priv->net_test_stage = NET_TEST_STAGE_WARMUP;
- }
- } else {
+
+ if (!test_rate) {
red_channel_client_start_connectivity_monitoring(&mcc->base, CLIENT_CONNECTIVITY_TIMEOUT);
+ return;
}
+
+ 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->priv->net_test_id = mcc->priv->ping_id - 2;
+ mcc->priv->net_test_stage = NET_TEST_STAGE_WARMUP;
}
static RedPipeItem *red_ping_item_new(int size)
commit b7353a0c61a68c5aa270bf92e46b51b6a57d49bd
Author: Victor Toso <victortoso at redhat.com>
Date: Wed Sep 7 15:35:17 2016 +0200
mcc: early return and lower indentation
Acked-by: Frediano Ziglio <fziglio at redhat.com
diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 75aae9f..e94aeee 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -384,59 +384,59 @@ void main_channel_client_handle_pong(MainChannelClient *mcc, SpiceMsgPing *ping,
roundtrip = g_get_monotonic_time() - ping->timestamp;
- if (ping->id == mcc->priv->net_test_id) {
- switch (mcc->priv->net_test_stage) {
- case NET_TEST_STAGE_WARMUP:
- mcc->priv->net_test_id++;
- mcc->priv->net_test_stage = NET_TEST_STAGE_LATENCY;
- mcc->priv->latency = roundtrip;
- break;
- case NET_TEST_STAGE_LATENCY:
- mcc->priv->net_test_id++;
- mcc->priv->net_test_stage = NET_TEST_STAGE_RATE;
- mcc->priv->latency = MIN(mcc->priv->latency, roundtrip);
- break;
- case NET_TEST_STAGE_RATE:
- mcc->priv->net_test_id = 0;
- if (roundtrip <= mcc->priv->latency) {
- // probably high load on client or server result with incorrect values
- spice_printerr("net test: invalid values, latency %" PRIu64
- " roundtrip %" PRIu64 ". assuming high"
- "bandwidth", mcc->priv->latency, roundtrip);
- mcc->priv->latency = 0;
- mcc->priv->net_test_stage = NET_TEST_STAGE_INVALID;
- red_channel_client_start_connectivity_monitoring(&mcc->base,
- CLIENT_CONNECTIVITY_TIMEOUT);
- break;
- }
- mcc->priv->bitrate_per_sec = (uint64_t)(NET_TEST_BYTES * 8) * 1000000
- / (roundtrip - mcc->priv->latency);
- mcc->priv->net_test_stage = NET_TEST_STAGE_COMPLETE;
- spice_printerr("net test: latency %f ms, bitrate %"PRIu64" bps (%f Mbps)%s",
- (double)mcc->priv->latency / 1000,
- mcc->priv->bitrate_per_sec,
- (double)mcc->priv->bitrate_per_sec / 1024 / 1024,
- main_channel_client_is_low_bandwidth(mcc) ? " LOW BANDWIDTH" : "");
- red_channel_client_start_connectivity_monitoring(&mcc->base,
- CLIENT_CONNECTIVITY_TIMEOUT);
- break;
- default:
- spice_printerr("invalid net test stage, ping id %d test id %d stage %d",
- ping->id,
- mcc->priv->net_test_id,
- mcc->priv->net_test_stage);
- mcc->priv->net_test_stage = NET_TEST_STAGE_INVALID;
- }
- return;
- } else {
+ if (ping->id != mcc->priv->net_test_id) {
/*
* channel client monitors the connectivity using ping-pong messages
*/
red_channel_client_handle_message(rcc, size, SPICE_MSGC_PONG, ping);
- }
#ifdef RED_STATISTICS
- stat_update_value(red_channel_client_get_channel(rcc)->reds, roundtrip);
+ stat_update_value(red_channel_client_get_channel(rcc)->reds, roundtrip);
#endif
+ return;
+ }
+
+ switch (mcc->priv->net_test_stage) {
+ case NET_TEST_STAGE_WARMUP:
+ mcc->priv->net_test_id++;
+ mcc->priv->net_test_stage = NET_TEST_STAGE_LATENCY;
+ mcc->priv->latency = roundtrip;
+ break;
+ case NET_TEST_STAGE_LATENCY:
+ mcc->priv->net_test_id++;
+ mcc->priv->net_test_stage = NET_TEST_STAGE_RATE;
+ mcc->priv->latency = MIN(mcc->priv->latency, roundtrip);
+ break;
+ case NET_TEST_STAGE_RATE:
+ mcc->priv->net_test_id = 0;
+ if (roundtrip <= mcc->priv->latency) {
+ // probably high load on client or server result with incorrect values
+ spice_printerr("net test: invalid values, latency %" PRIu64
+ " roundtrip %" PRIu64 ". assuming high"
+ "bandwidth", mcc->priv->latency, roundtrip);
+ mcc->priv->latency = 0;
+ mcc->priv->net_test_stage = NET_TEST_STAGE_INVALID;
+ red_channel_client_start_connectivity_monitoring(&mcc->base,
+ CLIENT_CONNECTIVITY_TIMEOUT);
+ break;
+ }
+ mcc->priv->bitrate_per_sec = (uint64_t)(NET_TEST_BYTES * 8) * 1000000
+ / (roundtrip - mcc->priv->latency);
+ mcc->priv->net_test_stage = NET_TEST_STAGE_COMPLETE;
+ spice_printerr("net test: latency %f ms, bitrate %"PRIu64" bps (%f Mbps)%s",
+ (double)mcc->priv->latency / 1000,
+ mcc->priv->bitrate_per_sec,
+ (double)mcc->priv->bitrate_per_sec / 1024 / 1024,
+ main_channel_client_is_low_bandwidth(mcc) ? " LOW BANDWIDTH" : "");
+ red_channel_client_start_connectivity_monitoring(&mcc->base,
+ CLIENT_CONNECTIVITY_TIMEOUT);
+ break;
+ default:
+ spice_printerr("invalid net test stage, ping id %d test id %d stage %d",
+ ping->id,
+ mcc->priv->net_test_id,
+ mcc->priv->net_test_stage);
+ mcc->priv->net_test_stage = NET_TEST_STAGE_INVALID;
+ }
}
void main_channel_client_handle_migrate_end(MainChannelClient *mcc)
More information about the Spice-commits
mailing list