Skip to content

Commit d040a2e

Browse files
committed
Improve.
1 parent f0600b1 commit d040a2e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Grpc/Client.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ public function __construct(string $hostname, array $opts = [])
131131
];
132132
$this->opts = $opts + $default_opts;
133133
$this->timeout = &$this->opts['timeout'];
134-
$this->sendYield = &$opts['send_yield'];
134+
$this->sendYield = &$this->opts['send_yield'];
135135
$this->ssl = &$this->opts['ssl'];
136-
$this->ssl = $opts['ssl'] || !empty($opts['ssl_host_name']);
136+
$this->ssl = !!$this->ssl || !!$this->opts['ssl_host_name'];
137137

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

380380
public function recv(int $streamId, float $timeout = null)
381381
{
382-
assert($streamId > 0);
382+
if (!$this->isConnected() || $streamId <= 0) {
383+
return false;
384+
}
383385
$channel = $this->recvChannelMap[$streamId] ?? null;
384386
if ($channel) {
385387
$response = $channel->pop($timeout === null ? $this->timeout : $timeout);
@@ -397,6 +399,9 @@ public function recv(int $streamId, float $timeout = null)
397399

398400
private function wait(int $type, $yield = true): bool
399401
{
402+
if (!$this->isConnected()) {
403+
return false;
404+
}
400405
$this->waitStatus = $type;
401406
if ($this->waitStatus === self::WAIT_CLOSE) {
402407
$ret = true;

src/Grpc/StreamingCall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function push($message): bool
4646

4747
public function recv(float $timeout = -1)
4848
{
49-
if (!$this->streamId) {
49+
if ($this->streamId <= 0) {
5050
$recv = false;
5151
} else {
5252
$recv = $this->client->recv($this->streamId, $timeout);

0 commit comments

Comments
 (0)