public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH] Cygwin: pipe: Handle STATUS_PENDING even for nonblocking mode.
Date: Tue, 16 Nov 2021 17:10:56 +0900	[thread overview]
Message-ID: <20211116171056.a9f0fd202624fc25d764de25@nifty.ne.jp> (raw)
In-Reply-To: <20211116031848.247-1-takashi.yano@nifty.ne.jp>

On Tue, 16 Nov 2021 12:18:47 +0900
Takashi Yano wrote:
> - NtReadFile() and NtWriteFile() seems to return STATUS_PENDING
>   occasionally even in nonblocking mode. This patch adds handling
>   for STATUS_PENDING in nonblocking mode.
> 
> Addresses:
>   https://cygwin.com/pipermail/cygwin/2021-November/249910.html
> ---
>  winsup/cygwin/fhandler_pipe.cc | 10 ++++++----
>  winsup/cygwin/release/3.3.3    |  5 +++++
>  2 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler_pipe.cc b/winsup/cygwin/fhandler_pipe.cc
> index 1ebf4de10..f70ff56fe 100644
> --- a/winsup/cygwin/fhandler_pipe.cc
> +++ b/winsup/cygwin/fhandler_pipe.cc
> @@ -336,9 +336,10 @@ fhandler_pipe::raw_read (void *ptr, size_t& len)
>  	break;
>        status = NtReadFile (get_handle (), evt, NULL, NULL, &io, ptr,
>  			   len1, NULL, NULL);
> -      if (evt && status == STATUS_PENDING)
> +      if (status == STATUS_PENDING)
>  	{
> -	  waitret = cygwait (evt, INFINITE, cw_cancel | cw_sig);
> +	  HANDLE w = evt ?: get_handle ();
> +	  waitret = cygwait (w, INFINITE, cw_cancel | cw_sig);
>  	  /* If io.Status is STATUS_CANCELLED after CancelIo, IO has actually
>  	     been cancelled and io.Information contains the number of bytes
>  	     processed so far.
> @@ -507,10 +508,11 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
>  	    break;
>  	  len1 >>= 1;
>  	}
> -      if (evt && status == STATUS_PENDING)
> +      if (status == STATUS_PENDING)
>  	{
> +	  HANDLE w = evt ?: get_handle ();
>  	  while (WAIT_TIMEOUT ==
> -		 (waitret = cygwait (evt, (DWORD) 0, cw_cancel | cw_sig)))
> +		 (waitret = cygwait (w, (DWORD) 0, cw_cancel | cw_sig)))
>  	    {
>  	      if (reader_closed ())
>  		{
> diff --git a/winsup/cygwin/release/3.3.3 b/winsup/cygwin/release/3.3.3
> index 1eb25e2fc..49c1bcdc3 100644
> --- a/winsup/cygwin/release/3.3.3
> +++ b/winsup/cygwin/release/3.3.3
> @@ -16,3 +16,8 @@ Bug Fixes
>  - Fix long-standing problem that new files don't get created with the
>    FILE_ATTRIBUTE_ARCHIVE DOS attribute set.
>    Addresses: https://cygwin.com/pipermail/cygwin/2021-November/249909.html
> +
> +- Fix issue that pipe read()/write() occationally returns a garnage
> +  length when NtReadFile/NtWriteFile returns STATUS_PENDING in non-
> +  blocking mode.
> +  Addresses: https://cygwin.com/pipermail/cygwin/2021-November/249910.html
> -- 
> 2.33.0

I noticed that this patch sometimes does not work as expected.
cygwaint(get_handle(), ...) may sometimes return WAIT_OBJECT_0
even when the operation is not completed.

I will submit a patch according to Corinna's way. (Use event
even in nonblocking mode.)

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

      reply	other threads:[~2021-11-16  8:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16  3:18 Takashi Yano
2021-11-16  8:10 ` Takashi Yano [this message]

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=20211116171056.a9f0fd202624fc25d764de25@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin-patches@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).