|
|
|
@ -51,8 +51,10 @@ |
|
|
|
|
#include <grpc/support/log.h> |
|
|
|
|
#include <grpc/grpc_security.h> |
|
|
|
|
|
|
|
|
|
#include "server.h" |
|
|
|
|
#include "completion_queue.h" |
|
|
|
|
#include "credentials.h" |
|
|
|
|
#include "server.h" |
|
|
|
|
#include "timeval.h" |
|
|
|
|
|
|
|
|
|
zend_class_entry *grpc_ce_channel; |
|
|
|
|
|
|
|
|
@ -224,6 +226,42 @@ PHP_METHOD(Channel, getConnectivityState) { |
|
|
|
|
(int)try_to_connect)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Watch the connectivity state of the channel until it changed |
|
|
|
|
* @param long The previous connectivity state of the channel |
|
|
|
|
* @param Timeval The deadline this function should wait until |
|
|
|
|
*/ |
|
|
|
|
PHP_METHOD(Channel, watchConnectivityState) { |
|
|
|
|
wrapped_grpc_channel *channel = |
|
|
|
|
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC); |
|
|
|
|
long last_state; |
|
|
|
|
zval *deadline_obj; |
|
|
|
|
/* "lO" == 1 long 1 object */ |
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lO", |
|
|
|
|
&last_state, &deadline_obj, grpc_ce_timeval) == FAILURE) { |
|
|
|
|
zend_throw_exception(spl_ce_InvalidArgumentException, |
|
|
|
|
"watchConnectivityState expects 1 long 1 timeval", |
|
|
|
|
1 TSRMLS_CC); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wrapped_grpc_timeval *deadline = |
|
|
|
|
(wrapped_grpc_timeval *)zend_object_store_get_object( |
|
|
|
|
deadline_obj TSRMLS_CC); |
|
|
|
|
grpc_channel_watch_connectivity_state( |
|
|
|
|
channel->wrapped, (grpc_connectivity_state)last_state, |
|
|
|
|
deadline->wrapped, completion_queue, NULL); |
|
|
|
|
grpc_event event = grpc_completion_queue_pluck( |
|
|
|
|
completion_queue, NULL, |
|
|
|
|
gpr_inf_future(GPR_CLOCK_REALTIME)); |
|
|
|
|
if (!event.success) { |
|
|
|
|
zend_throw_exception(spl_ce_LogicException, |
|
|
|
|
"watchConnectivityState failed", |
|
|
|
|
1 TSRMLS_CC); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Close the channel |
|
|
|
|
*/ |
|
|
|
@ -240,6 +278,7 @@ static zend_function_entry channel_methods[] = { |
|
|
|
|
PHP_ME(Channel, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) |
|
|
|
|
PHP_ME(Channel, getTarget, NULL, ZEND_ACC_PUBLIC) |
|
|
|
|
PHP_ME(Channel, getConnectivityState, NULL, ZEND_ACC_PUBLIC) |
|
|
|
|
PHP_ME(Channel, watchConnectivityState, NULL, ZEND_ACC_PUBLIC) |
|
|
|
|
PHP_ME(Channel, close, NULL, ZEND_ACC_PUBLIC) |
|
|
|
|
PHP_FE_END}; |
|
|
|
|
|
|
|
|
|