X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qga%2Fchannel-win32.c;h=c86f4388dbc3a1a33727be76e3f566984ec982a5;hb=HEAD;hp=16bf44a376bd5ce096d6e96d7eedd73f09b939d2;hpb=b71706d122838d9656e1a6dae80e22401babdf37;p=mirror_qemu.git diff --git a/qga/channel-win32.c b/qga/channel-win32.c index 16bf44a376..779007e39b 100644 --- a/qga/channel-win32.c +++ b/qga/channel-win32.c @@ -1,12 +1,8 @@ -#include -#include -#include -#include +#include "qemu/osdep.h" #include -#include #include -#include "qga/guest-agent-core.h" -#include "qga/channel.h" +#include "guest-agent-core.h" +#include "channel.h" typedef struct GAChannelReadState { guint thread_id; @@ -80,7 +76,7 @@ static gboolean ga_channel_prepare(GSource *source, gint *timeout_ms) } out: - /* dont block forever, iterate the main loop every once and a while */ + /* don't block forever, iterate the main loop every once in a while */ *timeout_ms = 500; /* if there's data in the read buffer, or another event is pending, * skip polling and issue user cb. @@ -268,8 +264,8 @@ static GIOStatus ga_channel_write(GAChannel *c, const char *buf, size_t size, GIOStatus ga_channel_write_all(GAChannel *c, const char *buf, size_t size) { - GIOStatus status = G_IO_STATUS_NORMAL;; - size_t count; + GIOStatus status = G_IO_STATUS_NORMAL; + size_t count = 0; while (size) { status = ga_channel_write(c, buf, size, &count); @@ -287,16 +283,35 @@ GIOStatus ga_channel_write_all(GAChannel *c, const char *buf, size_t size) static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method, const gchar *path) { - if (!method == GA_CHANNEL_VIRTIO_SERIAL) { + COMMTIMEOUTS comTimeOut = {0}; + gchar newpath[MAXPATHLEN] = {0}; + comTimeOut.ReadIntervalTimeout = 1; + + if (method != GA_CHANNEL_VIRTIO_SERIAL && method != GA_CHANNEL_ISA_SERIAL) { g_critical("unsupported communication method"); return false; } - c->handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, + if (method == GA_CHANNEL_ISA_SERIAL) { + snprintf(newpath, sizeof(newpath), "\\\\.\\%s", path); + } else { + g_strlcpy(newpath, path, sizeof(newpath)); + } + + c->handle = CreateFile(newpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL); if (c->handle == INVALID_HANDLE_VALUE) { - g_critical("error opening path"); + g_autofree gchar *emsg = g_win32_error_message(GetLastError()); + g_critical("error opening path %s: %s", newpath, emsg); + return false; + } + + if (method == GA_CHANNEL_ISA_SERIAL + && !SetCommTimeouts(c->handle, &comTimeOut)) { + g_autofree gchar *emsg = g_win32_error_message(GetLastError()); + g_critical("error setting timeout for com port: %s", emsg); + CloseHandle(c->handle); return false; } @@ -304,9 +319,9 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method, } GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path, - GAChannelCallback cb, gpointer opaque) + int listen_fd, GAChannelCallback cb, gpointer opaque) { - GAChannel *c = g_malloc0(sizeof(GAChannel)); + GAChannel *c = g_new0(GAChannel, 1); SECURITY_ATTRIBUTES sec_attrs; if (!ga_channel_open(c, method, path)) {