red-channel-client: Simplify red_channel_client_wait_pipe_item_sent

Currently, red_channel_client_wait_pipe_item_sent() inserts a MarkerItem
which will sent after the item we want to wait for: the tail of the
queue is the first item to send, and the function uses
red_channel_client_pipe_add_after_pos(). Then, if the marker has been
successfully sent, the function calls
red_channel_client_wait_outgoing_item to wait for 'item' to be sent.

Instead of doing this, we can add the MarkerItem to the queue so that
it's sent after 'item' (ie, insert it _before_ 'item' in the queue).
This way, when the marker is marked as having been sent, we'll also know
that 'item' has been sent.

This avoids having to call red_channel_client_wait_outgoing_item and
possibly the case where the item was not queued and
red_channel_client_wait_outgoing_item returning TRUE even if the item
was not sent as required.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
Frediano Ziglio 2017-09-11 10:20:48 +01:00
parent 35e9a9d435
commit 8e06a57649

View File

@ -1574,6 +1574,19 @@ void red_channel_client_pipe_add_after_pos(RedChannelClient *rcc,
g_queue_insert_after(&rcc->priv->pipe, pipe_item_pos, item);
}
static void
red_channel_client_pipe_add_before_pos(RedChannelClient *rcc,
RedPipeItem *item,
GList *pipe_item_pos)
{
spice_assert(pipe_item_pos);
if (!prepare_pipe_add(rcc, item)) {
return;
}
g_queue_insert_before(&rcc->priv->pipe, pipe_item_pos, item);
}
void red_channel_client_pipe_add_after(RedChannelClient *rcc,
RedPipeItem *item,
RedPipeItem *pos)
@ -1774,7 +1787,7 @@ bool red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
red_pipe_item_init(&mark_item->base, RED_PIPE_ITEM_TYPE_MARKER);
mark_item->item_in_pipe = true;
red_pipe_item_ref(&mark_item->base);
red_channel_client_pipe_add_after_pos(rcc, &mark_item->base, item_pos);
red_channel_client_pipe_add_before_pos(rcc, &mark_item->base, item_pos);
for (;;) {
red_channel_client_receive(rcc);
@ -1793,10 +1806,8 @@ bool red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
// still on the queue
spice_warning("timeout");
return FALSE;
} else {
return red_channel_client_wait_outgoing_item(rcc,
timeout == -1 ? -1 : end_time - spice_get_monotonic_time_ns());
}
return TRUE;
}
bool red_channel_client_wait_outgoing_item(RedChannelClient *rcc,