aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xsrc/php/ext/grpc/call.c111
-rwxr-xr-xsrc/php/ext/grpc/call.h14
-rwxr-xr-xsrc/php/ext/grpc/completion_queue.c4
-rwxr-xr-xsrc/php/ext/grpc/event.c174
-rwxr-xr-xsrc/php/ext/grpc/event.h15
-rwxr-xr-xsrc/php/ext/grpc/php_grpc.c1
-rwxr-xr-xsrc/php/ext/grpc/server.c4
-rwxr-xr-xsrc/php/lib/Grpc/AbstractSurfaceActiveCall.php64
-rwxr-xr-xsrc/php/lib/Grpc/ActiveCall.php7
-rwxr-xr-xsrc/php/lib/Grpc/BaseStub.php2
-rwxr-xr-xsrc/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php43
-rwxr-xr-xsrc/php/lib/Grpc/ClientStreamingSurfaceActiveCall.php39
-rwxr-xr-xsrc/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php42
-rwxr-xr-xsrc/php/lib/Grpc/SimpleSurfaceActiveCall.php39
-rwxr-xr-xsrc/php/lib/Grpc/SurfaceActiveCall.php211
-rwxr-xr-xsrc/php/lib/autoload.php21
-rwxr-xr-xsrc/php/tests/generated_code/GeneratedCodeTest.php4
-rwxr-xr-xsrc/php/tests/interop/interop_client.php4
-rwxr-xr-xsrc/php/tests/unit_tests/CallTest.php19
-rwxr-xr-xsrc/php/tests/unit_tests/EndToEndTest.php85
-rwxr-xr-xsrc/php/tests/unit_tests/SecureEndToEndTest.php84
-rw-r--r--test/core/echo/echo_test.c4
-rw-r--r--test/core/fling/fling_stream_test.c4
-rw-r--r--test/core/fling/fling_test.c4
-rw-r--r--test/core/util/test_config.c9
25 files changed, 534 insertions, 474 deletions
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c
index cc87e214c9..7f4f221caa 100755
--- a/src/php/ext/grpc/call.c
+++ b/src/php/ext/grpc/call.c
@@ -26,7 +26,7 @@
/* Frees and destroys an instance of wrapped_grpc_call */
void free_wrapped_grpc_call(void *object TSRMLS_DC){
wrapped_grpc_call *call = (wrapped_grpc_call*)object;
- if(call->wrapped != NULL){
+ if(call->owned && call->wrapped != NULL){
grpc_call_destroy(call->wrapped);
}
efree(call);
@@ -53,7 +53,9 @@ zend_object_value create_wrapped_grpc_call(
return retval;
}
-zval *grpc_php_wrap_call(grpc_call *wrapped){
+/* Wraps a grpc_call struct in a PHP object. Owned indicates whether the struct
+ should be destroyed at the end of the object's lifecycle */
+zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned){
zval *call_object;
MAKE_STD_ZVAL(call_object);
object_init_ex(call_object, grpc_ce_call);
@@ -124,6 +126,7 @@ int php_grpc_call_add_metadata_array_walk(void *elem TSRMLS_DC,
int num_args,
va_list args,
zend_hash_key *hash_key){
+ grpc_call_error error_code;
zval **data = (zval**)elem;
grpc_metadata metadata;
grpc_call *call = va_arg(args, grpc_call*);
@@ -144,7 +147,8 @@ int php_grpc_call_add_metadata_array_walk(void *elem TSRMLS_DC,
metadata.key = (char*)key;
metadata.value = Z_STRVAL_P(*data);
metadata.value_length = Z_STRLEN_P(*data);
- grpc_call_add_metadata(call, &metadata, 0u);
+ error_code = grpc_call_add_metadata(call, &metadata, 0u);
+ MAYBE_THROW_CALL_ERROR(add_metadata, error_code);
break;
case IS_ARRAY:
inner_hash = Z_ARRVAL_P(*data);
@@ -246,9 +250,10 @@ PHP_METHOD(Call, add_metadata){
* @param long $finished_tag The tag to associate with the finished event
* @param long $flags A bitwise combination of the Grpc\WRITE_* constants
* (optional)
- * @return long Error code
+ * @return Void
*/
PHP_METHOD(Call, start_invoke){
+ grpc_call_error error_code;
long tag1;
long tag2;
long tag3;
@@ -274,12 +279,13 @@ PHP_METHOD(Call, start_invoke){
wrapped_grpc_completion_queue *queue =
(wrapped_grpc_completion_queue*)zend_object_store_get_object(
queue_obj TSRMLS_CC);
- RETURN_LONG(grpc_call_start_invoke(call->wrapped,
- queue->wrapped,
- (void*)tag1,
- (void*)tag2,
- (void*)tag3,
- (gpr_uint32)flags));
+ error_code = grpc_call_start_invoke(call->wrapped,
+ queue->wrapped,
+ (void*)tag1,
+ (void*)tag2,
+ (void*)tag3,
+ (gpr_uint32)flags);
+ MAYBE_THROW_CALL_ERROR(start_invoke, error_code);
}
/**
@@ -290,21 +296,20 @@ PHP_METHOD(Call, start_invoke){
* @param long $finished_tag The tag to associate with the finished event
* @param long $flags A bitwise combination of the Grpc\WRITE_* constants
* (optional)
- * @return long Error code
+ * @return Void
*/
-PHP_METHOD(Call, accept){
+PHP_METHOD(Call, server_accept){
long tag;
zval *queue_obj;
- long flags = 0;
- /* "Ol|l" == 1 Object, 1 mandatory long, 1 optional long */
+ grpc_call_error error_code;
+ /* "Ol|l" == 1 Object, 1 long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
- "Ol|l",
+ "Ol",
&queue_obj, grpc_ce_completion_queue,
- &tag,
- &flags) == FAILURE){
+ &tag) == FAILURE){
zend_throw_exception(
spl_ce_InvalidArgumentException,
- "accept expects a CompletionQueue, a long, and an optional long",
+ "server_accept expects a CompletionQueue, a long, and an optional long",
1 TSRMLS_CC);
return;
}
@@ -314,20 +319,39 @@ PHP_METHOD(Call, accept){
wrapped_grpc_completion_queue *queue =
(wrapped_grpc_completion_queue*)zend_object_store_get_object(
queue_obj TSRMLS_CC);
- RETURN_LONG(grpc_call_accept(call->wrapped,
- queue->wrapped,
- (void*)tag,
- (gpr_uint32)flags));
+ error_code = grpc_call_server_accept(call->wrapped,
+ queue->wrapped,
+ (void*)tag);
+ MAYBE_THROW_CALL_ERROR(server_accept, error_code);
+}
+
+PHP_METHOD(Call, server_end_initial_metadata) {
+ grpc_call_error error_code;
+ long flags = 0;
+ /* "|l" == 1 optional long */
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ "|l",
+ &flags) == FAILURE) {
+ zend_throw_exception(
+ spl_ce_InvalidArgumentException,
+ "server_end_initial_metadata expects an optional long",
+ 1 TSRMLS_CC);
+ }
+ wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
+ getThis() TSRMLS_CC);
+ error_code = grpc_call_server_end_initial_metadata(call->wrapped, flags);
+ MAYBE_THROW_CALL_ERROR(server_end_initial_metadata, error_code);
}
/**
* Called by clients to cancel an RPC on the server.
- * @return long Error code
+ * @return Void
*/
PHP_METHOD(Call, cancel){
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
- RETURN_LONG(grpc_call_cancel(call->wrapped));
+ grpc_call_error error_code = grpc_call_cancel(call->wrapped);
+ MAYBE_THROW_CALL_ERROR(cancel, error_code);
}
/**
@@ -336,9 +360,10 @@ PHP_METHOD(Call, cancel){
* @param long $tag The tag to associate with this write
* @param long $flags A bitwise combination of the Grpc\WRITE_* constants
* (optional)
- * @return long Error code
+ * @return Void
*/
PHP_METHOD(Call, start_write){
+ grpc_call_error error_code;
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
char *buffer;
@@ -357,10 +382,11 @@ PHP_METHOD(Call, start_write){
1 TSRMLS_CC);
return;
}
- RETURN_LONG(grpc_call_start_write(call->wrapped,
- string_to_byte_buffer(buffer, buffer_len),
- (void*)tag,
- (gpr_uint32)flags));
+ error_code = grpc_call_start_write(call->wrapped,
+ string_to_byte_buffer(buffer, buffer_len),
+ (void*)tag,
+ (gpr_uint32)flags);
+ MAYBE_THROW_CALL_ERROR(start_write, error_code);
}
/**
@@ -368,9 +394,10 @@ PHP_METHOD(Call, start_write){
* @param long $status_code The status code to send
* @param string $status_details The status details to send
* @param long $tag The tag to associate with this status
- * @return long Error code
+ * @return Void
*/
PHP_METHOD(Call, start_write_status){
+ grpc_call_error error_code;
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
long status_code;
@@ -389,17 +416,19 @@ PHP_METHOD(Call, start_write_status){
1 TSRMLS_CC);
return;
}
- RETURN_LONG(grpc_call_start_write_status(call->wrapped,
- (grpc_status_code)status_code,
- status_details,
- (void*)tag));
+ error_code = grpc_call_start_write_status(call->wrapped,
+ (grpc_status_code)status_code,
+ status_details,
+ (void*)tag);
+ MAYBE_THROW_CALL_ERROR(start_write_status, error_code);
}
/**
* Indicate that there are no more messages to send
- * @return long Error code
+ * @return Void
*/
PHP_METHOD(Call, writes_done){
+ grpc_call_error error_code;
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
long tag;
@@ -410,16 +439,18 @@ PHP_METHOD(Call, writes_done){
1 TSRMLS_CC);
return;
}
- RETURN_LONG(grpc_call_writes_done(call->wrapped, (void*)tag));
+ error_code = grpc_call_writes_done(call->wrapped, (void*)tag);
+ MAYBE_THROW_CALL_ERROR(writes_done, error_code);
}
/**
* Initiate a read on a call. Output event contains a byte buffer with the
* result of the read
* @param long $tag The tag to associate with this read
- * @return long Error code
+ * @return Void
*/
PHP_METHOD(Call, start_read){
+ grpc_call_error error_code;
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
long tag;
@@ -430,12 +461,14 @@ PHP_METHOD(Call, start_read){
1 TSRMLS_CC);
return;
}
- RETURN_LONG(grpc_call_start_read(call->wrapped, (void*)tag));
+ error_code = grpc_call_start_read(call->wrapped, (void*)tag);
+ MAYBE_THROW_CALL_ERROR(start_read, error_code);
}
static zend_function_entry call_methods[] = {
PHP_ME(Call, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
- PHP_ME(Call, accept, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Call, server_accept, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Call, server_end_initial_metadata, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, add_metadata, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, cancel, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, start_invoke, NULL, ZEND_ACC_PUBLIC)
diff --git a/src/php/ext/grpc/call.h b/src/php/ext/grpc/call.h
index c433e6fee6..c3b18d66cb 100755
--- a/src/php/ext/grpc/call.h
+++ b/src/php/ext/grpc/call.h
@@ -12,6 +12,17 @@
#include "grpc/grpc.h"
+// Throw an exception if error_code is not OK
+#define MAYBE_THROW_CALL_ERROR(func_name, error_code) \
+ do{ \
+ if(error_code != GRPC_CALL_OK) { \
+ zend_throw_exception(spl_ce_LogicException, \
+ #func_name " was called incorrectly", \
+ (long)error_code TSRMLS_CC); \
+ } \
+ } while(0)
+
+
/* Class entry for the Call PHP class */
zend_class_entry *grpc_ce_call;
@@ -19,6 +30,7 @@ zend_class_entry *grpc_ce_call;
typedef struct wrapped_grpc_call {
zend_object std;
+ bool owned;
grpc_call *wrapped;
} wrapped_grpc_call;
@@ -26,7 +38,7 @@ typedef struct wrapped_grpc_call {
void grpc_init_call(TSRMLS_D);
/* Creates a Call object that wraps the given grpc_call struct */
-zval *grpc_php_wrap_call(grpc_call *wrapped);
+zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned);
/* Creates and returns a PHP associative array of metadata from a C array of
* call metadata */
diff --git a/src/php/ext/grpc/completion_queue.c b/src/php/ext/grpc/completion_queue.c
index 5b7bcfa976..0570bd5029 100755
--- a/src/php/ext/grpc/completion_queue.c
+++ b/src/php/ext/grpc/completion_queue.c
@@ -99,7 +99,7 @@ PHP_METHOD(CompletionQueue, next){
if(event == NULL){
RETURN_NULL();
}
- zval *wrapped_event = grpc_php_wrap_event(event);
+ zval *wrapped_event = grpc_php_convert_event(event);
RETURN_DESTROY_ZVAL(wrapped_event);
}
@@ -126,7 +126,7 @@ PHP_METHOD(CompletionQueue, pluck){
if(event == NULL){
RETURN_NULL();
}
- zval *wrapped_event = grpc_php_wrap_event(event);
+ zval *wrapped_event = grpc_php_convert_event(event);
RETURN_DESTROY_ZVAL(wrapped_event);
}
diff --git a/src/php/ext/grpc/event.c b/src/php/ext/grpc/event.c
index 23ce2c8343..c15f479448 100755
--- a/src/php/ext/grpc/event.c
+++ b/src/php/ext/grpc/event.c
@@ -17,86 +17,10 @@
#include "call.h"
#include "timeval.h"
-/* Frees and finishes a wrapped instance of grpc_event */
-void free_wrapped_grpc_event(void *object TSRMLS_DC){
- wrapped_grpc_event *event = (wrapped_grpc_event*)object;
- if(event->wrapped != NULL){
- grpc_event_finish(event->wrapped);
- }
- efree(event);
-}
-
-/* Initializes an instance of wrapped_grpc_channel to be associated with an
- * object of a class specified by class_type */
-zend_object_value create_wrapped_grpc_event(
- zend_class_entry *class_type TSRMLS_DC){
- zend_object_value retval;
- wrapped_grpc_event *intern;
- intern = (wrapped_grpc_event*)emalloc(sizeof(wrapped_grpc_event));
- memset(intern, 0, sizeof(wrapped_grpc_event));
- zend_object_std_init(&intern->std, class_type TSRMLS_CC);
- object_properties_init(&intern->std, class_type);
- retval.handle = zend_objects_store_put(
- intern,
- (zend_objects_store_dtor_t)zend_objects_destroy_object,
- free_wrapped_grpc_event,
- NULL TSRMLS_CC);
- retval.handlers = zend_get_std_object_handlers();
- return retval;
-}
-
-zval *grpc_php_wrap_event(grpc_event *wrapped){
- zval *event_object;
- MAKE_STD_ZVAL(event_object);
-
- object_init_ex(event_object, grpc_ce_event);
- wrapped_grpc_event *event = (wrapped_grpc_event*)zend_object_store_get_object(
- event_object TSRMLS_CC);
- event->wrapped = wrapped;
- return event_object;
-}
-
-/**
- * Get the type of the event
- * @return long Integer representing the type
- */
-PHP_METHOD(Event, get_type){
- wrapped_grpc_event *event = (wrapped_grpc_event*)zend_object_store_get_object(
- getThis() TSRMLS_CC);
- RETURN_LONG((long)(event->wrapped->type));
-}
-
-/**
- * Get the tag of the event
- * @return long The event's tag
- */
-PHP_METHOD(Event, get_tag){
- wrapped_grpc_event *event = (wrapped_grpc_event*)zend_object_store_get_object(
- getThis() TSRMLS_CC);
- RETURN_LONG((long)(event->wrapped->tag));
-}
-
-/**
- * Get the call associated with the event
- * @return Call The call
- */
-PHP_METHOD(Event, get_call){
- wrapped_grpc_event *event = (wrapped_grpc_event*)zend_object_store_get_object(
- getThis() TSRMLS_CC);
- zval *call_obj = grpc_php_wrap_call(event->wrapped->call);
- RETURN_DESTROY_ZVAL(call_obj);
-}
-
-/**
- * Get the data associated with the event
- * @return object The data, with type depending on the type field
- */
-PHP_METHOD(Event, get_data){
- zval *retval;
- wrapped_grpc_event *wrapped_event =
- (wrapped_grpc_event*)zend_object_store_get_object(
- getThis() TSRMLS_CC);
- grpc_event *event = wrapped_event->wrapped;
+/* Create a new PHP object containing the event data in the event struct.
+ event must not be used after this function is called */
+zval *grpc_php_convert_event(grpc_event *event) {
+ zval *data_object;
char *detail_string;
size_t detail_len;
char *method_string;
@@ -106,89 +30,103 @@ PHP_METHOD(Event, get_data){
char *read_string;
size_t read_len;
+ zval *event_object;
+
+ if(event == NULL) {
+ return NULL;
+ }
+
+ MAKE_STD_ZVAL(event_object);
+ object_init(event_object);
+
+ add_property_zval(event_object,
+ "call",
+ grpc_php_wrap_call(event->call,
+ event->type==GRPC_SERVER_RPC_NEW));
+ add_property_long(event_object, "type", event->type);
+ add_property_long(event_object, "tag", (long)event->tag);
+
switch(event->type){
- case GRPC_QUEUE_SHUTDOWN: RETURN_NULL(); break;
+ case GRPC_QUEUE_SHUTDOWN: add_property_null(event_object, "data"); break;
case GRPC_READ:
if(event->data.read == NULL){
- RETURN_NULL();
+ add_property_null(event_object, "data");
} else {
byte_buffer_to_string(event->data.read, &read_string, &read_len);
- RETURN_STRINGL(read_string, read_len, true);
+ add_property_stringl(event_object, "data", read_string, read_len, true);
}
break;
case GRPC_INVOKE_ACCEPTED:
- RETURN_LONG((long)event->data.invoke_accepted); break;
+ add_property_long(event_object,
+ "data",
+ (long)event->data.invoke_accepted);
+ break;
case GRPC_WRITE_ACCEPTED:
- RETURN_LONG((long)event->data.write_accepted); break;
+ add_property_long(event_object, "data", (long)event->data.write_accepted);
+ break;
case GRPC_FINISH_ACCEPTED:
- RETURN_LONG((long)event->data.finish_accepted); break;
+ add_property_long(event_object,
+ "data",
+ (long)event->data.finish_accepted);
+ break;
case GRPC_CLIENT_METADATA_READ:
- retval = grpc_call_create_metadata_array(
+ data_object = grpc_call_create_metadata_array(
event->data.client_metadata_read.count,
event->data.client_metadata_read.elements);
+ add_property_zval(event_object, "data", data_object);
break;
case GRPC_FINISHED:
- MAKE_STD_ZVAL(retval);
- object_init(retval);
- add_property_long(retval, "code", event->data.finished.status);
+ MAKE_STD_ZVAL(data_object);
+ object_init(data_object);
+ add_property_long(data_object, "code", event->data.finished.status);
if(event->data.finished.details == NULL){
- add_property_null(retval, "details");
+ add_property_null(data_object, "details");
} else {
detail_len = strlen(event->data.finished.details);
detail_string = ecalloc(detail_len+1, sizeof(char));
memcpy(detail_string, event->data.finished.details, detail_len);
- add_property_string(retval,
+ add_property_string(data_object,
"details",
detail_string,
true);
}
- add_property_zval(retval, "metadata", grpc_call_create_metadata_array(
- event->data.finished.metadata_count,
- event->data.finished.metadata_elements));
+ add_property_zval(data_object,
+ "metadata",
+ grpc_call_create_metadata_array(
+ event->data.finished.metadata_count,
+ event->data.finished.metadata_elements));
+ add_property_zval(event_object, "data", data_object);
break;
case GRPC_SERVER_RPC_NEW:
- MAKE_STD_ZVAL(retval);
- object_init(retval);
+ MAKE_STD_ZVAL(data_object);
+ object_init(data_object);
method_len = strlen(event->data.server_rpc_new.method);
method_string = ecalloc(method_len+1, sizeof(char));
memcpy(method_string, event->data.server_rpc_new.method, method_len);
- add_property_string(retval,
+ add_property_string(data_object,
"method",
method_string,
false);
host_len = strlen(event->data.server_rpc_new.host);
host_string = ecalloc(host_len+1, sizeof(char));
memcpy(host_string, event->data.server_rpc_new.host, host_len);
- add_property_string(retval,
+ add_property_string(data_object,
"host",
host_string,
false);
- add_property_zval(retval,
+ add_property_zval(data_object,
"absolute_timeout",
grpc_php_wrap_timeval(
event->data.server_rpc_new.deadline));
- add_property_zval(retval,
+ add_property_zval(data_object,
"metadata",
grpc_call_create_metadata_array(
event->data.server_rpc_new.metadata_count,
event->data.server_rpc_new.metadata_elements));
+ add_property_zval(event_object, "data", data_object);
break;
- default: RETURN_NULL(); break;
+ default: add_property_null(event_object, "data"); break;
}
- RETURN_DESTROY_ZVAL(retval);
-}
-
-static zend_function_entry event_methods[] = {
- PHP_ME(Event, get_call, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Event, get_data, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Event, get_tag, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Event, get_type, NULL, ZEND_ACC_PUBLIC)
- PHP_FE_END
-};
-
-void grpc_init_event(TSRMLS_D){
- zend_class_entry ce;
- INIT_CLASS_ENTRY(ce, "Grpc\\Event", event_methods);
- ce.create_object = create_wrapped_grpc_event;
- grpc_ce_event = zend_register_internal_class(&ce TSRMLS_CC);
+ grpc_event_finish(event);
+ return event_object;
}
diff --git a/src/php/ext/grpc/event.h b/src/php/ext/grpc/event.h
index 9dc164e249..f00c1cc902 100755
--- a/src/php/ext/grpc/event.h
+++ b/src/php/ext/grpc/event.h
@@ -12,20 +12,7 @@
#include "grpc/grpc.h"
-/* Class entry for the PHP Event class */
-zend_class_entry *grpc_ce_event;
-
-/* Struct wrapping grpc_event that can be associated with a PHP object */
-typedef struct wrapped_grpc_event {
- zend_object std;
-
- grpc_event *wrapped;
-} wrapped_grpc_event;
-
-/* Initialize the Event class */
-void grpc_init_event(TSRMLS_D);
-
/* Create a new Event object that wraps an existing grpc_event struct */
-zval *grpc_php_wrap_event(grpc_event *wrapped);
+zval *grpc_php_convert_event(grpc_event *event);
#endif /* NET_GRPC_PHP_GRPC_COMPLETION_CHANNEL_H */
diff --git a/src/php/ext/grpc/php_grpc.c b/src/php/ext/grpc/php_grpc.c
index c49b84542c..71449bfd06 100755
--- a/src/php/ext/grpc/php_grpc.c
+++ b/src/php/ext/grpc/php_grpc.c
@@ -196,7 +196,6 @@ PHP_MINIT_FUNCTION(grpc)
grpc_init_channel(TSRMLS_C);
grpc_init_server(TSRMLS_C);
grpc_init_completion_queue(TSRMLS_C);
- grpc_init_event(TSRMLS_C);
grpc_init_timeval(TSRMLS_C);
grpc_init_credentials(TSRMLS_C);
grpc_init_server_credentials(TSRMLS_C);
diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c
index 7e98713bd5..5af42f76ee 100755
--- a/src/php/ext/grpc/server.c
+++ b/src/php/ext/grpc/server.c
@@ -121,6 +121,7 @@ PHP_METHOD(Server, __construct){
* @return Void
*/
PHP_METHOD(Server, request_call){
+ grpc_call_error error_code;
wrapped_grpc_server *server =
(wrapped_grpc_server*)zend_object_store_get_object(getThis() TSRMLS_CC);
long tag_new;
@@ -133,7 +134,8 @@ PHP_METHOD(Server, request_call){
1 TSRMLS_CC);
return;
}
- grpc_server_request_call(server->wrapped, (void*)tag_new);
+ error_code = grpc_server_request_call(server->wrapped, (void*)tag_new);
+ MAYBE_THROW_CALL_ERROR(request_call, error_code);
}
/**
diff --git a/src/php/lib/Grpc/AbstractSurfaceActiveCall.php b/src/php/lib/Grpc/AbstractSurfaceActiveCall.php
new file mode 100755
index 0000000000..53c7d4cd1a
--- /dev/null
+++ b/src/php/lib/Grpc/AbstractSurfaceActiveCall.php
@@ -0,0 +1,64 @@
+<?php
+namespace Grpc;
+
+require_once realpath(dirname(__FILE__) . '/../autoload.php');
+
+/**
+ * Represents an active call that allows sending and recieving messages.
+ * Subclasses restrict how data can be sent and recieved.
+ */
+abstract class AbstractSurfaceActiveCall {
+ private $active_call;
+ private $deserialize;
+
+ /**
+ * Create a new surface active call.
+ * @param Channel $channel The channel to communicate on
+ * @param string $method The method to call on the remote server
+ * @param callable $deserialize The function to deserialize a value
+ * @param array $metadata Metadata to send with the call, if applicable
+ * @param long $flags Write flags to use with this call
+ */
+ public function __construct(Channel $channel,
+ $method,
+ callable $deserialize,
+ $metadata = array(),
+ $flags = 0) {
+ $this->active_call = new ActiveCall($channel, $method, $metadata, $flags);
+ $this->deserialize = $deserialize;
+ }
+
+ /**
+ * @return The metadata sent by the server
+ */
+ public function getMetadata() {
+ return $this->metadata();
+ }
+
+ /**
+ * Cancels the call
+ */
+ public function cancel() {
+ $this->active_call->cancel();
+ }
+
+ protected function _read() {
+ $response = $this->active_call->read();
+ if ($response == null) {
+ return null;
+ }
+ return call_user_func($this->deserialize, $response);
+ }
+
+ protected function _write($value) {
+ return $this->active_call->write($value->serialize());
+ }
+
+ protected function _writesDone() {
+ $this->active_call->writesDone();
+ }
+
+ protected function _getStatus() {
+ return $this->active_call->getStatus();
+ }
+} \ No newline at end of file
diff --git a/src/php/lib/Grpc/ActiveCall.php b/src/php/lib/Grpc/ActiveCall.php
index 63877e3f6b..aa66dbb848 100755
--- a/src/php/lib/Grpc/ActiveCall.php
+++ b/src/php/lib/Grpc/ActiveCall.php
@@ -1,5 +1,6 @@
<?php
namespace Grpc;
+require_once realpath(dirname(__FILE__) . '/../autoload.php');
/**
* Represents an active call that allows sending and recieving binary data
@@ -35,7 +36,7 @@ class ActiveCall {
Timeval::inf_future());
$metadata_event = $this->completion_queue->pluck(CLIENT_METADATA_READ,
Timeval::inf_future());
- $this->metadata = $metadata_event->get_data();
+ $this->metadata = $metadata_event->data;
}
/**
@@ -59,7 +60,7 @@ class ActiveCall {
public function read() {
$this->call->start_read(READ);
$read_event = $this->completion_queue->pluck(READ, Timeval::inf_future());
- return $read_event->get_data();
+ return $read_event->data;
}
/**
@@ -93,6 +94,6 @@ class ActiveCall {
public function getStatus() {
$status_event = $this->completion_queue->pluck(FINISHED,
Timeval::inf_future());
- return $status_event->get_data();
+ return $status_event->data;
}
} \ No newline at end of file
diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php
index 7aa0c4ac4d..e1feb1206b 100755
--- a/src/php/lib/Grpc/BaseStub.php
+++ b/src/php/lib/Grpc/BaseStub.php
@@ -1,6 +1,6 @@
<?php
-
namespace Grpc;
+require_once realpath(dirname(__FILE__) . '/../autoload.php');
/**
* Base class for generated client stubs. Stub methods are expected to call
diff --git a/src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php b/src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php
new file mode 100755
index 0000000000..b5d557e02d
--- /dev/null
+++ b/src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php
@@ -0,0 +1,43 @@
+<?php
+namespace Grpc;
+require_once realpath(dirname(__FILE__) . '/../autoload.php');
+
+/**
+ * Represents an active call that allows for sending and recieving messages in
+ * streams in any order.
+ */
+class BidiStreamingSurfaceActiveCall extends AbstractSurfaceActiveCall {
+
+ /**
+ * Reads the next value from the server.
+ * @return The next value from the server, or null if there is none
+ */
+ public function read() {
+ return $this->_read();
+ }
+
+ /**
+ * Writes a single message to the server. This cannot be called after
+ * writesDone is called.
+ * @param $value The message to send
+ */
+ public function write($value) {
+ $this->_write($value);
+ }
+
+ /**
+ * Indicate that no more writes will be sent
+ */
+ public function writesDone() {
+ $this->_writesDone();
+ }
+
+ /**
+ * Wait for the server to send the status, and return it.
+ * @return object The status object, with integer $code and string $details
+ * members
+ */
+ public function getStatus() {
+ return $this->_getStatus();
+ }
+} \ No newline at end of file
diff --git a/src/php/lib/Grpc/ClientStreamingSurfaceActiveCall.php b/src/php/lib/Grpc/ClientStreamingSurfaceActiveCall.php
new file mode 100755
index 0000000000..fa643e50a8
--- /dev/null
+++ b/src/php/lib/Grpc/ClientStreamingSurfaceActiveCall.php
@@ -0,0 +1,39 @@
+<?php
+namespace Grpc;
+require_once realpath(dirname(__FILE__) . '/../autoload.php');
+
+/**
+ * Represents an active call that sends a stream of messages and then gets a
+ * single response.
+ */
+class ClientStreamingSurfaceActiveCall extends AbstractSurfaceActiveCall {
+ /**
+ * Create a new simple (single request/single response) active call.
+ * @param Channel $channel The channel to communicate on
+ * @param string $method The method to call on the remote server
+ * @param callable $deserialize The function to deserialize a value
+ * @param Traversable $arg_iter The iterator of arguments to send
+ * @param array $metadata Metadata to send with the call, if applicable
+ */
+ public function __construct(Channel $channel,
+ $method,
+ callable $deserialize,
+ $arg_iter,
+ $metadata = array()) {
+ parent::__construct($channel, $method, $deserialize, $metadata, 0);
+ foreach($arg_iter as $arg) {
+ $this->_write($arg);
+ }
+ $this->_writesDone();
+ }
+
+ /**
+ * Wait for the server to respond with data and a status
+ * @return [response data, status]
+ */
+ public function wait() {
+ $response = $this->_read();
+ $status = $this->_getStatus();
+ return array($response, $status);
+ }
+}
diff --git a/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php b/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php
new file mode 100755
index 0000000000..082f995d8a
--- /dev/null
+++ b/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php
@@ -0,0 +1,42 @@
+<?php
+namespace Grpc;
+
+require_once realpath(dirname(__FILE__) . '/../autoload.php');
+
+/**
+ * Represents an active call that sends a single message and then gets a stream
+ * of reponses
+ */
+class ServerStreamingSurfaceActiveCall extends AbstractSurfaceActiveCall {
+ /**
+ * Create a new simple (single request/single response) active call.
+ * @param Channel $channel The channel to communicate on
+ * @param string $method The method to call on the remote server
+ * @param callable $deserialize The function to deserialize a value
+ * @param $arg The argument to send
+ * @param array $metadata Metadata to send with the call, if applicable
+ */
+ public function __construct(Channel $channel,
+ $method,
+ callable $deserialize,
+ $arg,
+ $metadata = array()) {
+ parent::__construct($channel, $method, $deserialize, $metadata,
+ \Grpc\WRITE_BUFFER_HINT);
+ $this->_write($arg);
+ $this->_writesDone();
+ }
+
+ /**
+ * @return An iterator of response values
+ */
+ public function responses() {
+ while(($response = $this->_read()) != null) {
+ yield $response;
+ }
+ }
+
+ public function getStatus() {
+ return $this->_getStatus();
+ }
+}
diff --git a/src/php/lib/Grpc/SimpleSurfaceActiveCall.php b/src/php/lib/Grpc/SimpleSurfaceActiveCall.php
new file mode 100755
index 0000000000..f352573f34
--- /dev/null
+++ b/src/php/lib/Grpc/SimpleSurfaceActiveCall.php
@@ -0,0 +1,39 @@
+<?php
+namespace Grpc;
+
+require_once realpath(dirname(__FILE__) . '/../autoload.php');
+
+/**
+ * Represents an active call that sends a single message and then gets a single
+ * response.
+ */
+class SimpleSurfaceActiveCall extends AbstractSurfaceActiveCall {
+ /**
+ * Create a new simple (single request/single response) active call.
+ * @param Channel $channel The channel to communicate on
+ * @param string $method The method to call on the remote server
+ * @param callable $deserialize The function to deserialize a value
+ * @param $arg The argument to send
+ * @param array $metadata Metadata to send with the call, if applicable
+ */
+ public function __construct(Channel $channel,
+ $method,
+ callable $deserialize,
+ $arg,
+ $metadata = array()) {
+ parent::__construct($channel, $method, $deserialize, $metadata,
+ \Grpc\WRITE_BUFFER_HINT);
+ $this->_write($arg);
+ $this->_writesDone();
+ }
+
+ /**
+ * Wait for the server to respond with data and a status
+ * @return [response data, status]
+ */
+ public function wait() {
+ $response = $this->_read();
+ $status = $this->_getStatus();
+ return array($response, $status);
+ }
+}
diff --git a/src/php/lib/Grpc/SurfaceActiveCall.php b/src/php/lib/Grpc/SurfaceActiveCall.php
deleted file mode 100755
index 5f94303357..0000000000
--- a/src/php/lib/Grpc/SurfaceActiveCall.php
+++ /dev/null
@@ -1,211 +0,0 @@
-<?php
-namespace Grpc;
-
-/**
- * Represents an active call that allows sending and recieving messages.
- * Subclasses restrict how data can be sent and recieved.
- */
-abstract class AbstractSurfaceActiveCall {
- private $active_call;
- private $deserialize;
-
- /**
- * Create a new surface active call.
- * @param Channel $channel The channel to communicate on
- * @param string $method The method to call on the remote server
- * @param callable $deserialize The function to deserialize a value
- * @param array $metadata Metadata to send with the call, if applicable
- * @param long $flags Write flags to use with this call
- */
- public function __construct(Channel $channel,
- $method,
- callable $deserialize,
- $metadata = array(),
- $flags = 0) {
- $this->active_call = new ActiveCall($channel, $method, $metadata, $flags);
- $this->deserialize = $deserialize;
- }
-
- /**
- * @return The metadata sent by the server
- */
- public function getMetadata() {
- return $this->metadata();
- }
-
- /**
- * Cancels the call
- */
- public function cancel() {
- $this->active_call->cancel();
- }
-
- protected function _read() {
- $response = $this->active_call->read();
- if ($response == null) {
- return null;
- }
- return call_user_func($this->deserialize, $response);
- }
-
- protected function _write($value) {
- return $this->active_call->write($value->serialize());
- }
-
- protected function _writesDone() {
- $this->active_call->writesDone();
- }
-
- protected function _getStatus() {
- return $this->active_call->getStatus();
- }
-}
-
-/**
- * Represents an active call that sends a single message and then gets a single
- * response.
- */
-class SimpleSurfaceActiveCall extends AbstractSurfaceActiveCall {
- /**
- * Create a new simple (single request/single response) active call.
- * @param Channel $channel The channel to communicate on
- * @param string $method The method to call on the remote server
- * @param callable $deserialize The function to deserialize a value
- * @param $arg The argument to send
- * @param array $metadata Metadata to send with the call, if applicable
- */
- public function __construct(Channel $channel,
- $method,
- callable $deserialize,
- $arg,
- $metadata = array()) {
- parent::__construct($channel, $method, $deserialize, $metadata,
- \Grpc\WRITE_BUFFER_HINT);
- $this->_write($arg);
- $this->_writesDone();
- }
-
- /**
- * Wait for the server to respond with data and a status
- * @return [response data, status]
- */
- public function wait() {
- $response = $this->_read();
- $status = $this->_getStatus();
- return array($response, $status);
- }
-}
-
-/**
- * Represents an active call that sends a stream of messages and then gets a
- * single response.
- */
-class ClientStreamingSurfaceActiveCall extends AbstractSurfaceActiveCall {
- /**
- * Create a new simple (single request/single response) active call.
- * @param Channel $channel The channel to communicate on
- * @param string $method The method to call on the remote server
- * @param callable $deserialize The function to deserialize a value
- * @param Traversable $arg_iter The iterator of arguments to send
- * @param array $metadata Metadata to send with the call, if applicable
- */
- public function __construct(Channel $channel,
- $method,
- callable $deserialize,
- $arg_iter,
- $metadata = array()) {
- parent::__construct($channel, $method, $deserialize, $metadata, 0);
- foreach($arg_iter as $arg) {
- $this->_write($arg);
- }
- $this->_writesDone();
- }
-
- /**
- * Wait for the server to respond with data and a status
- * @return [response data, status]
- */
- public function wait() {
- $response = $this->_read();
- $status = $this->_getStatus();
- return array($response, $status);
- }
-}
-
-/**
- * Represents an active call that sends a single message and then gets a stream
- * of reponses
- */
-class ServerStreamingSurfaceActiveCall extends AbstractSurfaceActiveCall {
- /**
- * Create a new simple (single request/single response) active call.
- * @param Channel $channel The channel to communicate on
- * @param string $method The method to call on the remote server
- * @param callable $deserialize The function to deserialize a value
- * @param $arg The argument to send
- * @param array $metadata Metadata to send with the call, if applicable
- */
- public function __construct(Channel $channel,
- $method,
- callable $deserialize,
- $arg,
- $metadata = array()) {
- parent::__construct($channel, $method, $deserialize, $metadata,
- \Grpc\WRITE_BUFFER_HINT);
- $this->_write($arg);
- $this->_writesDone();
- }
-
- /**
- * @return An iterator of response values
- */
- public function responses() {
- while(($response = $this->_read()) != null) {
- yield $response;
- }
- }
-
- public function getStatus() {
- return $this->_getStatus();
- }
-}
-
-/**
- * Represents an active call that allows for sending and recieving messages in
- * streams in any order.
- */
-class BidiStreamingSurfaceActiveCall extends AbstractSurfaceActiveCall {
-
- /**
- * Reads the next value from the server.
- * @return The next value from the server, or null if there is none
- */
- public function read() {
- return $this->_read();
- }
-
- /**
- * Writes a single message to the server. This cannot be called after
- * writesDone is called.
- * @param $value The message to send
- */
- public function write($value) {
- $this->_write($value);
- }
-
- /**
- * Indicate that no more writes will be sent
- */
- public function writesDone() {
- $this->_writesDone();
- }
-
- /**
- * Wait for the server to send the status, and return it.
- * @return object The status object, with integer $code and string $details
- * members
- */
- public function getStatus() {
- return $this->_getStatus();
- }
-} \ No newline at end of file
diff --git a/src/php/lib/autoload.php b/src/php/lib/autoload.php
new file mode 100755
index 0000000000..8ae094730a
--- /dev/null
+++ b/src/php/lib/autoload.php
@@ -0,0 +1,21 @@
+<?php
+function grpcAutoloader($class) {
+ $prefix = 'Grpc\\';
+
+ $base_dir = __DIR__ . '/Grpc/';
+
+ $len = strlen($prefix);
+ if (strncmp($prefix, $class, $len) !== 0) {
+ return;
+ }
+
+ $relative_class = substr($class, $len);
+
+ $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
+
+ if (file_exists($file)) {
+ include $file;
+ }
+}
+
+spl_autoload_register('grpcAutoloader'); \ No newline at end of file
diff --git a/src/php/tests/generated_code/GeneratedCodeTest.php b/src/php/tests/generated_code/GeneratedCodeTest.php
index d8d726e21a..42d25e4614 100755
--- a/src/php/tests/generated_code/GeneratedCodeTest.php
+++ b/src/php/tests/generated_code/GeneratedCodeTest.php
@@ -1,7 +1,5 @@
<?php
-require __DIR__ . '/../../lib/Grpc/ActiveCall.php';
-require __DIR__ . '/../../lib/Grpc/SurfaceActiveCall.php';
-require __DIR__ . '/../../lib/Grpc/BaseStub.php';
+require_once realpath(dirname(__FILE__) . '/../../lib/autoload.php');
require 'DrSlump/Protobuf.php';
\DrSlump\Protobuf::autoload();
require 'math.php';
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index 9810c86272..43da47fd53 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -1,7 +1,5 @@
<?php
-require __DIR__ . '/../../lib/Grpc/ActiveCall.php';
-require __DIR__ . '/../../lib/Grpc/SurfaceActiveCall.php';
-require __DIR__ . '/../../lib/Grpc/BaseStub.php';
+require_once realpath(dirname(__FILE__) . '/../../lib/autoload.php');
require 'DrSlump/Protobuf.php';
\DrSlump\Protobuf::autoload();
require 'empty.php';
diff --git a/src/php/tests/unit_tests/CallTest.php b/src/php/tests/unit_tests/CallTest.php
index 150b8c3860..253052a038 100755
--- a/src/php/tests/unit_tests/CallTest.php
+++ b/src/php/tests/unit_tests/CallTest.php
@@ -9,12 +9,31 @@ class CallTest extends PHPUnit_Framework_TestCase{
}
public function setUp() {
+ $this->cq = new Grpc\CompletionQueue();
$this->channel = new Grpc\Channel('localhost:9001', []);
$this->call = new Grpc\Call($this->channel,
'/foo',
Grpc\Timeval::inf_future());
}
+ /**
+ * @expectedException LogicException
+ * @expectedExceptionCode Grpc\CALL_ERROR_INVALID_FLAGS
+ * @expectedExceptionMessage start_invoke
+ */
+ public function testStartInvokeRejectsBadFlags() {
+ $this->call->start_invoke($this->cq, 0, 0, 0, 0xDEADBEEF);
+ }
+
+ /**
+ * @expectedException LogicException
+ * @expectedExceptionCode Grpc\CALL_ERROR_NOT_ON_CLIENT
+ * @expectedExceptionMessage server_accept
+ */
+ public function testServerAcceptFailsCorrectly() {
+ $this->call->server_accept($this->cq, 0);
+ }
+
/* These test methods with assertTrue(true) at the end just check that the
method calls completed without errors. PHPUnit warns for tests with no
asserts, and this avoids that warning without changing the meaning of the
diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php
index be801bf016..3818f9531c 100755
--- a/src/php/tests/unit_tests/EndToEndTest.php
+++ b/src/php/tests/unit_tests/EndToEndTest.php
@@ -35,24 +35,29 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
// the client invocation was accepted
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\INVOKE_ACCEPTED, $event->get_type());
+ $this->assertEquals(Grpc\INVOKE_ACCEPTED, $event->type);
- $this->assertEquals(Grpc\CALL_OK, $call->writes_done($tag));
+ $call->writes_done($tag);
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->get_type());
- $this->assertEquals(Grpc\OP_OK, $event->get_data());
+ $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type);
+ $this->assertEquals(Grpc\OP_OK, $event->data);
// check that a server rpc new was received
$this->server->start();
- $this->assertEquals(Grpc\CALL_OK, $this->server->request_call($server_tag));
+ $this->server->request_call($server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->get_type());
- $server_call = $event->get_call();
+ $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->type);
+ $server_call = $event->call;
$this->assertNotNull($server_call);
$this->assertEquals(Grpc\CALL_OK,
- $server_call->accept($this->server_queue, $server_tag));
+ $server_call->server_accept($this->server_queue,
+ $server_tag));
+
+ $this->assertEquals(Grpc\CALL_OK,
+ $server_call->server_end_initial_metadata());
+
// the server sends the status
$this->assertEquals(Grpc\CALL_OK,
@@ -61,27 +66,27 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
$server_tag));
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->get_type());
- $this->assertEquals(Grpc\OP_OK, $event->get_data());
+ $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type);
+ $this->assertEquals(Grpc\OP_OK, $event->data);
// the client gets CLIENT_METADATA_READ
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->get_type());
+ $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->type);
// the client gets FINISHED
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISHED, $event->get_type());
- $status = $event->get_data();
+ $this->assertEquals(Grpc\FINISHED, $event->type);
+ $status = $event->data;
$this->assertEquals(Grpc\STATUS_OK, $status->code);
$this->assertEquals($status_text, $status->details);
// and the server gets FINISHED
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISHED, $event->get_type());
- $status = $event->get_data();
+ $this->assertEquals(Grpc\FINISHED, $event->type);
+ $status = $event->data;
unset($call);
unset($server_call);
@@ -108,56 +113,60 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
// the client invocation was accepted
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\INVOKE_ACCEPTED, $event->get_type());
+ $this->assertEquals(Grpc\INVOKE_ACCEPTED, $event->type);
// the client writes
- $this->assertEquals(Grpc\CALL_OK, $call->start_write($req_text, $tag));
+ $call->start_write($req_text, $tag);
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->get_type());
+ $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->type);
// check that a server rpc new was received
$this->server->start();
- $this->assertEquals(Grpc\CALL_OK, $this->server->request_call($server_tag));
+ $this->server->request_call($server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->get_type());
- $server_call = $event->get_call();
+ $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->type);
+ $server_call = $event->call;
$this->assertNotNull($server_call);
$this->assertEquals(Grpc\CALL_OK,
- $server_call->accept($this->server_queue, $server_tag));
+ $server_call->server_accept($this->server_queue,
+ $server_tag));
+
+ $this->assertEquals(Grpc\CALL_OK,
+ $server_call->server_end_initial_metadata());
// start the server read
- $this->assertEquals(Grpc\CALL_OK, $server_call->start_read($server_tag));
+ $server_call->start_read($server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\READ, $event->get_type());
- $this->assertEquals($req_text, $event->get_data());
+ $this->assertEquals(Grpc\READ, $event->type);
+ $this->assertEquals($req_text, $event->data);
// the server replies
$this->assertEquals(Grpc\CALL_OK,
$server_call->start_write($reply_text, $server_tag));
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->get_type());
+ $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->type);
// the client reads the metadata
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->get_type());
+ $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->type);
// the client reads the reply
- $this->assertEquals(Grpc\CALL_OK, $call->start_read($tag));
+ $call->start_read($tag);
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\READ, $event->get_type());
- $this->assertEquals($reply_text, $event->get_data());
+ $this->assertEquals(Grpc\READ, $event->type);
+ $this->assertEquals($reply_text, $event->data);
// the client sends writes done
- $this->assertEquals(Grpc\CALL_OK, $call->writes_done($tag));
+ $call->writes_done($tag);
$event = $this->client_queue->next($deadline);
- $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->get_type());
- $this->assertEquals(Grpc\OP_OK, $event->get_data());
+ $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type);
+ $this->assertEquals(Grpc\OP_OK, $event->data);
// the server sends the status
$this->assertEquals(Grpc\CALL_OK,
@@ -165,21 +174,21 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{
$status_text,
$server_tag));
$event = $this->server_queue->next($deadline);
- $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->get_type());
- $this->assertEquals(Grpc\OP_OK, $event->get_data());
+ $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type);
+ $this->assertEquals(Grpc\OP_OK, $event->data);
// the client gets FINISHED
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISHED, $event->get_type());
- $status = $event->get_data();
+ $this->assertEquals(Grpc\FINISHED, $event->type);
+ $status = $event->data;
$this->assertEquals(Grpc\STATUS_OK, $status->code);
$this->assertEquals($status_text, $status->details);
// and the server gets FINISHED
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISHED, $event->get_type());
+ $this->assertEquals(Grpc\FINISHED, $event->type);
unset($call);
unset($server_call);
diff --git a/src/php/tests/unit_tests/SecureEndToEndTest.php b/src/php/tests/unit_tests/SecureEndToEndTest.php
index d14574b4f7..c562a821a4 100755
--- a/src/php/tests/unit_tests/SecureEndToEndTest.php
+++ b/src/php/tests/unit_tests/SecureEndToEndTest.php
@@ -46,23 +46,27 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
// the client invocation was accepted
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\INVOKE_ACCEPTED, $event->get_type());
+ $this->assertEquals(Grpc\INVOKE_ACCEPTED, $event->type);
- $this->assertEquals(Grpc\CALL_OK, $call->writes_done($tag));
+ $call->writes_done($tag);
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->get_type());
- $this->assertEquals(Grpc\OP_OK, $event->get_data());
+ $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type);
+ $this->assertEquals(Grpc\OP_OK, $event->data);
// check that a server rpc new was received
- $this->assertEquals(Grpc\CALL_OK, $this->server->request_call($server_tag));
+ $this->server->request_call($server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->get_type());
- $server_call = $event->get_call();
+ $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->type);
+ $server_call = $event->call;
$this->assertNotNull($server_call);
$this->assertEquals(Grpc\CALL_OK,
- $server_call->accept($this->server_queue, $server_tag));
+ $server_call->server_accept($this->server_queue,
+ $server_tag));
+
+ $this->assertEquals(Grpc\CALL_OK,
+ $server_call->server_end_initial_metadata());
// the server sends the status
$this->assertEquals(Grpc\CALL_OK,
@@ -71,27 +75,27 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
$server_tag));
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->get_type());
- $this->assertEquals(Grpc\OP_OK, $event->get_data());
+ $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type);
+ $this->assertEquals(Grpc\OP_OK, $event->data);
// the client gets CLIENT_METADATA_READ
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->get_type());
+ $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->type);
// the client gets FINISHED
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISHED, $event->get_type());
- $status = $event->get_data();
+ $this->assertEquals(Grpc\FINISHED, $event->type);
+ $status = $event->data;
$this->assertEquals(Grpc\STATUS_OK, $status->code);
$this->assertEquals($status_text, $status->details);
// and the server gets FINISHED
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISHED, $event->get_type());
- $status = $event->get_data();
+ $this->assertEquals(Grpc\FINISHED, $event->type);
+ $status = $event->data;
unset($call);
unset($server_call);
@@ -119,55 +123,59 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
// the client invocation was accepted
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\INVOKE_ACCEPTED, $event->get_type());
+ $this->assertEquals(Grpc\INVOKE_ACCEPTED, $event->type);
// the client writes
- $this->assertEquals(Grpc\CALL_OK, $call->start_write($req_text, $tag));
+ $call->start_write($req_text, $tag);
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->get_type());
+ $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->type);
// check that a server rpc new was received
- $this->assertEquals(Grpc\CALL_OK, $this->server->request_call($server_tag));
+ $this->server->request_call($server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->get_type());
- $server_call = $event->get_call();
+ $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->type);
+ $server_call = $event->call;
$this->assertNotNull($server_call);
$this->assertEquals(Grpc\CALL_OK,
- $server_call->accept($this->server_queue, $server_tag));
+ $server_call->server_accept($this->server_queue,
+ $server_tag));
+
+ $this->assertEquals(Grpc\CALL_OK,
+ $server_call->server_end_initial_metadata());
// start the server read
- $this->assertEquals(Grpc\CALL_OK, $server_call->start_read($server_tag));
+ $server_call->start_read($server_tag);
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\READ, $event->get_type());
- $this->assertEquals($req_text, $event->get_data());
+ $this->assertEquals(Grpc\READ, $event->type);
+ $this->assertEquals($req_text, $event->data);
// the server replies
$this->assertEquals(Grpc\CALL_OK,
$server_call->start_write($reply_text, $server_tag));
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->get_type());
+ $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->type);
// the client reads the metadata
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->get_type());
+ $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->type);
// the client reads the reply
- $this->assertEquals(Grpc\CALL_OK, $call->start_read($tag));
+ $call->start_read($tag);
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\READ, $event->get_type());
- $this->assertEquals($reply_text, $event->get_data());
+ $this->assertEquals(Grpc\READ, $event->type);
+ $this->assertEquals($reply_text, $event->data);
// the client sends writes done
- $this->assertEquals(Grpc\CALL_OK, $call->writes_done($tag));
+ $call->writes_done($tag);
$event = $this->client_queue->next($deadline);
- $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->get_type());
- $this->assertEquals(Grpc\OP_OK, $event->get_data());
+ $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type);
+ $this->assertEquals(Grpc\OP_OK, $event->data);
// the server sends the status
$this->assertEquals(Grpc\CALL_OK,
@@ -175,21 +183,21 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
$status_text,
$server_tag));
$event = $this->server_queue->next($deadline);
- $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->get_type());
- $this->assertEquals(Grpc\OP_OK, $event->get_data());
+ $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type);
+ $this->assertEquals(Grpc\OP_OK, $event->data);
// the client gets FINISHED
$event = $this->client_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISHED, $event->get_type());
- $status = $event->get_data();
+ $this->assertEquals(Grpc\FINISHED, $event->type);
+ $status = $event->data;
$this->assertEquals(Grpc\STATUS_OK, $status->code);
$this->assertEquals($status_text, $status->details);
// and the server gets FINISHED
$event = $this->server_queue->next($deadline);
$this->assertNotNull($event);
- $this->assertEquals(Grpc\FINISHED, $event->get_type());
+ $this->assertEquals(Grpc\FINISHED, $event->type);
unset($call);
unset($server_call);
diff --git a/test/core/echo/echo_test.c b/test/core/echo/echo_test.c
index 748e8bc0ef..16d381fb65 100644
--- a/test/core/echo/echo_test.c
+++ b/test/core/echo/echo_test.c
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <string.h>
#include <signal.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -80,6 +81,9 @@ int main(int argc, char **argv) {
pid_t svr;
int ret;
int do_ipv6 = 1;
+ /* seed rng with pid, so we don't end up with the same random numbers as a
+ concurrently running test binary */
+ srand(getpid());
if (!grpc_ipv6_loopback_available()) {
gpr_log(GPR_INFO, "Can't bind to ::1. Skipping IPv6 tests.");
do_ipv6 = 0;
diff --git a/test/core/fling/fling_stream_test.c b/test/core/fling/fling_stream_test.c
index a24240ef1d..f6fe69824b 100644
--- a/test/core/fling/fling_stream_test.c
+++ b/test/core/fling/fling_stream_test.c
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <string.h>
#include <signal.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -53,6 +54,9 @@ int main(int argc, char **argv) {
char *args[10];
int status;
pid_t svr, cli;
+ /* seed rng with pid, so we don't end up with the same random numbers as a
+ concurrently running test binary */
+ srand(getpid());
/* figure out where we are */
if (lslash) {
memcpy(root, me, lslash - me);
diff --git a/test/core/fling/fling_test.c b/test/core/fling/fling_test.c
index c6b369518c..4607aa5f98 100644
--- a/test/core/fling/fling_test.c
+++ b/test/core/fling/fling_test.c
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <string.h>
#include <signal.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -53,6 +54,9 @@ int main(int argc, char **argv) {
char *args[10];
int status;
pid_t svr, cli;
+ /* seed rng with pid, so we don't end up with the same random numbers as a
+ concurrently running test binary */
+ srand(getpid());
/* figure out where we are */
if (lslash) {
memcpy(root, me, lslash - me);
diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c
index 993014aa14..fc5de9bbef 100644
--- a/test/core/util/test_config.c
+++ b/test/core/util/test_config.c
@@ -33,4 +33,11 @@
#include "test/core/util/test_config.h"
-void grpc_test_init(int argc, char **argv) {}
+#include <stdlib.h>
+#include <unistd.h>
+
+void grpc_test_init(int argc, char **argv) {
+ /* seed rng with pid, so we don't end up with the same random numbers as a
+ concurrently running test binary */
+ srand(getpid());
+}