|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-05-31 08:52 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 04:00:01 2025 UTC |
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; }