aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/ext
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2015-08-10 15:46:42 -0700
committerGravatar Stanley Cheung <stanleycheung@google.com>2015-08-13 10:48:32 -0700
commite63354a6e71427b273182455b052ffb606e0eadc (patch)
treec9de491f16a00daad2757f4e9630d775171bbc9f /src/php/ext
parent35ea361ff5042bc31acd476a9ca6f9d22bf6a1c6 (diff)
php: wrap getConnectivityState API
Diffstat (limited to 'src/php/ext')
-rw-r--r--src/php/ext/grpc/channel.c21
-rw-r--r--src/php/ext/grpc/php_grpc.c12
2 files changed, 33 insertions, 0 deletions
diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c
index 7d8a6f87ab..8a3fe11412 100644
--- a/src/php/ext/grpc/channel.c
+++ b/src/php/ext/grpc/channel.c
@@ -205,6 +205,26 @@ PHP_METHOD(Channel, getTarget) {
}
/**
+ * 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));
+}
+
+/**
* Close the channel
*/
PHP_METHOD(Channel, close) {
@@ -219,6 +239,7 @@ 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, close, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END};
diff --git a/src/php/ext/grpc/php_grpc.c b/src/php/ext/grpc/php_grpc.c
index fedcf0f539..0f730ea756 100644
--- a/src/php/ext/grpc/php_grpc.c
+++ b/src/php/ext/grpc/php_grpc.c
@@ -183,6 +183,18 @@ PHP_MINIT_FUNCTION(grpc) {
REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_CLOSE_ON_SERVER",
GRPC_OP_RECV_CLOSE_ON_SERVER, CONST_CS);
+ /* Register connectivity state constants */
+ REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_IDLE",
+ GRPC_CHANNEL_IDLE, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_CONNECTING",
+ GRPC_CHANNEL_CONNECTING, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_READY",
+ GRPC_CHANNEL_READY, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_TRANSIENT_FAILURE",
+ GRPC_CHANNEL_TRANSIENT_FAILURE, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\CHANNEL_FATAL_FAILURE",
+ GRPC_CHANNEL_FATAL_FAILURE, CONST_CS);
+
grpc_init_call(TSRMLS_C);
grpc_init_channel(TSRMLS_C);
grpc_init_server(TSRMLS_C);