You are not logged in.
Pages: 1
If I understand the documentation on select, select will block forever if the time out is set to zero.
My code looks like:
FD_ZERO(&readfds);
FD_SET(dns_sd_fd, &readfds);
tv.tv_sec = 1; //timeOut in 1 second;
tv.tv_usec = 0;
result = select(nfds, &readfds, (fd_set*)NULL, (fd_set*)NULL, &tv);
if (result > 0)
...
}
else
{
fprintf(stderr, "select() returned %d errno %d %s\n", result, errno, strerror(errno));
if (errno != EINTR) stopNow = 1;
}
...I never see a time out.... It just never happens.
Mac OS X 10.5
XCode 3.1.4
Offline
Actually, select() will block forever (or until the socket is ready-for-read) if you pass in NULL as the last argument (instead of a pointer to a timeval struct)
Passing in a timeval that has both tv_secs and tv_usecs set to zero, on the other hand, will force select() to return immediately no matter what.
In the code you posted, I would expect select() to return in 1 second, or earlier if your readfds socket has data available to read.
Note that you should test the return value to be "if (result >= 0)" instead of "if (result > 0)", since select() returning zero doesn't indicate an error. select() returns zero if the timeout was reached without any sockets being ready-for-(whatever).
Offline
I never see a time out.... It just never happens.
Are you saying that you end up blocking in that select() call for longer than 1 second?
Because, if that's true, that's a bug... And, I really doubt such an obvious bug would
exist in any OS's select()... So, it's probably something else going on with your code...
My guess is you're not "seeing" the timeout, because you just treat it the same as
an error condition, as jfriesne pointed out... But, it's surely still actually happening...
Or else select() is always returning in less time than a second with a positive return
value, because the FD is always readable...
Offline
If the time limit expires, select() returns 0.
result = select(nfds, &readfds, (fd_set*)NULL, (fd_set*)NULL, &tv);
if (result > 0)
{
if (FD_ISSET(dns_sd_fd, &readfds)) ProcessResult();
}
else if (result == 0)
{
printf("timeout\n");
}else{
printf("select( ) returned %d errno %d %s\n", result, errno, strerror(errno));
if (errno != EINTR) stopNow = 1;
}Offline
Pages: 1