1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00

Fix #256 - Ensure nowUpdateNeeded is set to true after a blocking wait in NativeDriver

So that expired timeouts also indeed do trigger immediately instead of in the next tick.
This commit is contained in:
Bob Weinand 2019-01-21 16:41:30 +01:00 committed by GitHub
parent 216315ee5c
commit c3afc5e977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,10 +166,15 @@ class NativeDriver extends Driver
$timeout /= self::MILLISEC_PER_SEC;
if (!empty($read) || !empty($write)) { // Use stream_select() if there are any streams in the loop.
if ($timeout >= 0) {
if ($timeout == 0) {
$seconds = 0;
$microseconds = 0;
} elseif ($timeout > 0) {
$this->nowUpdateNeeded = true;
$seconds = (int) $timeout;
$microseconds = (int) (($timeout - $seconds) * self::MICROSEC_PER_SEC);
} else {
$this->nowUpdateNeeded = true;
$seconds = null;
$microseconds = null;
}
@ -258,6 +263,7 @@ class NativeDriver extends Driver
if ($timeout > 0) { // Otherwise sleep with usleep() if $timeout > 0.
\usleep($timeout * self::MICROSEC_PER_SEC);
$this->nowUpdateNeeded = true;
}
}