php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #58199 spread_receive() should be able to wait forever
Submitted: 2008-05-23 07:06 UTC Modified: 2008-05-31 08:52 UTC
From: indeyets at gmail dot com Assigned:
Status: Closed Package: spread (PECL)
PHP Version: 5_2 CVS-2008-05-23 (dev) OS: irrelevant
Private report: No CVE-ID: None
 [2008-05-23 07:06 UTC] indeyets at gmail dot com
Description:
------------
spread_receive() has default value of 0 for "timeout" parameter which means, effectively, "check if there is anything on queue, but do not wait".

making timeout "positive" leads to some waiting-time in seconds.

wanted functionality: be able to wait for message without timeout. a common implementation for such cases is using "-1" value.

putting patch in "reproduce code" field

Reproduce code:
---------------
diff --git a/php_spread.c b/php_spread.c
index 69d6928..f325e29 100644
--- a/php_spread.c
+++ b/php_spread.c
@@ -590,12 +590,19 @@ PHP_FUNCTION(spread_receive) {
                RETURN_FALSE;
        }
 
-       towait.tv_sec = (unsigned long)timeout;
-       towait.tv_usec = (unsigned long)(1000000.0 * (timeout - (double)towait.tv_sec));
-
        FD_ZERO(&readfs);
        FD_SET(*mbox, &readfs);
-       if((ret = select(*mbox+1, &readfs, NULL, &readfs, &towait)) !=1 ) {
+
+       if (-1 == timeout) {
+               ret = select(*mbox+1, &readfs, NULL, &readfs, NULL);
+       } else {
+               towait.tv_sec = (unsigned long)timeout;
+               towait.tv_usec = (unsigned long)(1000000.0 * (timeout - (double)towait.tv_sec));
+
+               ret = select(*mbox+1, &readfs, NULL, &readfs, &towait);
+       }
+
+       if(1 != ret) {
                RETURN_FALSE;
        }



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-31 08:52 UTC] rrichards@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 03:01:28 2024 UTC