diff --git a/lib/EioHandle.php b/lib/EioHandle.php index a4e848a..14adb2f 100644 --- a/lib/EioHandle.php +++ b/lib/EioHandle.php @@ -132,6 +132,10 @@ class EioHandle implements Handle { $length = \strlen($data); + if ($length === 0) { + return new Success(0); + } + $deferred = new Deferred; $this->poll->listen($deferred->promise()); diff --git a/lib/UvHandle.php b/lib/UvHandle.php index b12b23e..d693a76 100644 --- a/lib/UvHandle.php +++ b/lib/UvHandle.php @@ -150,6 +150,10 @@ class UvHandle implements Handle { $length = \strlen($data); + if ($length === 0) { + return new Success(0); + } + $deferred = new Deferred; $this->poll->listen($deferred->promise()); diff --git a/test/HandleTest.php b/test/HandleTest.php index 6f2f4e7..8b5dd14 100644 --- a/test/HandleTest.php +++ b/test/HandleTest.php @@ -41,6 +41,21 @@ abstract class HandleTest extends TestCase }); } + public function testEmptyWrite() + { + $this->execute(function () { + $path = Fixture::path() . "/write"; + + $handle = yield File\open($path, "c+"); + $this->assertSame(0, $handle->tell()); + + yield $handle->write(""); + $this->assertSame(0, $handle->tell()); + + yield $handle->close(); + }); + } + public function testWriteAfterClose() { $this->execute(function () {