[Spice-devel] [spice-gtk v3 6/6] spice_channel_flush_wire: make it similar to _read_wire()
Victor Toso
victortoso at redhat.com
Tue Feb 28 11:21:51 UTC 2017
From: Victor Toso <me at victortoso.com>
* By making spice_channel_flush_wire() similar to
spice_channel_read_wire() where we keep the possible context switch
of g_coroutine_socket_wait() in the end of loop and dealing with the
return of the _flush_wire_nonblocking() case by case.
Related: https://bugs.freedesktop.org/show_bug.cgi?id=96598
Signed-off-by: Victor Toso <victortoso at redhat.com>
---
src/spice-channel.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/spice-channel.c b/src/spice-channel.c
index 4a105b0..e26c1aa 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -832,26 +832,25 @@ static void spice_channel_flush_wire(SpiceChannel *channel,
while (offset < datalen) {
gssize ret;
- if (c->has_error) return;
+ if (c->has_error)
+ return;
ret = spice_channel_flush_wire_nonblocking(channel, ptr+offset, datalen-offset, &cond);
- if (ret == -1) {
- if (cond != 0) {
- // TODO: should use g_pollable_input/output_stream_create_source() in 2.28 ?
- g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
- continue;
- } else {
- CHANNEL_DEBUG(channel, "Closing the channel: spice_channel_flush %d", errno);
- c->has_error = TRUE;
- return;
- }
- }
- if (ret == 0) {
+ if (ret > 0) {
+ offset += ret;
+ continue;
+ } else if (ret == 0) {
CHANNEL_DEBUG(channel, "Closing the connection: spice_channel_flush");
c->has_error = TRUE;
return;
+ } else if (cond == 0) {
+ CHANNEL_DEBUG(channel, "Closing the channel: spice_channel_flush %d", errno);
+ c->has_error = TRUE;
+ return;
}
- offset += ret;
+
+ // TODO: should use g_pollable_input/output_stream_create_source() in 2.28 ?
+ g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
}
}
--
2.9.3
More information about the Spice-devel
mailing list