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

Brendan Cully brendan
Sun Jul 25 19:48:01 PDT 2004


<200407261244.30032.msmith at xiph.org>
Message-ID: <20040726024801.GA18890 at watanabe.local>

On Monday, 26 July 2004 at 12:44, Michael Smith wrote:
> 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.

are we looking at the same code?

int sock_connected (int sock, unsigned timeout)
{
fd_set wfds;
int val = SOCK_ERROR;
socklen_t size = sizeof val;
struct timeval tv, *timeval = NULL;

if (timeout)
{
tv.tv_sec = timeout;
tv.tv_usec = 0;
timeval = &tv;
}

FD_ZERO(&wfds);
FD_SET(sock, &wfds);

switch (select(sock + 1, NULL, &wfds, NULL, timeval))

that looks like a special case to me.


More information about the Icecast-dev mailing list