Skip to content

Commit

Permalink
Improve.
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Nov 16, 2018
1 parent f0600b1 commit d040a2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/Grpc/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public function __construct(string $hostname, array $opts = [])
];
$this->opts = $opts + $default_opts;
$this->timeout = &$this->opts['timeout'];
$this->sendYield = &$opts['send_yield'];
$this->sendYield = &$this->opts['send_yield'];
$this->ssl = &$this->opts['ssl'];
$this->ssl = $opts['ssl'] || !empty($opts['ssl_host_name']);
$this->ssl = !!$this->ssl || !!$this->opts['ssl_host_name'];

$this->constructClient();
}
Expand Down Expand Up @@ -379,7 +379,9 @@ public function write(int $streamId, $data, bool $end = false): bool

public function recv(int $streamId, float $timeout = null)
{
assert($streamId > 0);
if (!$this->isConnected() || $streamId <= 0) {
return false;
}
$channel = $this->recvChannelMap[$streamId] ?? null;
if ($channel) {
$response = $channel->pop($timeout === null ? $this->timeout : $timeout);
Expand All @@ -397,6 +399,9 @@ public function recv(int $streamId, float $timeout = null)

private function wait(int $type, $yield = true): bool
{
if (!$this->isConnected()) {
return false;
}
$this->waitStatus = $type;
if ($this->waitStatus === self::WAIT_CLOSE) {
$ret = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc/StreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function push($message): bool

public function recv(float $timeout = -1)
{
if (!$this->streamId) {
if ($this->streamId <= 0) {
$recv = false;
} else {
$recv = $this->client->recv($this->streamId, $timeout);
Expand Down

0 comments on commit d040a2e

Please sign in to comment.