Skip to content

Commit 5c47be8

Browse files
committed
Handle zero-value return from fwrite() (fixes #6)
1 parent f2a24a3 commit 5c47be8

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/ReactApi.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ public function write(
186186
$length = $bufferLength;
187187
}
188188

189+
if ($length == 0) {
190+
$strand->send();
191+
192+
return;
193+
}
194+
189195
$done = null;
190196
$done = $this->streamQueue->write(
191197
$stream,
@@ -197,7 +203,9 @@ function ($stream) use (
197203
) {
198204
$bytes = @\fwrite($stream, $buffer, $length);
199205

200-
if ($bytes === false) {
206+
// zero and false both indicate an error
207+
// http://php.net/manual/en/function.fwrite.php#96951
208+
if ($bytes === 0 || $bytes === false) {
201209
// @codeCoverageIgnoreStart
202210
$done();
203211
$error = \error_get_last();

test/suite/unit/ReactKernel.spec.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Recoil\React;
66

77
use Eloquent\Phony\Phony;
8-
use React\EventLoop\Factory;
98
use React\EventLoop\LoopInterface;
109
use Recoil\Kernel\Api;
1110
use Throwable;
@@ -22,7 +21,7 @@
2221
});
2322

2423
describe('::create()', function () {
25-
it('can be called without a loop', function() {
24+
it('can be called without a loop', function () {
2625
$kernel = ReactKernel::create();
2726
expect($kernel)->to->be->an->instanceof(ReactKernel::class);
2827
});

0 commit comments

Comments
 (0)