php: connectivity state review feedback

pull/2877/head
Stanley Cheung 9 years ago
parent 04b7a41d18
commit 1567c0c9a6
  1. 5
      src/php/ext/grpc/channel.c
  2. 17
      src/php/lib/Grpc/BaseStub.php

@ -256,10 +256,7 @@ PHP_METHOD(Channel, watchConnectivityState) {
grpc_event event = grpc_completion_queue_pluck(
completion_queue, NULL,
gpr_inf_future(GPR_CLOCK_REALTIME));
if (!event.success) {
RETURN_BOOL(0);
}
RETURN_BOOL(1);
RETURN_BOOL(event.success);
}
/**

@ -85,8 +85,9 @@ class BaseStub {
/**
* @param $timeout in microseconds
* @return bool true if channel is ready
* @throw Exception if channel is in FATAL_ERROR state
*/
public function watchForReady($timeout) {
public function waitForReady($timeout) {
$new_state = $this->getConnectivityState(true);
if ($this->_checkConnectivityState($new_state)) {
return true;
@ -96,14 +97,16 @@ class BaseStub {
$delta = new Timeval($timeout);
$deadline = $now->add($delta);
if (!$this->channel->watchConnectivityState($new_state, $deadline)) {
return false;
while ($this->channel->watchConnectivityState($new_state, $deadline)) {
// state has changed before deadline
$new_state = $this->getConnectivityState();
if ($this->_checkConnectivityState($new_state)) {
return true;
}
}
// deadline has passed
$new_state = $this->getConnectivityState();
if ($this->_checkConnectivityState($new_state)) {
return true;
}
return false;
return $this->_checkConnectivityState($new_state);
}
private function _checkConnectivityState($new_state) {

Loading…
Cancel
Save