diff options
Diffstat (limited to 'src/php/ext/grpc/call.c')
-rw-r--r-- | src/php/ext/grpc/call.c | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index b802f04f53..a794226298 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -18,34 +18,19 @@ #include "call.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <php.h> -#include <php_ini.h> -#include <ext/standard/info.h> #include <ext/spl/spl_exceptions.h> -#include "php_grpc.h" -#include "call_credentials.h" - #include <zend_exceptions.h> -#include <zend_hash.h> - -#include <stdbool.h> #include <grpc/support/alloc.h> -#include <grpc/grpc.h> +#include "call_credentials.h" #include "completion_queue.h" #include "timeval.h" #include "channel.h" #include "byte_buffer.h" zend_class_entry *grpc_ce_call; -#if PHP_MAJOR_VERSION >= 7 -static zend_object_handlers call_ce_handlers; -#endif +PHP_GRPC_DECLARE_OBJECT_HANDLER(call_ce_handlers) /* Frees and destroys an instance of wrapped_grpc_call */ PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_call) @@ -195,7 +180,8 @@ zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) { zval *call_object; PHP_GRPC_MAKE_STD_ZVAL(call_object); object_init_ex(call_object, grpc_ce_call); - wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(call_object); + wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call, + call_object); call->wrapped = wrapped; call->owned = owned; return call_object; @@ -216,7 +202,8 @@ PHP_METHOD(Call, __construct) { zval *deadline_obj; char *host_override = NULL; php_grpc_int host_override_len = 0; - wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); + wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call, + getThis()); /* "OsO|s" == 1 Object, 1 string, 1 Object, 1 optional string */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OsO|s", &channel_obj, @@ -228,9 +215,10 @@ PHP_METHOD(Call, __construct) { "an optional String", 1 TSRMLS_CC); return; } - wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(channel_obj); + wrapped_grpc_channel *channel = + PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_channel, channel_obj); gpr_mu_lock(&channel->wrapper->mu); - if (channel->wrapper->wrapped == NULL) { + if (channel->wrapper == NULL || channel->wrapper->wrapped == NULL) { zend_throw_exception(spl_ce_InvalidArgumentException, "Call cannot be constructed from a closed Channel", 1 TSRMLS_CC); @@ -238,7 +226,8 @@ PHP_METHOD(Call, __construct) { return; } add_property_zval(getThis(), "channel", channel_obj); - wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj); + wrapped_grpc_timeval *deadline = + PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_timeval, deadline_obj); grpc_slice method_slice = grpc_slice_from_copied_string(method); grpc_slice host_slice = host_override != NULL ? grpc_slice_from_copied_string(host_override) : grpc_empty_slice(); @@ -251,6 +240,7 @@ PHP_METHOD(Call, __construct) { grpc_slice_unref(method_slice); grpc_slice_unref(host_slice); call->owned = true; + call->channel = channel; gpr_mu_unlock(&channel->wrapper->mu); } @@ -269,7 +259,17 @@ PHP_METHOD(Call, startBatch) { zval *inner_value; zval *message_value; zval *message_flags; - wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); + wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call, + getThis()); + if (call->channel) { + // startBatch in gRPC PHP server doesn't have channel in it. + if (call->channel->wrapper == NULL || + call->channel->wrapper->wrapped == NULL) { + zend_throw_exception(spl_ce_RuntimeException, + "startBatch Error. Channel is closed", + 1 TSRMLS_CC); + } + } grpc_op ops[8]; size_t op_num = 0; @@ -542,7 +542,8 @@ cleanup: * @return string The URI of the endpoint */ PHP_METHOD(Call, getPeer) { - wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); + wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call, + getThis()); char *peer = grpc_call_get_peer(call->wrapped); PHP_GRPC_RETVAL_STRING(peer, 1); gpr_free(peer); @@ -554,7 +555,8 @@ PHP_METHOD(Call, getPeer) { * @return void */ PHP_METHOD(Call, cancel) { - wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); + wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call, + getThis()); grpc_call_cancel(call->wrapped, NULL); } @@ -576,8 +578,9 @@ PHP_METHOD(Call, setCredentials) { } wrapped_grpc_call_credentials *creds = - Z_WRAPPED_GRPC_CALL_CREDS_P(creds_obj); - wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis()); + PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call_credentials, creds_obj); + wrapped_grpc_call *call = PHP_GRPC_GET_WRAPPED_OBJECT(wrapped_grpc_call, + getThis()); grpc_call_error error = GRPC_CALL_ERROR; error = grpc_call_set_credentials(call->wrapped, creds->wrapped); |