From: simon Date: Tue, 27 Mar 2007 18:49:59 +0000 (+0000) Subject: Windows apparently sends ERROR_BROKEN_PIPE when a pipe we're reading X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/425f5af23fa1fb9a2711d4c615c47221e8078de4 Windows apparently sends ERROR_BROKEN_PIPE when a pipe we're reading from is closed normally from the writing end. This is ludicrous; if that situation isn't a natural EOF, _nothing_ is. So if we get that particular error, we pretend it's EOF. git-svn-id: svn://svn.tartarus.org/sgt/putty@7415 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/windows/winhandl.c b/windows/winhandl.c index f515ee57..9f120dc0 100644 --- a/windows/winhandl.c +++ b/windows/winhandl.c @@ -134,13 +134,25 @@ static DWORD WINAPI handle_input_threadfunc(void *param) } ctx->readret = ReadFile(ctx->h, ctx->buffer, readlen, &ctx->len, povl); - if (povl && !ctx->readret && GetLastError() == ERROR_IO_PENDING) { + if (!ctx->readret) + error = GetLastError(); + if (povl && !ctx->readret && error == ERROR_IO_PENDING) { WaitForSingleObject(povl->hEvent, INFINITE); ctx->readret = GetOverlappedResult(ctx->h, povl, &ctx->len, FALSE); } - if (!ctx->readret) + if (!ctx->readret) { + /* + * Windows apparently sends ERROR_BROKEN_PIPE when a + * pipe we're reading from is closed normally from the + * writing end. This is ludicrous; if that situation + * isn't a natural EOF, _nothing_ is. So if we get that + * particular error, we pretend it's EOF. + */ + if (error == ERROR_BROKEN_PIPE) + ctx->readret = 1; ctx->len = 0; + } if (ctx->readret && ctx->len == 0 && (ctx->flags & HANDLE_FLAG_IGNOREEOF))