|
|
|
@ -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; |
|
|
|
|
|
|
|
|
@ -204,6 +206,59 @@ PHP_METHOD(Channel, getTarget) { |
|
|
|
|
RETURN_STRING(grpc_channel_get_target(channel->wrapped), 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the connectivity state of the channel |
|
|
|
|
* @param bool (optional) try to connect on the channel |
|
|
|
|
* @return long The grpc connectivity state |
|
|
|
|
*/ |
|
|
|
|
PHP_METHOD(Channel, getConnectivityState) { |
|
|
|
|
wrapped_grpc_channel *channel = |
|
|
|
|
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC); |
|
|
|
|
bool try_to_connect; |
|
|
|
|
/* "|b" == 1 optional bool */ |
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &try_to_connect) == |
|
|
|
|
FAILURE) { |
|
|
|
|
zend_throw_exception(spl_ce_InvalidArgumentException, |
|
|
|
|
"getConnectivityState expects a bool", 1 TSRMLS_CC); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
RETURN_LONG(grpc_channel_check_connectivity_state(channel->wrapped, |
|
|
|
|
(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 |
|
|
|
|
* @return bool If the connectivity state changes from last_state |
|
|
|
|
* before deadline |
|
|
|
|
*/ |
|
|
|
|
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)); |
|
|
|
|
RETURN_BOOL(event.success); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Close the channel |
|
|
|
|
*/ |
|
|
|
@ -219,6 +274,8 @@ PHP_METHOD(Channel, close) { |
|
|
|
|
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}; |
|
|
|
|
|
|
|
|
|