php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56500 poll not working, patch here
Submitted: 2005-08-18 11:07 UTC Modified: 2013-07-16 06:12 UTC
From: xuefer at 21cn dot com Assigned: osmanov (profile)
Status: Closed Package: event (PECL)
PHP Version: 5_1 CVS-2005-08-18 (dev) OS: gentoo
Private report: No CVE-ID: None
 [2005-08-18 11:07 UTC] xuefer at 21cn dot com
Description:
------------
Index: poll.c
===================================================================
RCS file: /repository/pecl/event/poll.c,v
retrieving revision 1.1
diff -u -r1.1 poll.c
--- poll.c  13 Dec 2004 04:56:31 -0000  1.1
+++ poll.c  18 Aug 2005 15:02:12 -0000
@@ -75,11 +75,12 @@
 static int poll_event_dispatch(void *arg, struct timeval *tv TSRMLS_DC)
 {
    struct poll_state *st = (struct poll_state*)arg;
-   int res, i, count, msec, nfds;
+   int res, i, count, msec, nfds, events;
    struct php_event *ev;
    struct pollfd *pfd;
 
-   if (EVENT_G(event_count) > st->event_count) {
+   count = EVENT_G(event_count);
+   if (count > st->event_count) {
        st->fds = erealloc(st->fds, count * sizeof(struct pollfd));
        st->slot_to_event = erealloc(st->slot_to_event, count * sizeof(struct php_event*));
        st->event_count = count;    
@@ -122,28 +123,33 @@
        return 0;
    }
 
-   for (i = 0; i < nfds; i++) {
-       pfd = &st->fds[nfds];
+   for (i = 0; res > 0 && i < nfds; i++) {
+       pfd = &st->fds[i];
+
+       if (pfd->revents == 0) {
+           continue;
+       }
+       res --;
 
-       res = 0;
+       events = 0;
        if (pfd->revents & (POLLERR|POLLHUP)) {
-           res |= EV_READ|EV_WRITE;
+           events |= EV_READ|EV_WRITE;
        }
        if (pfd->revents & POLLIN) {
-           res |= EV_READ;
+           events |= EV_READ;
        }
        if (pfd->revents & POLLOUT) {
-           res |= EV_WRITE;
+           events |= EV_WRITE;
        }
 
        ev = st->slot_to_event[i];
-       res &= ev->ev_events;
+       events &= ev->ev_events;
 
-       if (res == 0) {
+       if (events == 0) {
            continue;
        }
 
-       event_active(ev, res, 1 TSRMLS_CC);         
+       event_active(ev, events, 1 TSRMLS_CC);          
    }
    return 0;   
 }

-----------------------
in case u don't like the above. here's the clean patch without using (res > 0)
Index: poll.c
===================================================================
RCS file: /repository/pecl/event/poll.c,v
retrieving revision 1.1
diff -u -r1.1 poll.c
--- poll.c  13 Dec 2004 04:56:31 -0000  1.1
+++ poll.c  18 Aug 2005 15:06:11 -0000
@@ -79,7 +79,8 @@
    struct php_event *ev;
    struct pollfd *pfd;
 
-   if (EVENT_G(event_count) > st->event_count) {
+   count = EVENT_G(event_count);
+   if (count > st->event_count) {
        st->fds = erealloc(st->fds, count * sizeof(struct pollfd));
        st->slot_to_event = erealloc(st->slot_to_event, count * sizeof(struct php_event*));
        st->event_count = count;    
@@ -123,7 +124,7 @@
    }
 
    for (i = 0; i < nfds; i++) {
-       pfd = &st->fds[nfds];
+       pfd = &st->fds[i];
 
        res = 0;
        if (pfd->revents & (POLLERR|POLLHUP)) {


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-14 06:05 UTC] phpxcache at gmail dot com
any idea when will this be checked and commited?
 [2013-07-16 06:12 UTC] osmanov@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: osmanov -Block user comment: No +Block user comment: Yes
 [2013-07-16 06:12 UTC] osmanov@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Mar 24 13:01:25 2019 UTC