Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs
Date: Fri, 18 Jun 2004 09:33:16 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Lev Pliner <pliner AT sky DOT ru>
cc: cygwin AT cygwin DOT com
Subject: Re: Question about select function
In-Reply-To: <002801c45518$808914e0$b90d72d9@lsp>
Message-ID: <Pine.GSO.4.58.0406180912280.3356@slinky.cs.nyu.edu>
References: <002801c45518$808914e0$b90d72d9 AT lsp>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Scanned-By: MIMEDefang 2.39

On Fri, 18 Jun 2004, Lev Pliner wrote:

> Dear forum members!
>
> I'm writing a multithreaded rpc program. The following is a part of my
> program that causes a error:
>
>   fd_set readfds;
>   int size = getdtablesize ( );
>
>   while ( 1 )
>   {
>     readfds = svc_fdset;

Where is svc_fdset coming from?  Are you quoting the whole example?

AFAIK, you should first "FD_ZERO(&readfds)", and then "FD_SET(some_fd,
&readfds)", otherwise you're trying to select() on a random set of fd's.

>     switch ( select ( size, &readfds, NULL, NULL, NULL ) )
>     {
>       case -1:
>         if ( errno == EINTR )
>           continue;
>         else ...
>       break;
>       case 0:
>         continue;
>       break;
>     };
>   };
>
> "select" call here causes the following error: "Bad file descriptor". This
> example was taken from "Power programming with RPC" by John Bloomer.

Again, try making sure "readfds" is properly initialized.

> I tried to understand what svc_fdset consits of:
> sizeof ( svc_fdset ) == 2

This doesn't look right.  See below.

> Thus fd_set.fd_bits array has two elements:
> sprintf ( "%ld %ld\n", svc_fdset.fds_bits [ 0 ], svc_fdset.fds_bits [ 1 ] )
> == "8 0"
>
> But somehow:
> for (i=0;i<64;i++) FD_SET (i, svc_fdset) == 1

What's so strange about this?  fd_set is a *bitmask*, consisting of 2
4-byte (32-bit) quanitities, for a total of 64 bits.

> Could anyone tell me how to solve this problem?
> Lev.

fd_set is an 8-byte structure.  I'm not sure why "sizeof(svc_fdset)"
returns 2 bytes, but it's probably worth investigating.

In any case, if you think you've found a problem, please provide a
complete testcase, not the uncompilable snippet above.  Also, please
review and follow the Cygwin problem reporting guidelines at
<http://cygwin.com/problems.html>, in particular the part about
*attaching* the output of "cygcheck -svr".
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/