this function has a bug on windows I have reported this bug at 8/25/2004 but the fix did not got into ver 1.0.0:
the num parameter have to return the length of descriptors
the select call returns the total number of socket handles that are ready and contained in the fd_set structures
therefore if we have 2 socket that one have an FD_READ and the second have FD_READ and FD_WRITE it will return 3 , but the lenght of descriptors is only 2 , this is a bug
there for the fix for this bug is to add this line at file poll.c
(*num) = j;
#else /* no poll */
APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset,
apr_interval_time_t timeout,
apr_int32_t *num,
const apr_pollfd_t **descriptors)
{
int rv;
apr_uint32_t i, j;
struct timeval tv, *tvptr;
fd_set readset, writeset, exceptset;
if (timeout < 0) {
tvptr = NULL;
}
else {
tv.tv_sec = (long)apr_time_sec(timeout);
tv.tv_usec = (long)apr_time_usec(timeout);
tvptr = &tv;
}
memcpy(&readset, &(pollset->readset), sizeof(fd_set));
memcpy(&writeset, &(pollset->writeset), sizeof(fd_set));
memcpy(&exceptset, &(pollset->exceptset), sizeof(fd_set));
#ifdef NETWARE
if (HAS_PIPES(pollset->set_type)) {
rv = pipe_select(pollset->maxfd + 1, &readset, &writeset, &exceptset, tvptr);
}
else
#endif
rv = select(pollset->maxfd + 1, &readset, &writeset, &exceptset, tvptr);
(*num) = rv;
if (rv < 0) {
return apr_get_netos_error();
}
if (rv == 0) {
return APR_TIMEUP;
}
j = 0;
for (i = 0; i < pollset->nelts; i++) {
apr_os_sock_t fd;
if (pollset->query_set[i].desc_type == APR_POLL_SOCKET) {
fd = pollset->query_set[i].desc.s->socketdes;
}
else {
#if !APR_FILES_AS_SOCKETS
return APR_EBADF;
#else
fd = pollset->query_set[i].desc.f->filedes;
#endif
}
if (FD_ISSET(fd, &readset) || FD_ISSET(fd, &writeset) ||
FD_ISSET(fd, &exceptset)) {
pollset->result_set[j] = pollset->query_set[i];
pollset->result_set[j].rtnevents = 0;
if (FD_ISSET(fd, &readset)) {
pollset->result_set[j].rtnevents |= APR_POLLIN;
}
if (FD_ISSET(fd, &writeset)) {
pollset->result_set[j].rtnevents |= APR_POLLOUT;
}
if (FD_ISSET(fd, &exceptset)) {
pollset->result_set[j].rtnevents |= APR_POLLERR;
}
j++;
}
}
if (descriptors)
*descriptors = pollset->result_set;
(*num) = j;
return APR_SUCCESS;
}
#endif /* no poll */
Dror Shilo
Ericom software
-----Original Message-----
From: David Barrett [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 04, 2004 3:53 AM
Subject: Does apr_pollset_poll( ... ) block on non-blocking sockets?
Is the function "apr_pollset_poll( )" supposed to block, even on
non-blocking sockets? I ask because I would like it to, even though it
appears to not. The docs say this about the function:
Block for activity on the descriptor(s) in a pollset
Ideally I would like to *not* block when reading or writing, but I *do* want
to block while polling with a timeout. Am I doing something wrong, or is it
working as designed?
-david
