Skip to content

Commit

Permalink
Fixed Socket Client can't exit when server is shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Aug 11, 2016
1 parent e761db4 commit b652d0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Hprose/Socket/FullDuplexTransporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/Hprose/Socket/HalfDuplexTransporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 13 additions & 9 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 31, 2016 *
* LastModified: Aug 11, 2016 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit b652d0b

Please sign in to comment.