char-win: rename hcom->file

hcom is the name of the file handle, regardless of the actual chardev
driver (serial, file, console etc..). Rename it to be more explicit.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
This commit is contained in:
Marc-André Lureau 2017-01-04 21:37:01 +01:00
parent 221e659c3f
commit ef0f272f38
3 changed files with 24 additions and 24 deletions

View File

@ -58,27 +58,27 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
} }
openname = g_strdup_printf("\\\\.\\pipe\\%s", filename); openname = g_strdup_printf("\\\\.\\pipe\\%s", filename);
s->hcom = CreateNamedPipe(openname, s->file = CreateNamedPipe(openname,
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |
PIPE_WAIT, PIPE_WAIT,
MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL); MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL);
g_free(openname); g_free(openname);
if (s->hcom == INVALID_HANDLE_VALUE) { if (s->file == INVALID_HANDLE_VALUE) {
error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError()); error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());
s->hcom = NULL; s->file = NULL;
goto fail; goto fail;
} }
ZeroMemory(&ov, sizeof(ov)); ZeroMemory(&ov, sizeof(ov));
ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
ret = ConnectNamedPipe(s->hcom, &ov); ret = ConnectNamedPipe(s->file, &ov);
if (ret) { if (ret) {
error_setg(errp, "Failed ConnectNamedPipe"); error_setg(errp, "Failed ConnectNamedPipe");
goto fail; goto fail;
} }
ret = GetOverlappedResult(s->hcom, &ov, &size, TRUE); ret = GetOverlappedResult(s->file, &ov, &size, TRUE);
if (!ret) { if (!ret) {
error_setg(errp, "Failed GetOverlappedResult"); error_setg(errp, "Failed GetOverlappedResult");
if (ov.hEvent) { if (ov.hEvent) {

View File

@ -43,11 +43,11 @@ static void win_chr_read(Chardev *chr, DWORD len)
ZeroMemory(&s->orecv, sizeof(s->orecv)); ZeroMemory(&s->orecv, sizeof(s->orecv));
s->orecv.hEvent = s->hrecv; s->orecv.hEvent = s->hrecv;
ret = ReadFile(s->hcom, buf, len, &size, &s->orecv); ret = ReadFile(s->file, buf, len, &size, &s->orecv);
if (!ret) { if (!ret) {
err = GetLastError(); err = GetLastError();
if (err == ERROR_IO_PENDING) { if (err == ERROR_IO_PENDING) {
ret = GetOverlappedResult(s->hcom, &s->orecv, &size, TRUE); ret = GetOverlappedResult(s->file, &s->orecv, &size, TRUE);
} }
} }
@ -63,7 +63,7 @@ static int win_chr_serial_poll(void *opaque)
COMSTAT status; COMSTAT status;
DWORD comerr; DWORD comerr;
ClearCommError(s->hcom, &comerr, &status); ClearCommError(s->file, &comerr, &status);
if (status.cbInQue > 0) { if (status.cbInQue > 0) {
win_chr_read(chr, status.cbInQue); win_chr_read(chr, status.cbInQue);
return 1; return 1;
@ -91,15 +91,15 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
goto fail; goto fail;
} }
s->hcom = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, s->file = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
if (s->hcom == INVALID_HANDLE_VALUE) { if (s->file == INVALID_HANDLE_VALUE) {
error_setg(errp, "Failed CreateFile (%lu)", GetLastError()); error_setg(errp, "Failed CreateFile (%lu)", GetLastError());
s->hcom = NULL; s->file = NULL;
goto fail; goto fail;
} }
if (!SetupComm(s->hcom, NRECVBUF, NSENDBUF)) { if (!SetupComm(s->file, NRECVBUF, NSENDBUF)) {
error_setg(errp, "Failed SetupComm"); error_setg(errp, "Failed SetupComm");
goto fail; goto fail;
} }
@ -110,23 +110,23 @@ int win_chr_serial_init(Chardev *chr, const char *filename, Error **errp)
comcfg.dcb.DCBlength = sizeof(DCB); comcfg.dcb.DCBlength = sizeof(DCB);
CommConfigDialog(filename, NULL, &comcfg); CommConfigDialog(filename, NULL, &comcfg);
if (!SetCommState(s->hcom, &comcfg.dcb)) { if (!SetCommState(s->file, &comcfg.dcb)) {
error_setg(errp, "Failed SetCommState"); error_setg(errp, "Failed SetCommState");
goto fail; goto fail;
} }
if (!SetCommMask(s->hcom, EV_ERR)) { if (!SetCommMask(s->file, EV_ERR)) {
error_setg(errp, "Failed SetCommMask"); error_setg(errp, "Failed SetCommMask");
goto fail; goto fail;
} }
cto.ReadIntervalTimeout = MAXDWORD; cto.ReadIntervalTimeout = MAXDWORD;
if (!SetCommTimeouts(s->hcom, &cto)) { if (!SetCommTimeouts(s->file, &cto)) {
error_setg(errp, "Failed SetCommTimeouts"); error_setg(errp, "Failed SetCommTimeouts");
goto fail; goto fail;
} }
if (!ClearCommError(s->hcom, &err, &comstat)) { if (!ClearCommError(s->file, &err, &comstat)) {
error_setg(errp, "Failed ClearCommError"); error_setg(errp, "Failed ClearCommError");
goto fail; goto fail;
} }
@ -143,7 +143,7 @@ int win_chr_pipe_poll(void *opaque)
WinChardev *s = WIN_CHARDEV(opaque); WinChardev *s = WIN_CHARDEV(opaque);
DWORD size; DWORD size;
PeekNamedPipe(s->hcom, NULL, 0, NULL, &size, NULL); PeekNamedPipe(s->file, NULL, 0, NULL, &size, NULL);
if (size > 0) { if (size > 0) {
win_chr_read(chr, size); win_chr_read(chr, size);
return 1; return 1;
@ -162,14 +162,14 @@ static int win_chr_write(Chardev *chr, const uint8_t *buf, int len1)
s->osend.hEvent = s->hsend; s->osend.hEvent = s->hsend;
while (len > 0) { while (len > 0) {
if (s->hsend) { if (s->hsend) {
ret = WriteFile(s->hcom, buf, len, &size, &s->osend); ret = WriteFile(s->file, buf, len, &size, &s->osend);
} else { } else {
ret = WriteFile(s->hcom, buf, len, &size, NULL); ret = WriteFile(s->file, buf, len, &size, NULL);
} }
if (!ret) { if (!ret) {
err = GetLastError(); err = GetLastError();
if (err == ERROR_IO_PENDING) { if (err == ERROR_IO_PENDING) {
ret = GetOverlappedResult(s->hcom, &s->osend, &size, TRUE); ret = GetOverlappedResult(s->file, &s->osend, &size, TRUE);
if (ret) { if (ret) {
buf += size; buf += size;
len -= size; len -= size;
@ -202,8 +202,8 @@ static void char_win_finalize(Object *obj)
if (s->hrecv) { if (s->hrecv) {
CloseHandle(s->hrecv); CloseHandle(s->hrecv);
} }
if (s->hcom) { if (s->file) {
CloseHandle(s->hcom); CloseHandle(s->file);
} }
if (s->fpipe) { if (s->fpipe) {
qemu_del_polling_cb(win_chr_pipe_poll, chr); qemu_del_polling_cb(win_chr_pipe_poll, chr);
@ -219,7 +219,7 @@ void qemu_chr_open_win_file(Chardev *chr, HANDLE fd_out)
WinChardev *s = WIN_CHARDEV(chr); WinChardev *s = WIN_CHARDEV(chr);
s->skip_free = true; s->skip_free = true;
s->hcom = fd_out; s->file = fd_out;
} }
static void char_win_class_init(ObjectClass *oc, void *data) static void char_win_class_init(ObjectClass *oc, void *data)

View File

@ -29,7 +29,7 @@
typedef struct { typedef struct {
Chardev parent; Chardev parent;
HANDLE hcom, hrecv, hsend; HANDLE file, hrecv, hsend;
OVERLAPPED orecv; OVERLAPPED orecv;
BOOL fpipe; BOOL fpipe;