diff options
author | Victor Toso <victortoso@redhat.com> | 2015-09-29 15:48:28 +0200 |
---|---|---|
committer | Victor Toso <victortoso@redhat.com> | 2015-10-09 08:17:39 +0200 |
commit | 1077cda903fad579cf8b5e73160c7c4c12eac6e0 (patch) | |
tree | fa252980da12c3248e7dd34870e2b3af47ae8d24 | |
parent | 5d0649b8f00654e93cb7f8bc4756de567eb89771 (diff) |
main_channel: handle PING messagesclient-side-bandwidth-monitoring
We set SPICE_MAIN_CAP_PING capability as we now handle client's
SPICE_MSGC_MAIN_PING by replying with SPICE_MSG_MAIN_PONG using the same
payload SpiceMsgPing.
-rw-r--r-- | server/main_channel.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/server/main_channel.c b/server/main_channel.c index 0ecc9df..dd61efc 100644 --- a/server/main_channel.c +++ b/server/main_channel.c @@ -62,6 +62,7 @@ static uint8_t zero_page[ZERO_BUF_SIZE] = {0}; enum { PIPE_ITEM_TYPE_MAIN_CHANNELS_LIST = PIPE_ITEM_TYPE_CHANNEL_BASE, PIPE_ITEM_TYPE_MAIN_PING, + PIPE_ITEM_TYPE_MAIN_PONG, PIPE_ITEM_TYPE_MAIN_MOUSE_MODE, PIPE_ITEM_TYPE_MAIN_AGENT_DISCONNECTED, PIPE_ITEM_TYPE_MAIN_AGENT_TOKEN, @@ -88,6 +89,11 @@ typedef struct PingPipeItem { int size; } PingPipeItem; +typedef struct PongPipeItem { + PipeItem base; + SpiceMsgPing ping; +} PongPipeItem; + typedef struct MouseModePipeItem { PipeItem base; int current_mode; @@ -241,6 +247,15 @@ static PipeItem *main_ping_item_new(MainChannelClient *mcc, int size) return &item->base; } +static PipeItem *main_pong_item_new(MainChannelClient *mcc, SpiceMsgPing *ping, int size) +{ + PongPipeItem *item = spice_malloc(sizeof(PongPipeItem)); + + red_channel_pipe_item_init(mcc->base.channel, &item->base, PIPE_ITEM_TYPE_MAIN_PONG); + memcpy(&item->ping, ping, size); + return &item->base; +} + static PipeItem *main_agent_tokens_item_new(RedChannelClient *rcc, uint32_t num_tokens) { TokensPipeItem *item = spice_malloc(sizeof(TokensPipeItem)); @@ -744,6 +759,11 @@ static void main_channel_send_item(RedChannelClient *rcc, PipeItem *base) main_channel_marshall_ping(rcc, m, SPICE_CONTAINEROF(base, PingPipeItem, base)); break; + case PIPE_ITEM_TYPE_MAIN_PONG: + red_channel_client_init_send_data(rcc, SPICE_MSG_MAIN_PONG, base); + spice_marshall_msg_main_pong(m, + &SPICE_CONTAINEROF(base, PongPipeItem, base)->ping); + break; case PIPE_ITEM_TYPE_MAIN_MOUSE_MODE: { MouseModePipeItem *item = @@ -943,6 +963,11 @@ static int main_channel_handle_parsed(RedChannelClient *rcc, uint32_t size, uint case SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST: reds_on_main_mouse_mode_request(message, size); break; + case SPICE_MSGC_MAIN_PING: { + PipeItem *item = main_pong_item_new(mcc, message, size); + red_channel_client_pipe_add_push(rcc, item); + break; + } case SPICE_MSGC_PONG: { SpiceMsgPing *ping = (SpiceMsgPing *)message; uint64_t roundtrip; @@ -1210,6 +1235,7 @@ MainChannel* main_channel_init(void) spice_assert(channel); red_channel_set_cap(channel, SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE); red_channel_set_cap(channel, SPICE_MAIN_CAP_SEAMLESS_MIGRATE); + red_channel_set_cap(channel, SPICE_MAIN_CAP_PING); client_cbs.migrate = main_channel_client_migrate; red_channel_register_client_cbs(channel, &client_cbs); |