diff options
author | Sree Kuchibhotla <sreek@google.com> | 2017-01-13 10:16:35 -0800 |
---|---|---|
committer | Sree Kuchibhotla <sreek@google.com> | 2017-01-13 10:16:35 -0800 |
commit | d09122e51846d497b479a5e5072a775642cc32ae (patch) | |
tree | 758c3385caf091f5a8b19bc8bffd200c12b99a93 /src | |
parent | e93b028f07addb13240e636aaea837e3f0eaa9c4 (diff) | |
parent | 6b6954050cf0379dbbee90dd18313a3779e0dd52 (diff) |
Merge branch 'master' into tweak_slice_buffer
Diffstat (limited to 'src')
21 files changed, 282 insertions, 99 deletions
diff --git a/src/core/ext/census/tracing.c b/src/core/ext/census/tracing.c index 8f0e12296d..3b5d6dab2b 100644 --- a/src/core/ext/census/tracing.c +++ b/src/core/ext/census/tracing.c @@ -31,19 +31,15 @@ * */ -//#include "src/core/ext/census/tracing.h" - #include <grpc/census.h> /* TODO(aveitch): These are all placeholder implementations. */ -// int census_trace_mask(const census_context *context) { -// return CENSUS_TRACE_MASK_NONE; -// } - -// void census_set_trace_mask(int trace_mask) {} +int census_trace_mask(const census_context *context) { + return CENSUS_TRACE_MASK_NONE; +} -// void census_trace_print(census_context *context, uint32_t type, -// const char *buffer, size_t n) {} +void census_set_trace_mask(int trace_mask) {} -// void SetTracerParams(const Params& params); +void census_trace_print(census_context *context, uint32_t type, + const char *buffer, size_t n) {} diff --git a/src/core/ext/client_channel/http_connect_handshaker.c b/src/core/ext/client_channel/http_connect_handshaker.c index ace804c47f..fba32561ac 100644 --- a/src/core/ext/client_channel/http_connect_handshaker.c +++ b/src/core/ext/client_channel/http_connect_handshaker.c @@ -55,6 +55,8 @@ typedef struct http_connect_handshaker { grpc_handshaker base; char* proxy_server; + grpc_http_header* headers; + size_t num_headers; gpr_refcount refcount; gpr_mu mu; @@ -90,6 +92,11 @@ static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx, gpr_free(handshaker->read_buffer_to_destroy); } gpr_free(handshaker->proxy_server); + for (size_t i = 0; i < handshaker->num_headers; ++i) { + gpr_free(handshaker->headers[i].key); + gpr_free(handshaker->headers[i].value); + } + gpr_free(handshaker->headers); grpc_slice_buffer_destroy_internal(exec_ctx, &handshaker->write_buffer); grpc_http_parser_destroy(&handshaker->http_parser); grpc_http_response_destroy(&handshaker->http_response); @@ -290,6 +297,8 @@ static void http_connect_handshaker_do_handshake( request.host = server_name; request.http.method = "CONNECT"; request.http.path = server_name; + request.http.hdrs = handshaker->headers; + request.http.hdr_count = handshaker->num_headers; request.handshaker = &grpc_httpcli_plaintext; grpc_slice request_slice = grpc_httpcli_format_connect_request(&request); grpc_slice_buffer_add(&handshaker->write_buffer, request_slice); @@ -307,7 +316,9 @@ static const grpc_handshaker_vtable http_connect_handshaker_vtable = { http_connect_handshaker_destroy, http_connect_handshaker_shutdown, http_connect_handshaker_do_handshake}; -grpc_handshaker* grpc_http_connect_handshaker_create(const char* proxy_server) { +grpc_handshaker* grpc_http_connect_handshaker_create(const char* proxy_server, + grpc_http_header* headers, + size_t num_headers) { GPR_ASSERT(proxy_server != NULL); http_connect_handshaker* handshaker = gpr_malloc(sizeof(*handshaker)); memset(handshaker, 0, sizeof(*handshaker)); @@ -315,6 +326,14 @@ grpc_handshaker* grpc_http_connect_handshaker_create(const char* proxy_server) { gpr_mu_init(&handshaker->mu); gpr_ref_init(&handshaker->refcount, 1); handshaker->proxy_server = gpr_strdup(proxy_server); + if (num_headers > 0) { + handshaker->headers = gpr_malloc(sizeof(grpc_http_header) * num_headers); + for (size_t i = 0; i < num_headers; ++i) { + handshaker->headers[i].key = gpr_strdup(headers[i].key); + handshaker->headers[i].value = gpr_strdup(headers[i].value); + } + handshaker->num_headers = num_headers; + } grpc_slice_buffer_init(&handshaker->write_buffer); grpc_closure_init(&handshaker->request_done_closure, on_write_done, handshaker, grpc_schedule_on_exec_ctx); @@ -358,8 +377,9 @@ static void handshaker_factory_add_handshakers( const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { char* proxy_name = grpc_get_http_proxy_server(); if (proxy_name != NULL) { - grpc_handshake_manager_add(handshake_mgr, - grpc_http_connect_handshaker_create(proxy_name)); + grpc_handshake_manager_add( + handshake_mgr, + grpc_http_connect_handshaker_create(proxy_name, NULL, 0)); gpr_free(proxy_name); } } diff --git a/src/core/ext/client_channel/http_connect_handshaker.h b/src/core/ext/client_channel/http_connect_handshaker.h index 56485f1373..c2e68de716 100644 --- a/src/core/ext/client_channel/http_connect_handshaker.h +++ b/src/core/ext/client_channel/http_connect_handshaker.h @@ -35,9 +35,12 @@ #define GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_CONNECT_HANDSHAKER_H #include "src/core/lib/channel/handshaker.h" +#include "src/core/lib/http/parser.h" /// Creates a new HTTP CONNECT handshaker. -grpc_handshaker* grpc_http_connect_handshaker_create(const char* proxy_server); +grpc_handshaker* grpc_http_connect_handshaker_create(const char* proxy_server, + grpc_http_header* headers, + size_t num_headers); /// Returns the name of the proxy to use, or NULL if no proxy is configured. /// Caller takes ownership of result. diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index bb2b012507..655d9dc586 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -189,7 +189,7 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); gpr_timespec timeout = gpr_time_sub(next_try, now); const char *msg = grpc_error_string(error); - gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); + gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", msg); grpc_error_free_string(msg); GPR_ASSERT(!r->have_retry_timer); r->have_retry_timer = true; diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.c b/src/core/ext/transport/chttp2/transport/frame_rst_stream.c index b4c5ed769b..20043f5fbf 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.c @@ -109,7 +109,7 @@ grpc_error *grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx *exec_ctx, (((uint32_t)p->reason_bytes[2]) << 8) | (((uint32_t)p->reason_bytes[3])); grpc_error *error = GRPC_ERROR_NONE; - if (reason != GRPC_CHTTP2_NO_ERROR) { + if (reason != GRPC_CHTTP2_NO_ERROR || s->header_frames_received < 2) { error = grpc_error_set_int(GRPC_ERROR_CREATE("RST_STREAM"), GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)reason); grpc_status_code status_code = grpc_chttp2_http2_error_to_grpc_status( diff --git a/src/core/lib/iomgr/iocp_windows.c b/src/core/lib/iomgr/iocp_windows.c index 60ebe43676..f0f4a6ff39 100644 --- a/src/core/lib/iomgr/iocp_windows.c +++ b/src/core/lib/iomgr/iocp_windows.c @@ -80,7 +80,6 @@ grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx *exec_ctx, LPOVERLAPPED overlapped; grpc_winsocket *socket; grpc_winsocket_callback_info *info; - grpc_closure *closure = NULL; success = GetQueuedCompletionStatus( g_iocp, &bytes, &completion_key, &overlapped, deadline_to_millis_timeout(deadline, gpr_now(deadline.clock_type))); diff --git a/src/core/lib/iomgr/tcp_server_windows.c b/src/core/lib/iomgr/tcp_server_windows.c index 97d7827461..dafe851ce8 100644 --- a/src/core/lib/iomgr/tcp_server_windows.c +++ b/src/core/lib/iomgr/tcp_server_windows.c @@ -184,7 +184,6 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s, } static void tcp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) { - int immediately_done = 0; grpc_tcp_listener *sp; gpr_mu_lock(&s->mu); @@ -240,7 +239,7 @@ static grpc_error *prepare_socket(SOCKET sock, error = GRPC_WSA_ERROR(WSAGetLastError(), "getsockname"); goto failure; } - sockname_temp.len = sockname_temp_len; + sockname_temp.len = (size_t)sockname_temp_len; *port = grpc_sockaddr_get_port(&sockname_temp); return GRPC_ERROR_NONE; @@ -248,7 +247,7 @@ static grpc_error *prepare_socket(SOCKET sock, failure: GPR_ASSERT(error != GRPC_ERROR_NONE); char *tgtaddr = grpc_sockaddr_to_uri(addr); - grpc_error *final_error = grpc_error_set_int( + grpc_error_set_int( grpc_error_set_str(GRPC_ERROR_CREATE_REFERENCING( "Failed to prepare server socket", &error, 1), GRPC_ERROR_STR_TARGET_ADDRESS, tgtaddr), @@ -261,7 +260,6 @@ failure: static void decrement_active_ports_and_notify_locked(grpc_exec_ctx *exec_ctx, grpc_tcp_listener *sp) { - int notify = 0; sp->shutting_down = 0; GPR_ASSERT(sp->server->active_ports > 0); if (0 == --sp->server->active_ports) { @@ -375,7 +373,7 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { int peer_name_len = (int)peer_name.len; err = getpeername(sock, (struct sockaddr *)peer_name.addr, &peer_name_len); - peer_name.len = peer_name_len; + peer_name.len = (size_t)peer_name_len; if (!err) { peer_name_string = grpc_sockaddr_to_uri(&peer_name); } else { @@ -498,7 +496,7 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, if (0 == getsockname(sp->socket->socket, (struct sockaddr *)sockname_temp.addr, &sockname_temp_len)) { - sockname_temp.len = sockname_temp_len; + sockname_temp.len = (size_t)sockname_temp_len; *port = grpc_sockaddr_get_port(&sockname_temp); if (*port > 0) { allocated_addr = gpr_malloc(sizeof(grpc_resolved_address)); diff --git a/src/php/bin/generate_proto_php.sh b/src/php/bin/generate_proto_php.sh index c558bc5769..416fa9df97 100755 --- a/src/php/bin/generate_proto_php.sh +++ b/src/php/bin/generate_proto_php.sh @@ -39,10 +39,13 @@ protoc --proto_path=src/proto/math \ # replace the Empty message with EmptyMessage # because Empty is a PHP reserved word -sed -i 's/message Empty/message EmptyMessage/g' \ - src/proto/grpc/testing/empty.proto -sed -i 's/grpc\.testing\.Empty/grpc\.testing\.EmptyMessage/g' \ - src/proto/grpc/testing/test.proto +output_file=$(mktemp) +sed 's/message Empty/message EmptyMessage/g' \ + src/proto/grpc/testing/empty.proto > $output_file +mv $output_file ./src/proto/grpc/testing/empty.proto +sed 's/grpc\.testing\.Empty/grpc\.testing\.EmptyMessage/g' \ + src/proto/grpc/testing/test.proto > $output_file +mv $output_file ./src/proto/grpc/testing/test.proto protoc --proto_path=. \ --php_out=src/php/tests/interop \ @@ -53,7 +56,10 @@ protoc --proto_path=. \ src/proto/grpc/testing/test.proto # change it back -sed -i 's/message EmptyMessage/message Empty/g' \ - src/proto/grpc/testing/empty.proto -sed -i 's/grpc\.testing\.EmptyMessage/grpc\.testing\.Empty/g' \ - src/proto/grpc/testing/test.proto +sed 's/message EmptyMessage/message Empty/g' \ + src/proto/grpc/testing/empty.proto > $output_file +mv $output_file ./src/proto/grpc/testing/empty.proto +sed 's/grpc\.testing\.EmptyMessage/grpc\.testing\.Empty/g' \ + src/proto/grpc/testing/test.proto > $output_file +mv $output_file ./src/proto/grpc/testing/test.proto + diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 3a49ea8708..64b1137c2a 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -478,6 +478,7 @@ PHP_METHOD(Call, startBatch) { true); add_property_zval(result, "status", recv_status); PHP_GRPC_DELREF(recv_status); + PHP_GRPC_FREE_STD_ZVAL(recv_status); break; case GRPC_OP_RECV_CLOSE_ON_SERVER: add_property_bool(result, "cancelled", cancelled); @@ -501,6 +502,7 @@ cleanup: } if (ops[i].op == GRPC_OP_RECV_MESSAGE) { grpc_byte_buffer_destroy(message); + PHP_GRPC_FREE_STD_ZVAL(message_str); } } RETURN_DESTROY_ZVAL(result); diff --git a/src/php/ext/grpc/call_credentials.c b/src/php/ext/grpc/call_credentials.c index 3aafc3a19b..043817facd 100644 --- a/src/php/ext/grpc/call_credentials.c +++ b/src/php/ext/grpc/call_credentials.c @@ -111,9 +111,7 @@ PHP_METHOD(CallCredentials, createComposite) { grpc_call_credentials *creds = grpc_composite_call_credentials_create(cred1->wrapped, cred2->wrapped, NULL); - zval *creds_object; - PHP_GRPC_MAKE_STD_ZVAL(creds_object); - creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); + zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); } @@ -155,9 +153,7 @@ PHP_METHOD(CallCredentials, createFromPlugin) { grpc_call_credentials *creds = grpc_metadata_credentials_create_from_plugin(plugin, NULL); - zval *creds_object; - PHP_GRPC_MAKE_STD_ZVAL(creds_object); - creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); + zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); } @@ -211,6 +207,8 @@ void plugin_destroy_state(void *ptr) { plugin_state *state = (plugin_state *)ptr; efree(state->fci); efree(state->fci_cache); + PHP_GRPC_FREE_STD_ZVAL(state->fci->params); + PHP_GRPC_FREE_STD_ZVAL(state->fci->retval); efree(state); } diff --git a/src/php/ext/grpc/channel_credentials.c b/src/php/ext/grpc/channel_credentials.c index a32c4a4ea2..36a8223b88 100644 --- a/src/php/ext/grpc/channel_credentials.c +++ b/src/php/ext/grpc/channel_credentials.c @@ -121,9 +121,7 @@ PHP_METHOD(ChannelCredentials, setDefaultRootsPem) { */ PHP_METHOD(ChannelCredentials, createDefault) { grpc_channel_credentials *creds = grpc_google_default_credentials_create(); - zval *creds_object; - PHP_GRPC_MAKE_STD_ZVAL(creds_object); - creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); + zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); } @@ -160,9 +158,7 @@ PHP_METHOD(ChannelCredentials, createSsl) { grpc_channel_credentials *creds = grpc_ssl_credentials_create( pem_root_certs, pem_key_cert_pair.private_key == NULL ? NULL : &pem_key_cert_pair, NULL); - zval *creds_object; - PHP_GRPC_MAKE_STD_ZVAL(creds_object); - creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); + zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); } @@ -191,9 +187,7 @@ PHP_METHOD(ChannelCredentials, createComposite) { grpc_channel_credentials *creds = grpc_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped, NULL); - zval *creds_object; - PHP_GRPC_MAKE_STD_ZVAL(creds_object); - creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); + zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); } diff --git a/src/php/ext/grpc/php7_wrapper.h b/src/php/ext/grpc/php7_wrapper.h index 1d7824113f..72e982d6fc 100644 --- a/src/php/ext/grpc/php7_wrapper.h +++ b/src/php/ext/grpc/php7_wrapper.h @@ -50,8 +50,13 @@ #define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val, dup) #define PHP_GRPC_MAKE_STD_ZVAL(pzv) MAKE_STD_ZVAL(pzv) +#define PHP_GRPC_FREE_STD_ZVAL(pzv) #define PHP_GRPC_DELREF(zv) Z_DELREF_P(zv) +#define RETURN_DESTROY_ZVAL(val) \ + RETURN_ZVAL(val, false /* Don't execute copy constructor */, \ + true /* Dealloc original before returning */) + #define PHP_GRPC_WRAP_OBJECT_START(name) \ typedef struct name { \ zend_object std; @@ -144,8 +149,15 @@ static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len, #define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val) #define PHP_GRPC_MAKE_STD_ZVAL(pzv) \ pzv = (zval *)emalloc(sizeof(zval)); +#define PHP_GRPC_FREE_STD_ZVAL(pzv) efree(pzv); #define PHP_GRPC_DELREF(zv) +#define RETURN_DESTROY_ZVAL(val) \ + RETVAL_ZVAL(val, false /* Don't execute copy constructor */, \ + true /* Dealloc original before returning */); \ + efree(val); \ + return + #define PHP_GRPC_WRAP_OBJECT_START(name) \ typedef struct name { #define PHP_GRPC_WRAP_OBJECT_END(name) \ diff --git a/src/php/ext/grpc/php_grpc.h b/src/php/ext/grpc/php_grpc.h index e57a06545e..13083b0bc7 100644 --- a/src/php/ext/grpc/php_grpc.h +++ b/src/php/ext/grpc/php_grpc.h @@ -61,10 +61,6 @@ extern zend_module_entry grpc_module_entry; #include "grpc/grpc.h" -#define RETURN_DESTROY_ZVAL(val) \ - RETURN_ZVAL(val, false /* Don't execute copy constructor */, \ - true /* Dealloc original before returning */) - /* These are all function declarations */ /* Code that runs at module initialization */ PHP_MINIT_FUNCTION(grpc); diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c index 1610c8ebb0..3e39fee246 100644 --- a/src/php/ext/grpc/server_credentials.c +++ b/src/php/ext/grpc/server_credentials.c @@ -113,9 +113,7 @@ PHP_METHOD(ServerCredentials, createSsl) { grpc_server_credentials *creds = grpc_ssl_server_credentials_create_ex( pem_root_certs, &pem_key_cert_pair, 1, GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, NULL); - zval *creds_object; - PHP_GRPC_MAKE_STD_ZVAL(creds_object); - creds_object = grpc_php_wrap_server_credentials(creds TSRMLS_CC); + zval *creds_object = grpc_php_wrap_server_credentials(creds TSRMLS_CC); RETURN_DESTROY_ZVAL(creds_object); } diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c index 945231b47f..7ada915aad 100644 --- a/src/php/ext/grpc/timeval.c +++ b/src/php/ext/grpc/timeval.c @@ -115,11 +115,9 @@ PHP_METHOD(Timeval, add) { } wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj); - zval *sum; - PHP_GRPC_MAKE_STD_ZVAL(sum); - sum = - grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped) - TSRMLS_CC); + zval *sum = + grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped) + TSRMLS_CC); RETURN_DESTROY_ZVAL(sum); } @@ -141,11 +139,9 @@ PHP_METHOD(Timeval, subtract) { } wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis()); wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj); - zval *diff; - PHP_GRPC_MAKE_STD_ZVAL(diff); - diff = - grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped) - TSRMLS_CC); + zval *diff = + grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped) + TSRMLS_CC); RETURN_DESTROY_ZVAL(diff); } @@ -206,9 +202,7 @@ PHP_METHOD(Timeval, similar) { * @return Timeval The current time */ PHP_METHOD(Timeval, now) { - zval *now; - PHP_GRPC_MAKE_STD_ZVAL(now); - now = grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME) TSRMLS_CC); + zval *now = grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME) TSRMLS_CC); RETURN_DESTROY_ZVAL(now); } @@ -217,13 +211,9 @@ PHP_METHOD(Timeval, now) { * @return Timeval Zero length time interval */ PHP_METHOD(Timeval, zero) { - zval *grpc_php_timeval_zero; - PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_zero); - grpc_php_timeval_zero = - grpc_php_wrap_timeval(gpr_time_0(GPR_CLOCK_REALTIME) TSRMLS_CC); - RETURN_ZVAL(grpc_php_timeval_zero, - false, /* Copy original before returning? */ - true /* Destroy original before returning */); + zval *grpc_php_timeval_zero = + grpc_php_wrap_timeval(gpr_time_0(GPR_CLOCK_REALTIME) TSRMLS_CC); + RETURN_DESTROY_ZVAL(grpc_php_timeval_zero); } /** @@ -231,10 +221,8 @@ PHP_METHOD(Timeval, zero) { * @return Timeval Infinite future time value */ PHP_METHOD(Timeval, infFuture) { - zval *grpc_php_timeval_inf_future; - PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_inf_future); - grpc_php_timeval_inf_future = - grpc_php_wrap_timeval(gpr_inf_future(GPR_CLOCK_REALTIME) TSRMLS_CC); + zval *grpc_php_timeval_inf_future = + grpc_php_wrap_timeval(gpr_inf_future(GPR_CLOCK_REALTIME) TSRMLS_CC); RETURN_DESTROY_ZVAL(grpc_php_timeval_inf_future); } @@ -243,10 +231,8 @@ PHP_METHOD(Timeval, infFuture) { * @return Timeval Infinite past time value */ PHP_METHOD(Timeval, infPast) { - zval *grpc_php_timeval_inf_past; - PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_inf_past); - grpc_php_timeval_inf_past = - grpc_php_wrap_timeval(gpr_inf_past(GPR_CLOCK_REALTIME) TSRMLS_CC); + zval *grpc_php_timeval_inf_past = + grpc_php_wrap_timeval(gpr_inf_past(GPR_CLOCK_REALTIME) TSRMLS_CC); RETURN_DESTROY_ZVAL(grpc_php_timeval_inf_past); } diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index aec60af094..a9e77b9396 100644 --- a/src/php/lib/Grpc/BaseStub.php +++ b/src/php/lib/Grpc/BaseStub.php @@ -271,7 +271,7 @@ class BaseStub * @return ClientStreamingSurfaceActiveCall The active call object */ public function _clientStreamRequest($method, - callable $deserialize, + $deserialize, array $metadata = [], array $options = []) { @@ -307,7 +307,7 @@ class BaseStub */ public function _serverStreamRequest($method, $argument, - callable $deserialize, + $deserialize, array $metadata = [], array $options = []) { @@ -340,7 +340,7 @@ class BaseStub * @return BidiStreamingSurfaceActiveCall The active call object */ public function _bidiRequest($method, - callable $deserialize, + $deserialize, array $metadata = [], array $options = []) { diff --git a/src/proto/grpc/testing/control.proto b/src/proto/grpc/testing/control.proto index be387cf786..529313cfb1 100644 --- a/src/proto/grpc/testing/control.proto +++ b/src/proto/grpc/testing/control.proto @@ -78,6 +78,14 @@ message SecurityParams { string server_host_override = 2; } +message ChannelArg { + string name = 1; + oneof value { + string str_value = 2; + int32 int_value = 3; + } +} + message ClientConfig { // List of targets to connect to. At least one target needs to be specified. repeated string server_targets = 1; @@ -103,6 +111,8 @@ message ClientConfig { // If we use an OTHER_CLIENT client_type, this string gives more detail string other_client_api = 15; + + repeated ChannelArg channel_args = 16; } message ClientStatus { ClientStats stats = 1; } diff --git a/src/python/grpcio_tests/tests/qps/benchmark_client.py b/src/python/grpcio_tests/tests/qps/benchmark_client.py index 83b46c914e..650e4756e7 100644 --- a/src/python/grpcio_tests/tests/qps/benchmark_client.py +++ b/src/python/grpcio_tests/tests/qps/benchmark_client.py @@ -68,12 +68,8 @@ class BenchmarkClient: else: channel = grpc.insecure_channel(server) - connected_event = threading.Event() - def wait_for_ready(connectivity): - if connectivity == grpc.ChannelConnectivity.READY: - connected_event.set() - channel.subscribe(wait_for_ready, try_to_connect=True) - connected_event.wait() + # waits for the channel to be ready before we start sending messages + grpc.channel_ready_future(channel).result() if config.payload_config.WhichOneof('payload') == 'simple_params': self._generic = False diff --git a/src/python/grpcio_tests/tests/stress/client.py b/src/python/grpcio_tests/tests/stress/client.py index 390ea13021..b8116729b5 100644 --- a/src/python/grpcio_tests/tests/stress/client.py +++ b/src/python/grpcio_tests/tests/stress/client.py @@ -110,10 +110,13 @@ def _get_channel(target, args): channel_credentials = grpc.ssl_channel_credentials( root_certificates=root_certificates) options = (('grpc.ssl_target_name_override', args.server_host_override,),) - return grpc.secure_channel( - target, channel_credentials, options=options) + channel = grpc.secure_channel(target, channel_credentials, options=options) else: - return grpc.insecure_channel(target) + channel = grpc.insecure_channel(target) + + # waits for the channel to be ready before we start sending messages + grpc.channel_ready_future(channel).result() + return channel def run_test(args): test_cases = _parse_weighted_test_cases(args.test_cases) diff --git a/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb b/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb index fde328e4c5..7d1072e512 100644 --- a/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +++ b/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb @@ -54,6 +54,10 @@ module Grpc rpc :EmptyCall, Empty, Empty # One request followed by one response. rpc :UnaryCall, SimpleRequest, SimpleResponse + # One request followed by one response. Response has cache control + # headers set such that a caching HTTP proxy (such as GFE) can + # satisfy subsequent requests. + rpc :CacheableUnaryCall, SimpleRequest, SimpleResponse # One request followed by a sequence of responses (streamed download). # The server returns the payload with client desired type and sizes. rpc :StreamingOutputCall, StreamingOutputCallRequest, stream(StreamingOutputCallResponse) @@ -69,6 +73,9 @@ module Grpc # stream of responses are returned to the client when the server starts with # first request. rpc :HalfDuplexCall, stream(StreamingOutputCallRequest), stream(StreamingOutputCallResponse) + # The test server will not implement this method. It will be used + # to test the behavior when clients call unimplemented methods. + rpc :UnimplementedCall, Empty, Empty end Stub = Service.rpc_stub_class diff --git a/src/ruby/pb/test/client.rb b/src/ruby/pb/test/client.rb index f101f9d89e..9c4ee9c6f2 100755 --- a/src/ruby/pb/test/client.rb +++ b/src/ruby/pb/test/client.rb @@ -158,14 +158,26 @@ def create_stub(opts) GRPC.logger.info("... connecting securely to #{address}") stub_opts[:channel_args].merge!(compression_channel_args) - Grpc::Testing::TestService::Stub.new(address, creds, **stub_opts) + if opts.test_case == "unimplemented_service" + Grpc::Testing::UnimplementedService::Stub.new(address, creds, **stub_opts) + else + Grpc::Testing::TestService::Stub.new(address, creds, **stub_opts) + end else GRPC.logger.info("... connecting insecurely to #{address}") - Grpc::Testing::TestService::Stub.new( - address, - :this_channel_is_insecure, - channel_args: compression_channel_args - ) + if opts.test_case == "unimplemented_service" + Grpc::Testing::UnimplementedService::Stub.new( + address, + :this_channel_is_insecure, + channel_args: compression_channel_args + ) + else + Grpc::Testing::TestService::Stub.new( + address, + :this_channel_is_insecure, + channel_args: compression_channel_args + ) + end end end @@ -502,6 +514,153 @@ class NamedTests op.wait end + def unimplemented_method + begin + resp = @stub.unimplemented_call(Empty.new) + rescue GRPC::Unimplemented => e + return + rescue Exception => e + fail AssertionError, "Expected BadStatus. Received: #{e.inspect}" + end + fail AssertionError, "GRPC::Unimplemented should have been raised. Was not." + end + + def unimplemented_service + begin + resp = @stub.unimplemented_call(Empty.new) + rescue GRPC::Unimplemented => e + return + rescue Exception => e + fail AssertionError, "Expected BadStatus. Received: #{e.inspect}" + end + fail AssertionError, "GRPC::Unimplemented should have been raised. Was not." + end + + def status_code_and_message + + # Function wide constants. + message = "test status method" + code = GRPC::Core::StatusCodes::UNKNOWN + + # Testing with UnaryCall. + payload = Payload.new(type: :COMPRESSABLE, body: nulls(1)) + echo_status = EchoStatus.new(code: code, message: message) + req = SimpleRequest.new(response_type: :COMPRESSABLE, + response_size: 1, + payload: payload, + response_status: echo_status) + seen_correct_exception = false + begin + resp = @stub.unary_call(req) + rescue GRPC::Unknown => e + if e.details != message + fail AssertionError, + "Expected message #{message}. Received: #{e.details}" + end + seen_correct_exception = true + rescue Exception => e + fail AssertionError, "Expected BadStatus. Received: #{e.inspect}" + end + + if not seen_correct_exception + fail AssertionError, "Did not see expected status from UnaryCall" + end + + # testing with FullDuplex + req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters + duplex_req = req_cls.new(payload: Payload.new(body: nulls(1)), + response_type: :COMPRESSABLE, + response_parameters: [p_cls.new(size: 1)], + response_status: echo_status) + seen_correct_exception = false + begin + resp = @stub.full_duplex_call([duplex_req]) + resp.each { |r| } + rescue GRPC::Unknown => e + if e.details != message + fail AssertionError, + "Expected message #{message}. Received: #{e.details}" + end + seen_correct_exception = true + rescue Exception => e + fail AssertionError, "Expected BadStatus. Received: #{e.inspect}" + end + + if not seen_correct_exception + fail AssertionError, "Did not see expected status from FullDuplexCall" + end + + end + + + def custom_metadata + + # Function wide constants + req_size, wanted_response_size = 271_828, 314_159 + initial_metadata_key = "x-grpc-test-echo-initial" + initial_metadata_value = "test_initial_metadata_value" + trailing_metadata_key = "x-grpc-test-echo-trailing-bin" + trailing_metadata_value = "\x0a\x0b\x0a\x0b\x0a\x0b" + + metadata = { + initial_metadata_key => initial_metadata_value, + trailing_metadata_key => trailing_metadata_value + } + + # Testing with UnaryCall + payload = Payload.new(type: :COMPRESSABLE, body: nulls(req_size)) + req = SimpleRequest.new(response_type: :COMPRESSABLE, + response_size: wanted_response_size, + payload: payload) + + op = @stub.unary_call(req, metadata: metadata, return_op: true) + op.execute + if not op.metadata.has_key?(initial_metadata_key) + fail AssertionError, "Expected initial metadata. None received" + elsif op.metadata[initial_metadata_key] != metadata[initial_metadata_key] + fail AssertionError, + "Expected initial metadata: #{metadata[initial_metadata_key]}. "\ + "Received: #{op.metadata[initial_metadata_key]}" + end + if not op.trailing_metadata.has_key?(trailing_metadata_key) + fail AssertionError, "Expected trailing metadata. None received" + elsif op.trailing_metadata[trailing_metadata_key] != + metadata[trailing_metadata_key] + fail AssertionError, + "Expected trailing metadata: #{metadata[trailing_metadata_key]}. "\ + "Received: #{op.trailing_metadata[trailing_metadata_key]}" + end + + # Testing with FullDuplex + req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters + duplex_req = req_cls.new(payload: Payload.new(body: nulls(req_size)), + response_type: :COMPRESSABLE, + response_parameters: [p_cls.new(size: wanted_response_size)]) + + duplex_op = @stub.full_duplex_call([duplex_req], metadata: metadata, + return_op: true) + resp = duplex_op.execute + resp.each { |r| } # ensures that the server sends trailing data + duplex_op.wait + if not duplex_op.metadata.has_key?(initial_metadata_key) + fail AssertionError, "Expected initial metadata. None received" + elsif duplex_op.metadata[initial_metadata_key] != + metadata[initial_metadata_key] + fail AssertionError, + "Expected initial metadata: #{metadata[initial_metadata_key]}. "\ + "Received: #{duplex_op.metadata[initial_metadata_key]}" + end + if not duplex_op.trailing_metadata[trailing_metadata_key] + fail AssertionError, "Expected trailing metadata. None received" + elsif duplex_op.trailing_metadata[trailing_metadata_key] != + metadata[trailing_metadata_key] + fail AssertionError, + "Expected trailing metadata: #{metadata[trailing_metadata_key]}. "\ + "Received: #{duplex_op.trailing_metadata[trailing_metadata_key]}" + end + + end + def all all_methods = NamedTests.instance_methods(false).map(&:to_s) all_methods.each do |m| |