10000 StreamSelectLoop timer interval limit fix (on 32-bit systems) by alexmnv · Pull Request #23 · reactphp/event-loop · GitHub
[go: up one dir, main page]

Skip to content

StreamSelectLoop timer interval limit fix (on 32-bit systems) #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update StreamSelectLoop.php
  • Loading branch information
alexmnv committed Feb 5, 2015
commit e550715dcbc2dfe9071530a75c7d9ac2e0f8e76a
9 changes: 5 additions & 4 deletions src/StreamSelectLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ public function run()
$timeout = $scheduledAt - $this->timers->getTime();
if ($timeout < 0) {
$timeout = 0;
} else {
$timeout *= self::MICROSECONDS_PER_SECOND;
}

// The only possible event is stream activity, so wait forever ...
Expand Down Expand Up @@ -243,7 +241,7 @@ private function waitForStreamActivity($timeout)
*
* @param array &$read An array of read streams to select upon.
* @param array &$write An array of write streams to select upon.
* @param integer|null $timeout Activity timeout in microseconds, or null to wait forever.
* @param integer|null $timeout Activity timeout in seconds, or null to wait forever.
*
* @return integer The total number of streams that are ready for read/write.
*/
Expand All @@ -252,7 +250,10 @@ protected function streamSelect(array &$read, array &$write, $timeout)
if ($read || $write) {
$except = null;

return stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
$tv_sec = $timeout === null ?: floor($timeout);
// convert the fractional part of $timeout to microseconds
$tv_usec = $timeout === null ?: round(fmod($timeout, 1) * self::MICROSECONDS_PER_SECOND);
Copy link
Member
@jsor jsor Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When $timeout === null, both $tv_sec and $tv_usec will become true because of the elvis operator.

This should be

$tv_sec = $timeout === null ? null : floor($timeout);
// convert the fractional part of $timeout to microseconds
$tv_usec = $timeout === null ? null : round(fmod($timeout, 1) * self::MICROSECONDS_PER_SECOND);

return stream_select($read, $write, $except, $tv_sec, $tv_usec);
}

usleep($timeout);
Expand Down
0