public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* select() weirdness
@ 2001-11-14  8:28 chad fowler
  2001-11-15  7:24 ` Corinna Vinschen
  2001-11-21  5:06 ` chad fowler
  0 siblings, 2 replies; 8+ messages in thread
From: chad fowler @ 2001-11-14  8:28 UTC (permalink / raw)
  To: cygwin

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@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@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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: select() weirdness
  2001-11-14  8:28 select() weirdness chad fowler
@ 2001-11-15  7:24 ` Corinna Vinschen
  2001-11-15 12:15   ` chad fowler
  2001-11-23  5:09   ` Corinna Vinschen
  2001-11-21  5:06 ` chad fowler
  1 sibling, 2 replies; 8+ messages in thread
From: Corinna Vinschen @ 2001-11-15  7:24 UTC (permalink / raw)
  To: chad fowler; +Cc: cygwin

On Wed, Nov 21, 2001 at 05:06:53AM -0800, chad fowler wrote:
> 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):
> [...]
> Notice the "EXCEPT" lines.  AFAIK, the behavior on
> Cygwin is incorrect, though I'm *far* from being an
> expert.  

Thanks for the example!  I'm currently looking into the Cygwin
source and I have already found a small bug in the select() code
(though unrelated).  I think I have found the reason for what's
going on in your example but I'm still investigating.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

--
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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: select() weirdness
  2001-11-15  7:24 ` Corinna Vinschen
@ 2001-11-15 12:15   ` chad fowler
  2001-11-15 12:37     ` Christopher Faylor
  2001-11-23 17:39     ` chad fowler
  2001-11-23  5:09   ` Corinna Vinschen
  1 sibling, 2 replies; 8+ messages in thread
From: chad fowler @ 2001-11-15 12:15 UTC (permalink / raw)
  To: Corinna Vinschen

> 
> Thanks for the example!  I'm currently looking into
> the Cygwin
> source and I have already found a small bug in the
> select() code
> (though unrelated).  I think I have found the reason
> for what's
> going on in your example but I'm still
> investigating.
> 

Great news, Corinna.  Thank you.  Let me know if you
need any testing.

Chad

__________________________________________________
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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: select() weirdness
  2001-11-15 12:15   ` chad fowler
@ 2001-11-15 12:37     ` Christopher Faylor
  2001-11-23 19:30       ` Christopher Faylor
  2001-11-23 17:39     ` chad fowler
  1 sibling, 1 reply; 8+ messages in thread
From: Christopher Faylor @ 2001-11-15 12:37 UTC (permalink / raw)
  To: cygwin

On Fri, Nov 23, 2001 at 05:39:31PM -0800, chad fowler wrote:
>>Thanks for the example! I'm currently looking into the Cygwin source
>>and I have already found a small bug in the select() code (though
>>unrelated).  I think I have found the reason for what's going on in
>>your example but I'm still investigating.
>>
>
>Great news, Corinna.  Thank you.  Let me know if you need any testing.

I've just built a snapshot which incorporates Corinna's patches.

http://cygwin.com/snapshots/

FYI,
cgf

--
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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* select() weirdness
  2001-11-14  8:28 select() weirdness chad fowler
  2001-11-15  7:24 ` Corinna Vinschen
@ 2001-11-21  5:06 ` chad fowler
  1 sibling, 0 replies; 8+ messages in thread
From: chad fowler @ 2001-11-21  5:06 UTC (permalink / raw)
  To: cygwin

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@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@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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: select() weirdness
  2001-11-15  7:24 ` Corinna Vinschen
  2001-11-15 12:15   ` chad fowler
@ 2001-11-23  5:09   ` Corinna Vinschen
  1 sibling, 0 replies; 8+ messages in thread
From: Corinna Vinschen @ 2001-11-23  5:09 UTC (permalink / raw)
  To: chad fowler; +Cc: cygwin

On Wed, Nov 21, 2001 at 05:06:53AM -0800, chad fowler wrote:
> 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):
> [...]
> Notice the "EXCEPT" lines.  AFAIK, the behavior on
> Cygwin is incorrect, though I'm *far* from being an
> expert.  

Thanks for the example!  I'm currently looking into the Cygwin
source and I have already found a small bug in the select() code
(though unrelated).  I think I have found the reason for what's
going on in your example but I'm still investigating.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

--
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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: select() weirdness
  2001-11-15 12:15   ` chad fowler
  2001-11-15 12:37     ` Christopher Faylor
@ 2001-11-23 17:39     ` chad fowler
  1 sibling, 0 replies; 8+ messages in thread
From: chad fowler @ 2001-11-23 17:39 UTC (permalink / raw)
  To: Corinna Vinschen

> 
> Thanks for the example!  I'm currently looking into
> the Cygwin
> source and I have already found a small bug in the
> select() code
> (though unrelated).  I think I have found the reason
> for what's
> going on in your example but I'm still
> investigating.
> 

Great news, Corinna.  Thank you.  Let me know if you
need any testing.

Chad

__________________________________________________
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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: select() weirdness
  2001-11-15 12:37     ` Christopher Faylor
@ 2001-11-23 19:30       ` Christopher Faylor
  0 siblings, 0 replies; 8+ messages in thread
From: Christopher Faylor @ 2001-11-23 19:30 UTC (permalink / raw)
  To: cygwin

On Fri, Nov 23, 2001 at 05:39:31PM -0800, chad fowler wrote:
>>Thanks for the example! I'm currently looking into the Cygwin source
>>and I have already found a small bug in the select() code (though
>>unrelated).  I think I have found the reason for what's going on in
>>your example but I'm still investigating.
>>
>
>Great news, Corinna.  Thank you.  Let me know if you need any testing.

I've just built a snapshot which incorporates Corinna's patches.

http://cygwin.com/snapshots/

FYI,
cgf

--
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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-11-24  3:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-14  8:28 select() weirdness chad fowler
2001-11-15  7:24 ` Corinna Vinschen
2001-11-15 12:15   ` chad fowler
2001-11-15 12:37     ` Christopher Faylor
2001-11-23 19:30       ` Christopher Faylor
2001-11-23 17:39     ` chad fowler
2001-11-23  5:09   ` Corinna Vinschen
2001-11-21  5:06 ` chad fowler

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).