[Icecast-dev] libnet: sock_connected insists on a timeout

Michael Smith msmith
Sun Jul 25 19:44:29 PDT 2004


On Monday 26 July 2004 11:48, Brendan Cully wrote:
> While working on integrating nonblocking IO into libshout, I noticed
> that sock_connected cannot be called without blocking. If I read it
> right, a timeout of zero will cause the call to block until the socket
> is connected. So, my questions:
>
> 1. Am I reading this right?

No. The timeout value (in seconds) gets put into a struct timeval.

This timeval gets passed directly to select().

Select() has 2 behaviours defined:

non-null timeval: block for up to this length of time. If { 0, 0 } is passed
in, then, this means "don't block".
null timeval: block indefinately.

We don't special-case zero to pass null, so passing zero will just never
block.

Maybe the comment above the function should say "pass zero as timeout if you
don't want it to block).

We might also consider allowing negative values to actually mean "block
forever" (special-cased to pass NULL), but I agrew with you that it's
unlikely anyone wants to do that.

Mike




More information about the Icecast-dev mailing list