Skip to content

Commit

Permalink
Fix NativeDriver when only signals are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Oct 10, 2020
1 parent 3a4c13a commit eb2f325
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/Loop/NativeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ private function selectStreams(array $read, array $write, int $timeout)
return;
}

if ($timeout > 0) { // Otherwise sleep with usleep() if $timeout > 0.
if ($timeout < 0) { // Only signal watchers are enabled, so sleep indefinitely.
\usleep(\PHP_INT_MAX);
return;
}

if ($timeout > 0) { // Sleep until next timer expires.
\usleep((int) ($timeout * self::MICROSEC_PER_SEC));
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/Loop/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public function testWeakTypes($type, $args)
\call_user_func_array([$loop, $type], $args);

if ($type == "onSignal") {
$loop->defer(function () {
$loop->delay(1, function () {
\posix_kill(\getmypid(), \SIGUSR1);
});
}
Expand Down Expand Up @@ -685,11 +685,11 @@ public function testNoMemoryLeak($type, $args)
$loop->onSignal(\SIGUSR1, $fn = function ($watcherId, $signo, $i) use (&$fn, $loop, $sendSignal) {
if ($i) {
$loop->onSignal(\SIGUSR1, $fn, --$i);
$loop->defer($sendSignal);
$loop->delay(1, $sendSignal);
}
$loop->cancel($watcherId);
}, $runs);
$loop->defer($sendSignal);
$loop->delay(1, $sendSignal);
$loop->run();
}
};
Expand Down Expand Up @@ -837,7 +837,7 @@ public function testSignalExecutionOrder()
$loop->onSignal(SIGUSR1, $f(2));
$loop->defer(function () use ($loop, $sig2) {
$loop->enable($sig2);
$loop->defer(function () use ($loop) {
$loop->delay(1, function () use ($loop) {
\posix_kill(\getmypid(), \SIGUSR1);
$loop->delay($msDelay = 10, function () use ($loop) {
$loop->stop();
Expand Down

0 comments on commit eb2f325

Please sign in to comment.