-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
12 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> * | ||
* * | ||
\**********************************************************/ | ||
|
@@ -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"); | ||
} | ||
|