public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Ken Brown <kbrown@cornell.edu>
To: cygwin@cygwin.com
Subject: Re: FIFO issues
Date: Fri, 23 Sep 2022 11:36:56 -0400	[thread overview]
Message-ID: <c8e491a7-784a-248e-abd1-d3eb1204d784@cornell.edu> (raw)
In-Reply-To: <Yyn2SEWN3R80ItR8@GIOVE>

[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]

On 9/20/2022 1:20 PM, Enrico Forestieri wrote:
> On Tue, Sep 20, 2022 at 06:18:54PM -0700, Ken Brown wrote:
>>
>> On 9/20/2022 2:54 AM, Enrico Forestieri wrote:
>>>
>>>   I compared the behavior of read() and select() on 3 different platforms.
>>>   My conclusion is that, actually, read() behaves the same on all of them,
>>>   whereas cygwin differs in the way select() works.
>>
>> Then I'm even more confused than I was before. Are you saying that
>> there are situations in which read() reports EOF but select() does not
>> report read ready? Could you post the code you used for testing?
> 
> I simply introduced a timeout for select() such that it returns on any
> platform. On cygwin, when using "O_RDONLY | O_NONBLOCK" for the input
> pipe, select() always returns 1, while on all other platforms it returns 0
> unless a client actually opens it for writing.
> 
> As the "if (FD_ISSET(infd, &readfds))" block would not be entered on the
> other platforms, I replaced it with "if (TRUE)" so that the read() is
> always executed. In this conditions, the output is the same on all
> platforms, meaning that the issue is the select() and not the read() call.
> 
> This is the attached fifocomm-test.c file.

I've just sent a patch to the cygwin-patches list that makes Cygwin behave the 
same as Linux.  Thanks for reporting this problem.

Ken

P.S. I'm attaching a simplified test case that I used for testing the patch.

[-- Attachment #2: select_eof_fifo.c --]
[-- Type: text/plain, Size: 1298 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/select.h>
#include <errno.h>
#include <sys/stat.h>

#define FIFO_PATH "/tmp/myfifo"

int
main ()
{
  int fd, tmpfd, nsel;
  fd_set readfds;
  struct timeval wait_tm = { 0l, 200000l }; /* 200 millisecs */

  if (unlink (FIFO_PATH) < 0  && errno != ENOENT)
    {
      perror ("unlink");
      exit (1);
    }

  if (mkfifo (FIFO_PATH, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
	      | S_IWOTH) < 0)
    {
      perror ("mkfifo");
      exit (1);
    }

  printf ("Opening a FIFO for reading with O_NONBLOCK\n");
  if ((fd = open (FIFO_PATH, O_RDONLY | O_NONBLOCK)) < 0)
    {
      perror ("open");
      exit (1);
    }

  printf ("Testing for read ready...\n");
  FD_ZERO (&readfds);
  FD_SET (fd, &readfds);
  nsel = select (fd + 1, &readfds, NULL, NULL, &wait_tm);
  printf ("  select returned %d\n", nsel);

  printf ("Opening and closing FIFO for writing...\n");
  if ((tmpfd = open (FIFO_PATH, O_WRONLY)) < 0)
    {
      perror ("open");
      exit (1);
    }
  if (close (tmpfd) < 0)
    {
      perror ("close");
      exit (1);
    }

  FD_ZERO (&readfds);
  FD_SET (fd, &readfds);
  nsel = select (fd + 1, &readfds, NULL, NULL, &wait_tm);
  printf ("  now select returned %d\n", nsel);
}

      reply	other threads:[~2022-09-23 15:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-18 21:45 Enrico Forestieri
2022-09-19 19:15 ` Ken Brown
2022-09-19 19:50   ` Norton Allen
2022-09-19 19:53     ` Norton Allen
2022-09-19 21:25       ` Ken Brown
2022-09-19 21:28         ` Norton Allen
2022-09-19 22:05         ` Enrico Forestieri
2022-09-19 23:54           ` Ken Brown
2022-09-20  3:51             ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-09-20  6:54             ` Enrico Forestieri
2022-09-20 13:18               ` Ken Brown
2022-09-20 17:20                 ` Enrico Forestieri
2022-09-23 15:36                   ` Ken Brown [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=c8e491a7-784a-248e-abd1-d3eb1204d784@cornell.edu \
    --to=kbrown@cornell.edu \
    --cc=cygwin@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).