summaryrefslogtreecommitdiffstats
path: root/qemu/qga/channel-posix.c
diff options
context:
space:
mode:
Diffstat (limited to 'qemu/qga/channel-posix.c')
-rw-r--r--qemu/qga/channel-posix.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/qemu/qga/channel-posix.c b/qemu/qga/channel-posix.c
index 8aad4fee9..63458c663 100644
--- a/qemu/qga/channel-posix.c
+++ b/qemu/qga/channel-posix.c
@@ -1,11 +1,7 @@
+#include "qemu/osdep.h"
#include <glib.h>
#include <termios.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "qemu/sockets.h"
#include "qga/channel.h"
@@ -217,25 +213,24 @@ GIOStatus ga_channel_write_all(GAChannel *c, const gchar *buf, gsize size)
GIOStatus status = G_IO_STATUS_NORMAL;
while (size) {
+ g_debug("sending data, count: %d", (int)size);
status = g_io_channel_write_chars(c->client_channel, buf, size,
&written, &err);
- g_debug("sending data, count: %d", (int)size);
- if (err != NULL) {
+ if (status == G_IO_STATUS_NORMAL) {
+ size -= written;
+ buf += written;
+ } else if (status != G_IO_STATUS_AGAIN) {
g_warning("error writing to channel: %s", err->message);
- return G_IO_STATUS_ERROR;
+ return status;
}
- if (status != G_IO_STATUS_NORMAL) {
- break;
- }
- size -= written;
}
- if (status == G_IO_STATUS_NORMAL) {
+ do {
status = g_io_channel_flush(c->client_channel, &err);
- if (err != NULL) {
- g_warning("error flushing channel: %s", err->message);
- return G_IO_STATUS_ERROR;
- }
+ } while (status == G_IO_STATUS_AGAIN);
+
+ if (status != G_IO_STATUS_NORMAL) {
+ g_warning("error flushing channel: %s", err->message);
}
return status;
@@ -249,7 +244,7 @@ GIOStatus ga_channel_read(GAChannel *c, gchar *buf, gsize size, gsize *count)
GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path,
GAChannelCallback cb, gpointer opaque)
{
- GAChannel *c = g_malloc0(sizeof(GAChannel));
+ GAChannel *c = g_new0(GAChannel, 1);
c->event_cb = cb;
c->user_data = opaque;