Another point of view re sys_select behavior.
David Collier-Brown
davecb at canada.sun.com
Wed May 10 18:51:01 GMT 2000
Jeremy Allison wrote:
>
> David Collier-Brown wrote:
>
> > I therefor turned this into a three-possibility
> > check: success, failure (any of the three) or timeout.
> > It is the least code to cover the cases, and I strongly
> > recommend the team apply the fix or an equivalent one.
>
> Already done it Dave, thanks :-.
And Ron just found a bug in my code, and is
checking the
I forgot select returns 0 for timeout...
It should say...
---
struct packet_struct *receive_packet(int fd,enum packet_type type,int
t)
{
fd_set fds;
struct timeval timeout;
int rc;
FD_ZERO(&fds);
FD_SET(fd,&fds);
timeout.tv_sec = t/1000;
timeout.tv_usec = 1000*(t%1000);
if ((rc = sys_select(fd+1,&fds,&timeout)) == -1) {
/* errno should be EBADF or EINVAL. */
DEBUG(0,("select returned -1, errno = %s (%d)\n",
strerror(errno), errno));
return NULL;
}
else if (rc == 0) {
/* Select returned a timeout. */
return NULL;
}
else if (FD_ISSET(fd,&fds)) {
/* Get the data. */
return(read_packet(fd,type));
}
else {
return NULL;
}
}
---
The final else is arguably redundant for at least BSD.
--dave
More information about the samba-technical
mailing list