Merge branch 'am/mingw-poll-fix'

MinGW's poll() emulation has been improved.

* am/mingw-poll-fix:
  mingw: workaround for hangs when sending STDIN
This commit is contained in:
Junio C Hamano 2020-03-09 11:21:20 -07:00
commit 1ac37deba2
1 changed files with 3 additions and 28 deletions

View File

@ -139,22 +139,10 @@ win32_compute_revents (HANDLE h, int *p_sought)
INPUT_RECORD *irbuffer; INPUT_RECORD *irbuffer;
DWORD avail, nbuffer; DWORD avail, nbuffer;
BOOL bRet; BOOL bRet;
IO_STATUS_BLOCK iosb;
FILE_PIPE_LOCAL_INFORMATION fpli;
static PNtQueryInformationFile NtQueryInformationFile;
static BOOL once_only;
switch (GetFileType (h)) switch (GetFileType (h))
{ {
case FILE_TYPE_PIPE: case FILE_TYPE_PIPE:
if (!once_only)
{
NtQueryInformationFile = (PNtQueryInformationFile)(void (*)(void))
GetProcAddress (GetModuleHandleW (L"ntdll.dll"),
"NtQueryInformationFile");
once_only = TRUE;
}
happened = 0; happened = 0;
if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0) if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0)
{ {
@ -166,22 +154,9 @@ win32_compute_revents (HANDLE h, int *p_sought)
else else
{ {
/* It was the write-end of the pipe. Check if it is writable. /* It was the write-end of the pipe. Unfortunately there is no
If NtQueryInformationFile fails, optimistically assume the pipe is reliable way of knowing if it can be written without blocking.
writable. This could happen on Win9x, where NtQueryInformationFile Just say that it's all good. */
is not available, or if we inherit a pipe that doesn't permit
FILE_READ_ATTRIBUTES access on the write end (I think this should
not happen since WinXP SP2; WINE seems fine too). Otherwise,
ensure that enough space is available for atomic writes. */
memset (&iosb, 0, sizeof (iosb));
memset (&fpli, 0, sizeof (fpli));
if (!NtQueryInformationFile
|| NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli),
FilePipeLocalInformation)
|| fpli.WriteQuotaAvailable >= PIPE_BUF
|| (fpli.OutboundQuota < PIPE_BUF &&
fpli.WriteQuotaAvailable == fpli.OutboundQuota))
happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND);
} }
return happened; return happened;