Merge pull request #1134 from murgatroid99/php_interop_ssl_fix

Fix PHP interop test failures
pull/1137/head
Tim Emiola 10 years ago
commit 66990377f8
  1. 5
      src/php/ext/grpc/byte_buffer.c
  2. 21
      src/php/ext/grpc/call.c
  3. 8
      src/php/lib/Grpc/ActiveCall.php
  4. 7
      src/php/tests/interop/interop_client.php

@ -57,6 +57,11 @@ grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) {
void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string, void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,
size_t *out_length) { size_t *out_length) {
if (buffer == NULL) {
*out_string = NULL;
*out_length = 0;
return;
}
size_t length = grpc_byte_buffer_length(buffer); size_t length = grpc_byte_buffer_length(buffer);
char *string = ecalloc(length + 1, sizeof(char)); char *string = ecalloc(length + 1, sizeof(char));
size_t offset = 0; size_t offset = 0;

@ -448,8 +448,12 @@ PHP_METHOD(Call, start_batch) {
break; break;
case GRPC_OP_RECV_MESSAGE: case GRPC_OP_RECV_MESSAGE:
byte_buffer_to_string(message, &message_str, &message_len); byte_buffer_to_string(message, &message_str, &message_len);
add_property_stringl(result, "message", message_str, message_len, if (message_str == NULL) {
false); add_property_null(result, "message");
} else {
add_property_stringl(result, "message", message_str, message_len,
false);
}
break; break;
case GRPC_OP_RECV_STATUS_ON_CLIENT: case GRPC_OP_RECV_STATUS_ON_CLIENT:
MAKE_STD_ZVAL(recv_status); MAKE_STD_ZVAL(recv_status);
@ -478,9 +482,20 @@ cleanup:
RETURN_DESTROY_ZVAL(result); RETURN_DESTROY_ZVAL(result);
} }
/**
* Cancel the call. This will cause the call to end with STATUS_CANCELLED if it
* has not already ended with another status.
*/
PHP_METHOD(Call, cancel) {
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
grpc_call_cancel(call->wrapped);
}
static zend_function_entry call_methods[] = { static zend_function_entry call_methods[] = {
PHP_ME(Call, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) PHP_ME(Call, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Call, start_batch, NULL, ZEND_ACC_PUBLIC) PHP_FE_END}; PHP_ME(Call, start_batch, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, cancel, NULL, ZEND_ACC_PUBLIC) PHP_FE_END};
void grpc_init_call(TSRMLS_D) { void grpc_init_call(TSRMLS_D) {
zend_class_entry ce; zend_class_entry ce;

@ -77,7 +77,7 @@ class ActiveCall {
*/ */
public function read() { public function read() {
$read_event = $this->call->start_batch([OP_RECV_MESSAGE => true]); $read_event = $this->call->start_batch([OP_RECV_MESSAGE => true]);
return $read_event->data; return $read_event->message;
} }
/** /**
@ -102,7 +102,9 @@ class ActiveCall {
* and array $metadata members * and array $metadata members
*/ */
public function getStatus() { public function getStatus() {
$status_event = $this->call->start_batch([RECV_STATUS_ON_CLIENT => true]); $status_event = $this->call->start_batch([
return $status_event->data; OP_RECV_STATUS_ON_CLIENT => true
]);
return $status_event->status;
} }
} }

@ -132,8 +132,6 @@ function serverStreaming($stub) {
} }
$call = $stub->StreamingOutputCall($request); $call = $stub->StreamingOutputCall($request);
hardAssert($call->getStatus()->code === Grpc\STATUS_OK,
'Call did not complete successfully');
$i = 0; $i = 0;
foreach($call->responses() as $value) { foreach($call->responses() as $value) {
hardAssert($i < 4, 'Too many responses'); hardAssert($i < 4, 'Too many responses');
@ -142,7 +140,10 @@ function serverStreaming($stub) {
'Payload ' . $i . ' had the wrong type'); 'Payload ' . $i . ' had the wrong type');
hardAssert(strlen($payload->getBody()) === $sizes[$i], hardAssert(strlen($payload->getBody()) === $sizes[$i],
'Response ' . $i . ' had the wrong length'); 'Response ' . $i . ' had the wrong length');
$i += 1;
} }
hardAssert($call->getStatus()->code === Grpc\STATUS_OK,
'Call did not complete successfully');
} }
/** /**
@ -240,4 +241,6 @@ switch($args['test_case']) {
break; break;
case 'cancel_after_first_response': case 'cancel_after_first_response':
cancelAfterFirstResponse($stub); cancelAfterFirstResponse($stub);
default:
exit(1);
} }

Loading…
Cancel
Save