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

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


On Fri,  6 Sep 2024 18:01:08 +0900
Takashi Yano wrote:
> @@ -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