From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-developers@cygwin.com
Subject: Re: cygwin 3.3.x: another problem that may be related to pipes
Date: Tue, 16 Nov 2021 01:45:31 +0900 [thread overview]
Message-ID: <20211116014531.0c92dc9f4af9156d62c11fcc@nifty.ne.jp> (raw)
In-Reply-To: <75dcaf48-49d6-a032-9467-145480a3c4a6@cornell.edu>
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>
next prev parent reply other threads:[~2021-11-15 16:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <115203324.649908.1636923059546.ref@mail.yahoo.com>
[not found] ` <115203324.649908.1636923059546@mail.yahoo.com>
[not found] ` <20211115171811.844dce9cce2b4d13262d64f2@nifty.ne.jp>
2021-11-15 13:01 ` Corinna Vinschen
2021-11-15 13:57 ` Ken Brown
2021-11-15 14:36 ` Takashi Yano
2021-11-15 15:11 ` Takashi Yano
2021-11-15 15:27 ` Ken Brown
2021-11-15 15:36 ` Ken Brown
2021-11-15 16:45 ` Takashi Yano [this message]
2021-11-15 16:25 ` Corinna Vinschen
2021-11-15 14:50 ` Takashi Yano
2021-11-15 16:08 ` Corinna Vinschen
2021-11-15 16:37 ` Ken Brown
2021-11-15 16:52 ` Takashi Yano
2021-11-15 18:47 ` Ken Brown
2021-11-15 23:35 ` Takashi Yano
2021-11-15 23:49 ` Ken Brown
2021-11-16 3:28 ` Takashi Yano
2021-11-16 9:28 ` Corinna Vinschen
2021-11-16 9:45 ` Takashi Yano
2021-11-16 10:20 ` Takashi Yano
2021-11-16 14:35 ` Takashi Yano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211116014531.0c92dc9f4af9156d62c11fcc@nifty.ne.jp \
--to=takashi.yano@nifty.ne.jp \
--cc=cygwin-developers@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).