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.y...@nifty.ne.jp>

Reply via email to