delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/11/21/08:15:22

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <20011121130653.60456.qmail@web13906.mail.yahoo.com>
Date: Wed, 21 Nov 2001 05:06:53 -0800 (PST)
From: chad fowler <chadfowler AT yahoo DOT com>
Subject: select() weirdness
To: cygwin AT cygwin DOT com
MIME-Version: 1.0

I'm a little confused about the behavior of select(). 
It seems to behave differently in Cygwin than on other
systems.  This is specifically regarding the exception
fd_set when piping program output to another program. 
Here's an example (which might have a problem or two
but should demonstrate sufficiently):

<code_sample>
#include <sys/types.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>

#define TIMEOUT     1          

int openFile(char *);

int
main(int argc, char **argv)
{ 
	fd_set readfds, writefds, exceptfds;
	int n, fd, so, se, f;
	struct timeval tv;

	fd = openFile("select.c");

        FD_ZERO(&readfds);
        FD_ZERO(&writefds);
        FD_ZERO(&exceptfds);

	FD_SET(fd, &readfds);
       	FD_SET(fd, &exceptfds);
	FD_SET(1, &writefds);
	FD_SET(2, &writefds);
	FD_SET(1, &exceptfds);
	FD_SET(2, &exceptfds);

        tv.tv_sec = TIMEOUT;
        tv.tv_usec = 0;

        n = select(3, &readfds, &writefds, &exceptfds,
&tv);

        switch (n) {
        case -1:            
            perror("select");
            exit(1);
        case 0:            
            printf("\nTimeout expired.  Type
something!\n");
            break;
        default:            
		f = FD_ISSET(fd, &readfds); 
		so = FD_ISSET(1, &readfds), 
		se = FD_ISSET(2, &readfds);
		printf("READ - file: %d, stdout: %d, stderr: %d\n",
f, so, se);
		f = FD_ISSET(fd, &writefds), 
		so = FD_ISSET(1, &writefds), 
		se = FD_ISSET(2, &writefds);
		printf("WRITE - file: %d, stdout: %d, stderr: %d\n",
f, so, se);
		f = FD_ISSET(fd, &exceptfds), 
		so = FD_ISSET(1, &exceptfds), 
		se = FD_ISSET(2, &exceptfds);
		printf("EXCEPT - file: %d, stdout: %d, stderr:
%d\n", f, so, se);
            break;
        }
    }

int openFile(char *file)
{	 int fd;
	fd = -1;
        if ((fd = open(file, O_RDONLY)) < 0) {
            perror(file);
            exit(1);
        }
	return fd;
}
</code_sample>

<output_on_cygwin>
$ ./a.exe
READ - file: 0, stdout: 0, stderr: 0
WRITE - file: 0, stdout: 2, stderr: 4
EXCEPT - file: 0, stdout: 0, stderr: 0

$ ./a.exe |cat
READ - file: 0, stdout: 0, stderr: 0
WRITE - file: 0, stdout: 2, stderr: 4
EXCEPT - file: 0, stdout: 2, stderr: 0
</output_on_cygwin>


<output_on_linux>
cef AT yawmp:~$ ./a.out
READ - file: 0, stdout: 0, stderr: 0
WRITE - file: 0, stdout: 1, stderr: 1
EXCEPT - file: 0, stdout: 0, stderr: 0

cef AT yawmp:~$ ./a.out |cat
READ - file: 0, stdout: 0, stderr: 0
WRITE - file: 0, stdout: 1, stderr: 1
EXCEPT - file: 0, stdout: 0, stderr: 0
</output_on_linux>

Notice the "EXCEPT" lines.  AFAIK, the behavior on
Cygwin is incorrect, though I'm *far* from being an
expert.  

Any help would be greatly appreciated.

Thanks,
Chad Fowler

__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019