netutils use of socket descriptor

Hiren Patel hir3npatel at gmail.com
Mon Jun 15 21:50:20 CEST 2009


Thomas Guyot-Sionnest wrote:
> Good catch, though it looks like it will have no effect whatsoever.
> 
> According to socket(2):
>   On success, a file descriptor for  the  new  socket  is  returned. On
>   error, -1 is returned, and errno is set appropriately.
> 
> In other words if sd is not <0 (which returns an error immediately) the
> condition will always succeed (just like when testing the pointer) and
> there is no need to walk further the r list.
>
ah yes, I see that now.

> If you want to connect with a given per-address or global timeout, then
> you'll have to include most of the rest of the function in the while(r)
> loop... unfortunately that will give you a per-ip timeout which is
> likely not desired.
> 
> 
> A better way of doing this is to send a connect for the next ip in list
> every n miliseconds (where n is a small fraction of the timeout, you
> could for example take half of the timeout and divide it by the number
> of IP), use the first connected socket and clean up the rest.
> 
>
I'm not trying to solve any immediate problem, I was just having a look 
and came across that, so I'm not inclined to change its current 
behavior. thanks for the reply.


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects




More information about the Developers mailing list