You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Joe Orton <jo...@redhat.com> on 2004/08/25 10:39:57 UTC
Re: bug to fix in poll.c
On Wed, Aug 25, 2004 at 08:20:49AM +0300, Dror Shilo wrote:
> 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;
Thanks for looking into this. I don't have a platform using select() to
hand, but it looks like apr_poll() needs to be fixed too. Can you try
this patch against 0.9.4?
--- poll/unix/poll.c 10 Apr 2004 21:29:52 -0000 1.38.2.2
+++ poll/unix/poll.c 25 Aug 2004 08:37:16 -0000
@@ -244,14 +244,14 @@
}
#endif
- (*nsds) = rv;
- if ((*nsds) == 0) {
+ if (rv == 0) {
return APR_TIMEUP;
}
- if ((*nsds) < 0) {
+ if (rv < 0) {
return apr_get_netos_error();
}
-
+
+ *nsds = 0;
for (i = 0; i < num; i++) {
apr_os_sock_t fd;
@@ -268,14 +268,18 @@
else {
break;
}
- if (FD_ISSET(fd, &readset)) {
- aprset[i].rtnevents |= APR_POLLIN;
- }
- if (FD_ISSET(fd, &writeset)) {
- aprset[i].rtnevents |= APR_POLLOUT;
- }
- if (FD_ISSET(fd, &exceptset)) {
- aprset[i].rtnevents |= APR_POLLERR;
+ if (FD_ISSET(fd, &readset) || FD_ISSET(fd, &writeset) ||
+ FD_ISSET(fd, &exceptset)) {
+ (*nsds)++;
+ if (FD_ISSET(fd, &readset)) {
+ aprset[i].rtnevents |= APR_POLLIN;
+ }
+ if (FD_ISSET(fd, &writeset)) {
+ aprset[i].rtnevents |= APR_POLLOUT;
+ }
+ if (FD_ISSET(fd, &exceptset)) {
+ aprset[i].rtnevents |= APR_POLLERR;
+ }
}
}
@@ -553,8 +557,6 @@
else
#endif
rv = select(pollset->maxfd + 1, &readset, &writeset, &exceptset, tvptr);
-
- (*num) = rv;
if (rv < 0) {
return apr_get_netos_error();
}
@@ -590,6 +592,8 @@
j++;
}
}
+
+ (*num) = j;
*descriptors = pollset->result_set;
return APR_SUCCESS;