• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Select Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Select Problem


  • Subject: Re: Select Problem
  • From: Dario <email@hidden>
  • Date: Mon, 16 Feb 2004 17:57:11 +0100

I have some problem using select, i can't accept any connection.
this is the test code I have used to understand the problem.
with this it will always wait and never unblocks. what is wrong ?

while( 1 ) {
ret = select(1,&rset,NULL,NULL,NULL);

I see four problems/issues here.

1) The first argument to select should be the highest numbered fd plus
one, not the number of fds. In this case that would be sock+1.

2) select modifies rset, so you need to do the FD_SET inside the loop,
not outside.

3) It is always a good idea to provide a timeout value, the final
argument to select. Otherwise it will wait forever in a variety of
situations, even if you fix the above two problems.

4) Less important, but still useful, would be to provide an exception set
that included sock. You will hang if you get an exception on the socket
as it stands now. This can be worked around with a timeout, but actually
catching exceptions is always a good idea, rare as they may be.

Jason

-----------------
email@hidden
-----------------
Dr. Seuss books . . . can be read and enjoyed on several levels. For
example, 'One Fish Two Fish, Red Fish Blue Fish' can be deconstructed
as a searing indictment of the narrow-minded binary counting system.
-- Peter van der Linden, Expert C Programming, Deep C Secrets





Another question, on ndfs ( first argument ). it must be (max fd in select + 1 ) or I can set it to a very big value as 0xFFFFFFFF to don't care anymore of the problem, without any problem ?
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: Select Problem (From: Jason Linhart <email@hidden>)

  • Prev by Date: Re: Select Problem
  • Next by Date: Re: Select Problem
  • Previous by thread: Re: Select Problem
  • Next by thread: Re: Select Problem
  • Index(es):
    • Date
    • Thread