From 3b030391233020f480557933856ee90493e101b5 Mon Sep 17 00:00:00 2001 From: andot Date: Thu, 10 Jan 2019 17:19:25 +0800 Subject: [PATCH] Fixed fclose --- src/Hprose/Socket/Transporter.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Hprose/Socket/Transporter.php b/src/Hprose/Socket/Transporter.php index bdfd22eb..f21ad660 100644 --- a/src/Hprose/Socket/Transporter.php +++ b/src/Hprose/Socket/Transporter.php @@ -14,7 +14,7 @@ * * * hprose socket Transporter class for php 5.3+ * * * - * LastModified: Jul 25, 2018 * + * LastModified: Jan 10, 2019 * * Author: Ma Bingyao * * * \**********************************************************/ @@ -42,12 +42,16 @@ protected abstract function asyncReadError($o, $stream, $index); protected abstract function getResponse($stream, $o); protected abstract function afterRead($stream, $o, $response); + private function fclose($handle) { + if (is_resource($handle)) @fclose($handle); + } + public function __construct(Client $client, $async) { $this->client = $client; $this->async = $async; } public function __destruct() { - if ($this->stream !== null) @fclose($this->stream); + if ($this->stream !== null) $this->fclose($this->stream); } protected function getLastError($error) { $e = error_get_last(); @@ -104,7 +108,7 @@ protected function asyncWrite($stream, $o) { if ($sent === false) { $o->results[$request->index]->reject($this->getLastError('request write error')); $this->free($o, $request->index); - @fclose($stream); + $this->fclose($stream); $this->removeStream($stream, $o->writepool); return; } @@ -149,7 +153,7 @@ private function asyncRead($stream, $o) { private function removeStreamById($stream_id, &$pool) { foreach ($pool as $index => $stream) { if ((integer)$stream == $stream_id) { - @fclose($stream); + $this->fclose($stream); unset($pool[$index]); return; } @@ -276,8 +280,8 @@ public function loop() { $o->writepool = $this->createPool($client, $o); } } - foreach ($o->writepool as $stream) @fclose($stream); - foreach ($o->readpool as $stream) @fclose($stream); + foreach ($o->writepool as $stream) $this->fclose($stream); + foreach ($o->readpool as $stream) $this->fclose($stream); } } public function asyncSendAndReceive($buffer, stdClass $context) { @@ -378,13 +382,13 @@ public function syncSendAndReceive($buffer, stdClass $context) { } } if ($this->write($stream, $buffer) === false) { - @fclose($this->stream); + $this->fclose($this->stream); $this->stream = null; throw $this->getLastError("request write error"); } $response = $this->read($stream, $buffer); if ($response === false) { - @fclose($this->stream); + $this->fclose($this->stream); $this->stream = null; throw $this->getLastError("response read error"); }