-
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.
Fixed Socket Client can't exit when server is shutdown.
- Loading branch information
Showing
3 changed files
with
16 additions
and
13 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 FullDuplexTransporter class for php 5.3+ * | ||
* * | ||
* LastModified: Jul 30, 2016 * | ||
* LastModified: Aug 11, 2016 * | ||
* Author: Ma Bingyao <[email protected]> * | ||
* * | ||
\**********************************************************/ | ||
|
@@ -47,7 +47,7 @@ protected function afterWrite($request, $stream, $o) { | |
} | ||
$o->queue[$stream_id][$request->id] = $response; | ||
} | ||
protected function asyncReadError($o, $stream, $index) { | ||
protected function asyncReadError($o, $stream, $index = -1) { | ||
$stream_id = (integer)$stream; | ||
foreach ($o->queue[$stream_id] as $response) { | ||
$index = $response->index; | ||
|
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 HalfDuplexTransporter class for php 5.3+ * | ||
* * | ||
* LastModified: Jul 30, 2016 * | ||
* LastModified: Aug 11, 2016 * | ||
* Author: Ma Bingyao <[email protected]> * | ||
* * | ||
\**********************************************************/ | ||
|
@@ -54,7 +54,6 @@ protected function getResponse($stream, $o) { | |
$response = $o->responses[$stream_id]; | ||
if ($response->length === 0) { | ||
$length = $this->getBodyLength($stream); | ||
if ($length === false) return false; | ||
$response->length = $length; | ||
} | ||
return $response; | ||
|
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 31, 2016 * | ||
* LastModified: Aug 11, 2016 * | ||
* Author: Ma Bingyao <[email protected]> * | ||
* * | ||
\**********************************************************/ | ||
|
@@ -69,12 +69,17 @@ protected function readHeader($stream, $n) { | |
do { | ||
$buffer = @fread($stream, $n - strlen($header)); | ||
$header .= $buffer; | ||
} while (($buffer !== false) && (strlen($header) < $n)); | ||
if ($buffer === false) { | ||
} while (!empty($buffer) && (strlen($header) < $n)); | ||
if (strlen($header) < $n) { | ||
return false; | ||
} | ||
return $header; | ||
} | ||
protected function free($o, $index) { | ||
unset($o->results[$index]); | ||
unset($o->deadlines[$index]); | ||
unset($o->buffers[$index]); | ||
} | ||
protected function asyncWrite($stream, $o) { | ||
$stream_id = (integer)$stream; | ||
if (isset($o->requests[$stream_id])) { | ||
|
@@ -105,20 +110,19 @@ protected function asyncWrite($stream, $o) { | |
$this->afterWrite($request, $stream, $o); | ||
} | ||
} | ||
private function free($o, $index) { | ||
unset($o->results[$index]); | ||
unset($o->deadlines[$index]); | ||
unset($o->buffers[$index]); | ||
} | ||
private function asyncRead($stream, $o) { | ||
$response = $this->getResponse($stream, $o); | ||
if ($response === false) { | ||
$this->asyncReadError($o, $stream, -1); | ||
return; | ||
} | ||
else if ($response->length === false) { | ||
$this->asyncReadError($o, $stream, $response->index); | ||
return; | ||
} | ||
$remaining = $response->length - strlen($response->buffer); | ||
$buffer = @fread($stream, $remaining); | ||
if ($buffer === false) { | ||
if (empty($buffer)) { | ||
$this->asyncReadError($o, $stream, $response->index); | ||
return; | ||
} | ||
|