Re: Select Problem
Re: Select Problem
- Subject: Re: Select Problem
- From: Jason Linhart <email@hidden>
- Date: Mon, 16 Feb 2004 11:25:56 -0500
On 2/16/04 11:13 AM Dario (email@hidden) wrote:
>
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
_______________________________________________
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.