From 758a137739edff67a485ef9d534764cef8aab807 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 28 Aug 2006 18:16:49 +0000 Subject: [PATCH] Apparently it helps for an OVERLAPPED structure to contain a valid event handle. This seems to have fixed _some_, but not all, of the curious data loss issues in the Windows serial backend. git-svn-id: svn://svn.tartarus.org/sgt/putty@6826 cda61777-01e9-0310-a592-d414129be87e --- windows/winhandl.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/windows/winhandl.c b/windows/winhandl.c index fc641812..7a3cce35 100644 --- a/windows/winhandl.c +++ b/windows/winhandl.c @@ -101,19 +101,26 @@ static DWORD WINAPI handle_input_threadfunc(void *param) { struct handle_input *ctx = (struct handle_input *) param; OVERLAPPED ovl, *povl; + HANDLE oev; - if (ctx->flags & HANDLE_FLAG_OVERLAPPED) + if (ctx->flags & HANDLE_FLAG_OVERLAPPED) { povl = &ovl; - else + oev = CreateEvent(NULL, TRUE, FALSE, NULL); + } else { povl = NULL; + } while (1) { - if (povl) + if (povl) { memset(povl, 0, sizeof(OVERLAPPED)); + povl->hEvent = oev; + } ctx->readret = ReadFile(ctx->h, ctx->buffer, sizeof(ctx->buffer), &ctx->len, povl); - if (povl && !ctx->readret && GetLastError() == ERROR_IO_PENDING) - ctx->readret = GetOverlappedResult(ctx->h, povl, &ctx->len, TRUE); + if (povl && !ctx->readret && GetLastError() == ERROR_IO_PENDING) { + WaitForSingleObject(povl->hEvent, INFINITE); + ctx->readret = GetOverlappedResult(ctx->h, povl, &ctx->len, FALSE); + } if (!ctx->readret) ctx->len = 0; @@ -132,6 +139,9 @@ static DWORD WINAPI handle_input_threadfunc(void *param) break; /* main thread told us to shut down */ } + if (povl) + CloseHandle(oev); + return 0; } -- 2.11.0