[PATCH v2] Cygwin: pipe: Switch pipe mode to blocking mode by defaut

Takashi Yano takashi.yano@nifty.ne.jp
Fri Sep 6 10:34:11 GMT 2024


On Fri,  6 Sep 2024 18:01:08 +0900
Takashi Yano wrote:
> diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
> index bc02c3f9d..9ddb9898c 100644
> --- a/winsup/cygwin/select.cc
> +++ b/winsup/cygwin/select.cc
> @@ -642,7 +642,7 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, int flags)
>          Consequentially, the only reliable information is available on the
>          read side, so fetch info from the read side via the pipe-specific
>          query handle.  Use fpli.WriteQuotaAvailable as storage for the actual
> -        interesting value, which is the InboundQuote on the write side,
> +        interesting value, which is the IutboundQuota on the write side,
>          decremented by the number of bytes of data in that buffer. */
>        /* Note: Do not use NtQueryInformationFile() for query_hdl because
>  	 NtQueryInformationFile() seems to interfere with reading pipes
> @@ -655,19 +655,17 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, int flags)
>  	 handling this fact. */
>        if (fh->get_device () == FH_PIPEW && fpli.WriteQuotaAvailable == 0)
>  	{
> -	  HANDLE query_hdl = ((fhandler_pipe *) fh)->get_query_handle ();
> -	  if (!query_hdl)
> -	    query_hdl = ((fhandler_pipe *) fh)->temporary_query_hdl ();
> -	  if (!query_hdl) /* We cannot know actual write pipe space. */
> -	    return (flags & PDA_SELECT) ? PIPE_BUF : 1;
> -	  DWORD nbytes_in_pipe;
> -	  BOOL res =
> -	    PeekNamedPipe (query_hdl, NULL, 0, NULL, &nbytes_in_pipe, NULL);
> -	  if (!((fhandler_pipe *) fh)->get_query_handle ())
> -	    CloseHandle (query_hdl); /* Close temporary query_hdl */
> -	  if (!res) /* We cannot know actual write pipe space. */
> -	    return (flags & PDA_SELECT) ? PIPE_BUF : 1;
> -	  fpli.WriteQuotaAvailable = fpli.InboundQuota - nbytes_in_pipe;
> +	  /* NtSetInformationFile() in set_pipe_non_blocking(true)
> +	     seems to fail for unknown reasons with STATUS_PIPE_BUSY
> +	     if no reader is reading the pipe. In this case, the pipe
> +	     is really full if WriteQuotaAvailable is zero. Otherwise,
> +	     the pipe is empty. */
> +	  if (!((fhandler_pipe *) fh)->set_pipe_non_blocking (true))
> +	    return 0; /* Full */
> +	  /* Restore pipe mode to blocking mode */
> +	  ((fhandler_pipe *) fh)->set_pipe_non_blocking (false);
> +	  /* Empty */
> +	  fpli.WriteQuotaAvailable = fpli.IutboundQuota;
                                          ^^^ In
Of cource...

>  	}
>        if (fpli.WriteQuotaAvailable > 0)
>  	{

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


More information about the Cygwin-patches mailing list