1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-02-03 21:52:24 +00:00

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.

[originally from svn r6826]
This commit is contained in:
Simon Tatham 2006-08-28 18:16:49 +00:00
parent 74278dcd64
commit 2aedc83f8d

View File

@ -101,19 +101,26 @@ static DWORD WINAPI handle_input_threadfunc(void *param)
{ {
struct handle_input *ctx = (struct handle_input *) param; struct handle_input *ctx = (struct handle_input *) param;
OVERLAPPED ovl, *povl; OVERLAPPED ovl, *povl;
HANDLE oev;
if (ctx->flags & HANDLE_FLAG_OVERLAPPED) if (ctx->flags & HANDLE_FLAG_OVERLAPPED) {
povl = &ovl; povl = &ovl;
else oev = CreateEvent(NULL, TRUE, FALSE, NULL);
} else {
povl = NULL; povl = NULL;
}
while (1) { while (1) {
if (povl) if (povl) {
memset(povl, 0, sizeof(OVERLAPPED)); memset(povl, 0, sizeof(OVERLAPPED));
povl->hEvent = oev;
}
ctx->readret = ReadFile(ctx->h, ctx->buffer, sizeof(ctx->buffer), ctx->readret = ReadFile(ctx->h, ctx->buffer, sizeof(ctx->buffer),
&ctx->len, povl); &ctx->len, povl);
if (povl && !ctx->readret && GetLastError() == ERROR_IO_PENDING) if (povl && !ctx->readret && GetLastError() == ERROR_IO_PENDING) {
ctx->readret = GetOverlappedResult(ctx->h, povl, &ctx->len, TRUE); WaitForSingleObject(povl->hEvent, INFINITE);
ctx->readret = GetOverlappedResult(ctx->h, povl, &ctx->len, FALSE);
}
if (!ctx->readret) if (!ctx->readret)
ctx->len = 0; ctx->len = 0;
@ -132,6 +139,9 @@ static DWORD WINAPI handle_input_threadfunc(void *param)
break; /* main thread told us to shut down */ break; /* main thread told us to shut down */
} }
if (povl)
CloseHandle(oev);
return 0; return 0;
} }