From fdcf400f19af26d06d183127d7cce57b24c574cf Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Fri, 15 Sep 2017 00:17:42 -0500 Subject: [PATCH] Check writable flag rather than for null resource Also null resource when writing in watcher callback fails. Fixes #20. --- lib/ResourceOutputStream.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ResourceOutputStream.php b/lib/ResourceOutputStream.php index 113f8cb..b9805d2 100644 --- a/lib/ResourceOutputStream.php +++ b/lib/ResourceOutputStream.php @@ -81,6 +81,7 @@ public function __construct($stream, int $chunkSize = null) { return; } + $resource = null; $writable = false; $message = "Failed to write to socket"; @@ -144,7 +145,7 @@ public function end(string $finalData = ""): Promise { } private function send(string $data, bool $end = false): Promise { - if ($this->resource === null) { + if (!$this->writable) { return new Failure(new StreamException("The stream is not writable")); }