Skip to content

Commit

Permalink
Fixed fclose
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Jan 10, 2019
1 parent 1dbf3da commit 3b03039
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Hprose/Socket/Transporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
* hprose socket Transporter class for php 5.3+ *
* *
* LastModified: Jul 25, 2018 *
* LastModified: Jan 10, 2019 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 3b03039

Please sign in to comment.