cygwin 3.3.x: another problem that may be related to pipes
Takashi Yano
takashi.yano@nifty.ne.jp
Mon Nov 15 16:45:31 GMT 2021
On Mon, 15 Nov 2021 10:36:19 -0500
Ken Brown wrote:
> On 11/15/2021 10:27 AM, Ken Brown wrote:
> > On 11/15/2021 10:11 AM, Takashi Yano wrote:
> >> I might be wrong. Your code certainly waits for something happening.
> >> I am not sure why it works...
> >
> > FWIW, I got the idea for this from the following code in
> > fhandler_socket_unix::listen_pipe:
> >
> > io.Status = STATUS_PENDING;
> > if (!is_nonblocking () && !(evt = create_event ()))
> > return -1;
> > status = NtFsControlFile (get_handle (), evt, NULL, NULL, &io,
> > FSCTL_PIPE_LISTEN, NULL, 0, NULL, 0);
> > if (status == STATUS_PENDING)
> > {
> > waitret = cygwait (evt ?: get_handle (), cw_infinite,
> > cw_cancel | cw_sig_eintr);
> > if (waitret == WAIT_OBJECT_0)
> > status = io.Status;
> > }
>
> And here's Corinna's answer when I asked her to explain it:
>
> https://cygwin.com/pipermail/cygwin-developers/2021-April/012093.html
I found
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntwritefile
says about NtWriteFile():
If the caller opened the file with the DesiredAccess SYNCHRONIZE
flag set, the caller can wait for this routine to set the given
FileHandle to the signaled state.
Also,
https://docs.microsoft.com/en-us/windows/win32/devnotes/ntreadfile
says about NtReadFile():
If the caller opened the file with the SYNCHRONIZE flag set in
DesiredAccess, the calling thread can synchronize to the completion
of the read operation by waiting on the file handle, FileHandle.
The handle is signaled each time that an I/O operation that was
issued on the handle completes. However, the caller must not wait
on a handle that was opened for synchronous file access
(FILE_SYNCHRONOUS_IO_NONALERT or FILE_SYNCHRONOUS_IO_ALERT).
In this case, NtReadFile waits on behalf of the caller and does
not return until the read operation is complete. The caller can
safely wait on the file handle only if all three of the following
conditions are met:
* The handle was opened for asynchronous access (that is, neither
FILE_SYNCHRONOUS_IO_XXX flag was specified).
* The handle is being used for only one I/O operation at a time.
* NtReadFile returned STATUS_PENDING.
Therefore, in this case, waiting for the pipe handle might be
the correct manner.
--
Takashi Yano <takashi.yano@nifty.ne.jp>
More information about the Cygwin-developers
mailing list