From 9770a702882211bbf566164728080f3c245ea8bb Mon Sep 17 00:00:00 2001 From: techno-express Date: Sun, 28 Feb 2021 15:18:42 -0500 Subject: [PATCH] bug fix by reverting some of last commit, insure `progressTask` only execute if actual data is returned --- Coroutine/FileSystem.php | 4 ++-- Coroutine/Kernel.php | 4 ++-- tests/FileSystemTest.php | 2 +- tests/libuv/010-uv_ip4_addr.phpt | 2 +- tests/libuv/010-uv_ip6_addr.phpt | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Coroutine/FileSystem.php b/Coroutine/FileSystem.php index 1e03c7f..054bd4a 100644 --- a/Coroutine/FileSystem.php +++ b/Coroutine/FileSystem.php @@ -1076,7 +1076,7 @@ protected static function writeFile($fd, string $buffer, $immediately = false) yield; $fwrite = 0; for ($written = 0; $written < \strlen($buffer); $written += $fwrite) { - yield Kernel::writeWait($fd, $immediately); + yield Kernel::writeWait($fd, (\is_bool($immediately) ? $immediately : false)); $fwrite = \fwrite($fd, \substr($buffer, $written)); // see https://www.php.net/manual/en/function.fwrite.php#96951 if (($fwrite === false) || ($fwrite == 0)) { @@ -1187,7 +1187,7 @@ public static function meta($fd, ?string $info = null) if ($info == 'status' && isset($meta['wrapper_data'])) { $http_statusCode = 400; foreach ($meta['wrapper_data'] as $headerLine) { - if (preg_match('/^HTTP\/(\d+\.\d+)\s+(\d+)\s*(.+)?$/', $headerLine, $result)) { + if (\preg_match('/^HTTP\/(\d+\.\d+)\s+(\d+)\s*(.+)?$/', $headerLine, $result)) { $http_statusCode = (int) $result[2]; } } diff --git a/Coroutine/Kernel.php b/Coroutine/Kernel.php index d720455..a087930 100644 --- a/Coroutine/Kernel.php +++ b/Coroutine/Kernel.php @@ -562,7 +562,8 @@ public static function progressTask(callable $handler) if (\is_array($received) && (\count($received) == 2)) { [$type, $data] = $received; $received = null; - yield $handler($type, $data); + if (!\is_null($data)) + yield $handler($type, $data); } } }); @@ -818,7 +819,6 @@ function (TaskInterface $task, CoroutineInterface $coroutine) use ($taskId) { continue; } - if ($tasks->isPending()) { $coroutine->execute(); } elseif ($tasks->isRescheduled()) { diff --git a/tests/FileSystemTest.php b/tests/FileSystemTest.php index fea0692..8d96c1f 100644 --- a/tests/FileSystemTest.php +++ b/tests/FileSystemTest.php @@ -312,7 +312,7 @@ public function taskFileSendfile() $this->assertEquals($size, $written); $data = yield \file_contents($outFd); $this->assertEquals('Hello', \trim($data)); - $this->assertGreaterThanOrEqual(8, $this->counterResult); + $this->assertGreaterThanOrEqual(7, $this->counterResult); yield \file_close($fd); yield \file_close($outFd); diff --git a/tests/libuv/010-uv_ip4_addr.phpt b/tests/libuv/010-uv_ip4_addr.phpt index ba47ff8..93e1913 100644 --- a/tests/libuv/010-uv_ip4_addr.phpt +++ b/tests/libuv/010-uv_ip4_addr.phpt @@ -4,5 +4,5 @@ Check for uv_ip4_addr