Skip to content

Commit

Permalink
Fix writing in watcher callback if $chunkSize is null
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jun 18, 2017
1 parent 8b20bf9 commit 816307c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ResourceOutputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public function __construct($stream, int $chunkSize = null) {
}

// Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full.
$written = @\fwrite($stream, $data, $chunkSize);
// Use conditional, because PHP doesn't like getting null passed.
if ($chunkSize) {
$written = @\fwrite($stream, $data, $chunkSize);
} else {
$written = @\fwrite($stream, $data);
}

if ($written === false || $written === 0) {
$writable = false;
Expand Down Expand Up @@ -163,6 +168,7 @@ private function send(string $data, bool $end = false): Promise {
}

if ($written === false) {
$this->close();
$message = "Failed to write to stream";
if ($error = \error_get_last()) {
$message .= \sprintf(" Errno: %d; %s", $error["type"], $error["message"]);
Expand Down

0 comments on commit 816307c

Please sign in to comment.