Merge pull request #1129 from nicolasnoble/scan-build
Adding Dockerfile for grpc/scan-build.
diff --git a/.travis.yml b/.travis.yml
index e43a89e..165f892 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,9 +19,12 @@
- CONFIG=opt TEST=python
- CONFIG=gcov TEST=c
- CONFIG=gcov TEST=c++
+ - USE_GCC=4.4 CONFIG=opt TEST=build
+ - USE_GCC=4.5 CONFIG=opt TEST=build
script:
- rvm use $RUBY_VERSION
- gem install bundler
+ - if [ ! -z "$USE_GCC" ] ; then export CC=gcc-$USE_GCC ; export CXX=g++-$USE_GCC ; fi
- ./tools/run_tests/run_tests.py -l $TEST -t -j 16 -c $CONFIG -s 4.0
after_success:
- if [ "$CONFIG" = "gcov" ] ; then coveralls --exclude third_party --exclude gens -b. --gcov-options '\-p' ; fi
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..e5822c7
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,565 @@
+# GRPC Bazel BUILD file.
+# This currently builds C and C++ code.
+
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+licenses(["notice"]) # 3-clause BSD
+
+
+
+cc_library(
+ name = "gpr",
+ srcs = [
+ "src/core/support/env.h",
+ "src/core/support/file.h",
+ "src/core/support/murmur_hash.h",
+ "src/core/support/string.h",
+ "src/core/support/string_win32.h",
+ "src/core/support/thd_internal.h",
+ "src/core/support/alloc.c",
+ "src/core/support/cancellable.c",
+ "src/core/support/cmdline.c",
+ "src/core/support/cpu_iphone.c",
+ "src/core/support/cpu_linux.c",
+ "src/core/support/cpu_posix.c",
+ "src/core/support/cpu_windows.c",
+ "src/core/support/env_linux.c",
+ "src/core/support/env_posix.c",
+ "src/core/support/env_win32.c",
+ "src/core/support/file.c",
+ "src/core/support/file_posix.c",
+ "src/core/support/file_win32.c",
+ "src/core/support/histogram.c",
+ "src/core/support/host_port.c",
+ "src/core/support/log.c",
+ "src/core/support/log_android.c",
+ "src/core/support/log_linux.c",
+ "src/core/support/log_posix.c",
+ "src/core/support/log_win32.c",
+ "src/core/support/murmur_hash.c",
+ "src/core/support/slice.c",
+ "src/core/support/slice_buffer.c",
+ "src/core/support/string.c",
+ "src/core/support/string_posix.c",
+ "src/core/support/string_win32.c",
+ "src/core/support/sync.c",
+ "src/core/support/sync_posix.c",
+ "src/core/support/sync_win32.c",
+ "src/core/support/thd_posix.c",
+ "src/core/support/thd_win32.c",
+ "src/core/support/time.c",
+ "src/core/support/time_posix.c",
+ "src/core/support/time_win32.c",
+ ],
+ hdrs = [
+ "include/grpc/support/alloc.h",
+ "include/grpc/support/atm.h",
+ "include/grpc/support/atm_gcc_atomic.h",
+ "include/grpc/support/atm_gcc_sync.h",
+ "include/grpc/support/atm_win32.h",
+ "include/grpc/support/cancellable_platform.h",
+ "include/grpc/support/cmdline.h",
+ "include/grpc/support/cpu.h",
+ "include/grpc/support/histogram.h",
+ "include/grpc/support/host_port.h",
+ "include/grpc/support/log.h",
+ "include/grpc/support/log_win32.h",
+ "include/grpc/support/port_platform.h",
+ "include/grpc/support/slice.h",
+ "include/grpc/support/slice_buffer.h",
+ "include/grpc/support/sync.h",
+ "include/grpc/support/sync_generic.h",
+ "include/grpc/support/sync_posix.h",
+ "include/grpc/support/sync_win32.h",
+ "include/grpc/support/thd.h",
+ "include/grpc/support/time.h",
+ "include/grpc/support/useful.h",
+ ],
+ includes = [
+ "include",
+ ".",
+ ],
+ deps = [
+ ],
+)
+
+
+
+
+cc_library(
+ name = "grpc",
+ srcs = [
+ "src/core/httpcli/format_request.h",
+ "src/core/httpcli/httpcli.h",
+ "src/core/httpcli/httpcli_security_context.h",
+ "src/core/httpcli/parser.h",
+ "src/core/security/auth.h",
+ "src/core/security/base64.h",
+ "src/core/security/credentials.h",
+ "src/core/security/json_token.h",
+ "src/core/security/secure_endpoint.h",
+ "src/core/security/secure_transport_setup.h",
+ "src/core/security/security_context.h",
+ "src/core/tsi/fake_transport_security.h",
+ "src/core/tsi/ssl_transport_security.h",
+ "src/core/tsi/transport_security.h",
+ "src/core/tsi/transport_security_interface.h",
+ "src/core/channel/census_filter.h",
+ "src/core/channel/channel_args.h",
+ "src/core/channel/channel_stack.h",
+ "src/core/channel/child_channel.h",
+ "src/core/channel/client_channel.h",
+ "src/core/channel/client_setup.h",
+ "src/core/channel/connected_channel.h",
+ "src/core/channel/http_client_filter.h",
+ "src/core/channel/http_filter.h",
+ "src/core/channel/http_server_filter.h",
+ "src/core/channel/metadata_buffer.h",
+ "src/core/channel/noop_filter.h",
+ "src/core/compression/algorithm.h",
+ "src/core/compression/message_compress.h",
+ "src/core/debug/trace.h",
+ "src/core/iomgr/alarm.h",
+ "src/core/iomgr/alarm_heap.h",
+ "src/core/iomgr/alarm_internal.h",
+ "src/core/iomgr/endpoint.h",
+ "src/core/iomgr/endpoint_pair.h",
+ "src/core/iomgr/fd_posix.h",
+ "src/core/iomgr/iocp_windows.h",
+ "src/core/iomgr/iomgr.h",
+ "src/core/iomgr/iomgr_internal.h",
+ "src/core/iomgr/iomgr_posix.h",
+ "src/core/iomgr/pollset.h",
+ "src/core/iomgr/pollset_kick.h",
+ "src/core/iomgr/pollset_kick_posix.h",
+ "src/core/iomgr/pollset_kick_windows.h",
+ "src/core/iomgr/pollset_posix.h",
+ "src/core/iomgr/pollset_windows.h",
+ "src/core/iomgr/resolve_address.h",
+ "src/core/iomgr/sockaddr.h",
+ "src/core/iomgr/sockaddr_posix.h",
+ "src/core/iomgr/sockaddr_utils.h",
+ "src/core/iomgr/sockaddr_win32.h",
+ "src/core/iomgr/socket_utils_posix.h",
+ "src/core/iomgr/socket_windows.h",
+ "src/core/iomgr/tcp_client.h",
+ "src/core/iomgr/tcp_posix.h",
+ "src/core/iomgr/tcp_server.h",
+ "src/core/iomgr/tcp_windows.h",
+ "src/core/iomgr/time_averaged_stats.h",
+ "src/core/iomgr/wakeup_fd_pipe.h",
+ "src/core/iomgr/wakeup_fd_posix.h",
+ "src/core/json/json.h",
+ "src/core/json/json_common.h",
+ "src/core/json/json_reader.h",
+ "src/core/json/json_writer.h",
+ "src/core/statistics/census_interface.h",
+ "src/core/statistics/census_log.h",
+ "src/core/statistics/census_rpc_stats.h",
+ "src/core/statistics/census_tracing.h",
+ "src/core/statistics/hash_table.h",
+ "src/core/statistics/window_stats.h",
+ "src/core/surface/byte_buffer_queue.h",
+ "src/core/surface/call.h",
+ "src/core/surface/channel.h",
+ "src/core/surface/client.h",
+ "src/core/surface/completion_queue.h",
+ "src/core/surface/event_string.h",
+ "src/core/surface/init.h",
+ "src/core/surface/server.h",
+ "src/core/surface/surface_trace.h",
+ "src/core/transport/chttp2/alpn.h",
+ "src/core/transport/chttp2/bin_encoder.h",
+ "src/core/transport/chttp2/frame.h",
+ "src/core/transport/chttp2/frame_data.h",
+ "src/core/transport/chttp2/frame_goaway.h",
+ "src/core/transport/chttp2/frame_ping.h",
+ "src/core/transport/chttp2/frame_rst_stream.h",
+ "src/core/transport/chttp2/frame_settings.h",
+ "src/core/transport/chttp2/frame_window_update.h",
+ "src/core/transport/chttp2/hpack_parser.h",
+ "src/core/transport/chttp2/hpack_table.h",
+ "src/core/transport/chttp2/http2_errors.h",
+ "src/core/transport/chttp2/huffsyms.h",
+ "src/core/transport/chttp2/status_conversion.h",
+ "src/core/transport/chttp2/stream_encoder.h",
+ "src/core/transport/chttp2/stream_map.h",
+ "src/core/transport/chttp2/timeout_encoding.h",
+ "src/core/transport/chttp2/varint.h",
+ "src/core/transport/chttp2_transport.h",
+ "src/core/transport/metadata.h",
+ "src/core/transport/stream_op.h",
+ "src/core/transport/transport.h",
+ "src/core/transport/transport_impl.h",
+ "src/core/httpcli/format_request.c",
+ "src/core/httpcli/httpcli.c",
+ "src/core/httpcli/httpcli_security_context.c",
+ "src/core/httpcli/parser.c",
+ "src/core/security/auth.c",
+ "src/core/security/base64.c",
+ "src/core/security/credentials.c",
+ "src/core/security/credentials_posix.c",
+ "src/core/security/credentials_win32.c",
+ "src/core/security/factories.c",
+ "src/core/security/google_default_credentials.c",
+ "src/core/security/json_token.c",
+ "src/core/security/secure_endpoint.c",
+ "src/core/security/secure_transport_setup.c",
+ "src/core/security/security_context.c",
+ "src/core/security/server_secure_chttp2.c",
+ "src/core/surface/init_secure.c",
+ "src/core/surface/secure_channel_create.c",
+ "src/core/tsi/fake_transport_security.c",
+ "src/core/tsi/ssl_transport_security.c",
+ "src/core/tsi/transport_security.c",
+ "src/core/channel/call_op_string.c",
+ "src/core/channel/census_filter.c",
+ "src/core/channel/channel_args.c",
+ "src/core/channel/channel_stack.c",
+ "src/core/channel/child_channel.c",
+ "src/core/channel/client_channel.c",
+ "src/core/channel/client_setup.c",
+ "src/core/channel/connected_channel.c",
+ "src/core/channel/http_client_filter.c",
+ "src/core/channel/http_filter.c",
+ "src/core/channel/http_server_filter.c",
+ "src/core/channel/metadata_buffer.c",
+ "src/core/channel/noop_filter.c",
+ "src/core/compression/algorithm.c",
+ "src/core/compression/message_compress.c",
+ "src/core/debug/trace.c",
+ "src/core/iomgr/alarm.c",
+ "src/core/iomgr/alarm_heap.c",
+ "src/core/iomgr/endpoint.c",
+ "src/core/iomgr/endpoint_pair_posix.c",
+ "src/core/iomgr/fd_posix.c",
+ "src/core/iomgr/iocp_windows.c",
+ "src/core/iomgr/iomgr.c",
+ "src/core/iomgr/iomgr_posix.c",
+ "src/core/iomgr/iomgr_windows.c",
+ "src/core/iomgr/pollset_kick.c",
+ "src/core/iomgr/pollset_multipoller_with_epoll.c",
+ "src/core/iomgr/pollset_multipoller_with_poll_posix.c",
+ "src/core/iomgr/pollset_posix.c",
+ "src/core/iomgr/pollset_windows.c",
+ "src/core/iomgr/resolve_address_posix.c",
+ "src/core/iomgr/resolve_address_windows.c",
+ "src/core/iomgr/sockaddr_utils.c",
+ "src/core/iomgr/socket_utils_common_posix.c",
+ "src/core/iomgr/socket_utils_linux.c",
+ "src/core/iomgr/socket_utils_posix.c",
+ "src/core/iomgr/socket_windows.c",
+ "src/core/iomgr/tcp_client_posix.c",
+ "src/core/iomgr/tcp_client_windows.c",
+ "src/core/iomgr/tcp_posix.c",
+ "src/core/iomgr/tcp_server_posix.c",
+ "src/core/iomgr/tcp_server_windows.c",
+ "src/core/iomgr/tcp_windows.c",
+ "src/core/iomgr/time_averaged_stats.c",
+ "src/core/iomgr/wakeup_fd_eventfd.c",
+ "src/core/iomgr/wakeup_fd_nospecial.c",
+ "src/core/iomgr/wakeup_fd_pipe.c",
+ "src/core/iomgr/wakeup_fd_posix.c",
+ "src/core/json/json.c",
+ "src/core/json/json_reader.c",
+ "src/core/json/json_string.c",
+ "src/core/json/json_writer.c",
+ "src/core/statistics/census_init.c",
+ "src/core/statistics/census_log.c",
+ "src/core/statistics/census_rpc_stats.c",
+ "src/core/statistics/census_tracing.c",
+ "src/core/statistics/hash_table.c",
+ "src/core/statistics/window_stats.c",
+ "src/core/surface/byte_buffer.c",
+ "src/core/surface/byte_buffer_queue.c",
+ "src/core/surface/byte_buffer_reader.c",
+ "src/core/surface/call.c",
+ "src/core/surface/call_details.c",
+ "src/core/surface/call_log_batch.c",
+ "src/core/surface/channel.c",
+ "src/core/surface/channel_create.c",
+ "src/core/surface/client.c",
+ "src/core/surface/completion_queue.c",
+ "src/core/surface/event_string.c",
+ "src/core/surface/init.c",
+ "src/core/surface/lame_client.c",
+ "src/core/surface/metadata_array.c",
+ "src/core/surface/server.c",
+ "src/core/surface/server_chttp2.c",
+ "src/core/surface/server_create.c",
+ "src/core/surface/surface_trace.c",
+ "src/core/transport/chttp2/alpn.c",
+ "src/core/transport/chttp2/bin_encoder.c",
+ "src/core/transport/chttp2/frame_data.c",
+ "src/core/transport/chttp2/frame_goaway.c",
+ "src/core/transport/chttp2/frame_ping.c",
+ "src/core/transport/chttp2/frame_rst_stream.c",
+ "src/core/transport/chttp2/frame_settings.c",
+ "src/core/transport/chttp2/frame_window_update.c",
+ "src/core/transport/chttp2/hpack_parser.c",
+ "src/core/transport/chttp2/hpack_table.c",
+ "src/core/transport/chttp2/huffsyms.c",
+ "src/core/transport/chttp2/status_conversion.c",
+ "src/core/transport/chttp2/stream_encoder.c",
+ "src/core/transport/chttp2/stream_map.c",
+ "src/core/transport/chttp2/timeout_encoding.c",
+ "src/core/transport/chttp2/varint.c",
+ "src/core/transport/chttp2_transport.c",
+ "src/core/transport/metadata.c",
+ "src/core/transport/stream_op.c",
+ "src/core/transport/transport.c",
+ ],
+ hdrs = [
+ "include/grpc/grpc_security.h",
+ "include/grpc/byte_buffer.h",
+ "include/grpc/byte_buffer_reader.h",
+ "include/grpc/grpc.h",
+ "include/grpc/grpc_http.h",
+ "include/grpc/status.h",
+ ],
+ includes = [
+ "include",
+ ".",
+ ],
+ deps = [
+ ":gpr",
+ ],
+)
+
+
+
+
+cc_library(
+ name = "grpc_unsecure",
+ srcs = [
+ "src/core/channel/census_filter.h",
+ "src/core/channel/channel_args.h",
+ "src/core/channel/channel_stack.h",
+ "src/core/channel/child_channel.h",
+ "src/core/channel/client_channel.h",
+ "src/core/channel/client_setup.h",
+ "src/core/channel/connected_channel.h",
+ "src/core/channel/http_client_filter.h",
+ "src/core/channel/http_filter.h",
+ "src/core/channel/http_server_filter.h",
+ "src/core/channel/metadata_buffer.h",
+ "src/core/channel/noop_filter.h",
+ "src/core/compression/algorithm.h",
+ "src/core/compression/message_compress.h",
+ "src/core/debug/trace.h",
+ "src/core/iomgr/alarm.h",
+ "src/core/iomgr/alarm_heap.h",
+ "src/core/iomgr/alarm_internal.h",
+ "src/core/iomgr/endpoint.h",
+ "src/core/iomgr/endpoint_pair.h",
+ "src/core/iomgr/fd_posix.h",
+ "src/core/iomgr/iocp_windows.h",
+ "src/core/iomgr/iomgr.h",
+ "src/core/iomgr/iomgr_internal.h",
+ "src/core/iomgr/iomgr_posix.h",
+ "src/core/iomgr/pollset.h",
+ "src/core/iomgr/pollset_kick.h",
+ "src/core/iomgr/pollset_kick_posix.h",
+ "src/core/iomgr/pollset_kick_windows.h",
+ "src/core/iomgr/pollset_posix.h",
+ "src/core/iomgr/pollset_windows.h",
+ "src/core/iomgr/resolve_address.h",
+ "src/core/iomgr/sockaddr.h",
+ "src/core/iomgr/sockaddr_posix.h",
+ "src/core/iomgr/sockaddr_utils.h",
+ "src/core/iomgr/sockaddr_win32.h",
+ "src/core/iomgr/socket_utils_posix.h",
+ "src/core/iomgr/socket_windows.h",
+ "src/core/iomgr/tcp_client.h",
+ "src/core/iomgr/tcp_posix.h",
+ "src/core/iomgr/tcp_server.h",
+ "src/core/iomgr/tcp_windows.h",
+ "src/core/iomgr/time_averaged_stats.h",
+ "src/core/iomgr/wakeup_fd_pipe.h",
+ "src/core/iomgr/wakeup_fd_posix.h",
+ "src/core/json/json.h",
+ "src/core/json/json_common.h",
+ "src/core/json/json_reader.h",
+ "src/core/json/json_writer.h",
+ "src/core/statistics/census_interface.h",
+ "src/core/statistics/census_log.h",
+ "src/core/statistics/census_rpc_stats.h",
+ "src/core/statistics/census_tracing.h",
+ "src/core/statistics/hash_table.h",
+ "src/core/statistics/window_stats.h",
+ "src/core/surface/byte_buffer_queue.h",
+ "src/core/surface/call.h",
+ "src/core/surface/channel.h",
+ "src/core/surface/client.h",
+ "src/core/surface/completion_queue.h",
+ "src/core/surface/event_string.h",
+ "src/core/surface/init.h",
+ "src/core/surface/server.h",
+ "src/core/surface/surface_trace.h",
+ "src/core/transport/chttp2/alpn.h",
+ "src/core/transport/chttp2/bin_encoder.h",
+ "src/core/transport/chttp2/frame.h",
+ "src/core/transport/chttp2/frame_data.h",
+ "src/core/transport/chttp2/frame_goaway.h",
+ "src/core/transport/chttp2/frame_ping.h",
+ "src/core/transport/chttp2/frame_rst_stream.h",
+ "src/core/transport/chttp2/frame_settings.h",
+ "src/core/transport/chttp2/frame_window_update.h",
+ "src/core/transport/chttp2/hpack_parser.h",
+ "src/core/transport/chttp2/hpack_table.h",
+ "src/core/transport/chttp2/http2_errors.h",
+ "src/core/transport/chttp2/huffsyms.h",
+ "src/core/transport/chttp2/status_conversion.h",
+ "src/core/transport/chttp2/stream_encoder.h",
+ "src/core/transport/chttp2/stream_map.h",
+ "src/core/transport/chttp2/timeout_encoding.h",
+ "src/core/transport/chttp2/varint.h",
+ "src/core/transport/chttp2_transport.h",
+ "src/core/transport/metadata.h",
+ "src/core/transport/stream_op.h",
+ "src/core/transport/transport.h",
+ "src/core/transport/transport_impl.h",
+ "src/core/surface/init_unsecure.c",
+ "src/core/channel/call_op_string.c",
+ "src/core/channel/census_filter.c",
+ "src/core/channel/channel_args.c",
+ "src/core/channel/channel_stack.c",
+ "src/core/channel/child_channel.c",
+ "src/core/channel/client_channel.c",
+ "src/core/channel/client_setup.c",
+ "src/core/channel/connected_channel.c",
+ "src/core/channel/http_client_filter.c",
+ "src/core/channel/http_filter.c",
+ "src/core/channel/http_server_filter.c",
+ "src/core/channel/metadata_buffer.c",
+ "src/core/channel/noop_filter.c",
+ "src/core/compression/algorithm.c",
+ "src/core/compression/message_compress.c",
+ "src/core/debug/trace.c",
+ "src/core/iomgr/alarm.c",
+ "src/core/iomgr/alarm_heap.c",
+ "src/core/iomgr/endpoint.c",
+ "src/core/iomgr/endpoint_pair_posix.c",
+ "src/core/iomgr/fd_posix.c",
+ "src/core/iomgr/iocp_windows.c",
+ "src/core/iomgr/iomgr.c",
+ "src/core/iomgr/iomgr_posix.c",
+ "src/core/iomgr/iomgr_windows.c",
+ "src/core/iomgr/pollset_kick.c",
+ "src/core/iomgr/pollset_multipoller_with_epoll.c",
+ "src/core/iomgr/pollset_multipoller_with_poll_posix.c",
+ "src/core/iomgr/pollset_posix.c",
+ "src/core/iomgr/pollset_windows.c",
+ "src/core/iomgr/resolve_address_posix.c",
+ "src/core/iomgr/resolve_address_windows.c",
+ "src/core/iomgr/sockaddr_utils.c",
+ "src/core/iomgr/socket_utils_common_posix.c",
+ "src/core/iomgr/socket_utils_linux.c",
+ "src/core/iomgr/socket_utils_posix.c",
+ "src/core/iomgr/socket_windows.c",
+ "src/core/iomgr/tcp_client_posix.c",
+ "src/core/iomgr/tcp_client_windows.c",
+ "src/core/iomgr/tcp_posix.c",
+ "src/core/iomgr/tcp_server_posix.c",
+ "src/core/iomgr/tcp_server_windows.c",
+ "src/core/iomgr/tcp_windows.c",
+ "src/core/iomgr/time_averaged_stats.c",
+ "src/core/iomgr/wakeup_fd_eventfd.c",
+ "src/core/iomgr/wakeup_fd_nospecial.c",
+ "src/core/iomgr/wakeup_fd_pipe.c",
+ "src/core/iomgr/wakeup_fd_posix.c",
+ "src/core/json/json.c",
+ "src/core/json/json_reader.c",
+ "src/core/json/json_string.c",
+ "src/core/json/json_writer.c",
+ "src/core/statistics/census_init.c",
+ "src/core/statistics/census_log.c",
+ "src/core/statistics/census_rpc_stats.c",
+ "src/core/statistics/census_tracing.c",
+ "src/core/statistics/hash_table.c",
+ "src/core/statistics/window_stats.c",
+ "src/core/surface/byte_buffer.c",
+ "src/core/surface/byte_buffer_queue.c",
+ "src/core/surface/byte_buffer_reader.c",
+ "src/core/surface/call.c",
+ "src/core/surface/call_details.c",
+ "src/core/surface/call_log_batch.c",
+ "src/core/surface/channel.c",
+ "src/core/surface/channel_create.c",
+ "src/core/surface/client.c",
+ "src/core/surface/completion_queue.c",
+ "src/core/surface/event_string.c",
+ "src/core/surface/init.c",
+ "src/core/surface/lame_client.c",
+ "src/core/surface/metadata_array.c",
+ "src/core/surface/server.c",
+ "src/core/surface/server_chttp2.c",
+ "src/core/surface/server_create.c",
+ "src/core/surface/surface_trace.c",
+ "src/core/transport/chttp2/alpn.c",
+ "src/core/transport/chttp2/bin_encoder.c",
+ "src/core/transport/chttp2/frame_data.c",
+ "src/core/transport/chttp2/frame_goaway.c",
+ "src/core/transport/chttp2/frame_ping.c",
+ "src/core/transport/chttp2/frame_rst_stream.c",
+ "src/core/transport/chttp2/frame_settings.c",
+ "src/core/transport/chttp2/frame_window_update.c",
+ "src/core/transport/chttp2/hpack_parser.c",
+ "src/core/transport/chttp2/hpack_table.c",
+ "src/core/transport/chttp2/huffsyms.c",
+ "src/core/transport/chttp2/status_conversion.c",
+ "src/core/transport/chttp2/stream_encoder.c",
+ "src/core/transport/chttp2/stream_map.c",
+ "src/core/transport/chttp2/timeout_encoding.c",
+ "src/core/transport/chttp2/varint.c",
+ "src/core/transport/chttp2_transport.c",
+ "src/core/transport/metadata.c",
+ "src/core/transport/stream_op.c",
+ "src/core/transport/transport.c",
+ ],
+ hdrs = [
+ "include/grpc/byte_buffer.h",
+ "include/grpc/byte_buffer_reader.h",
+ "include/grpc/grpc.h",
+ "include/grpc/grpc_http.h",
+ "include/grpc/status.h",
+ ],
+ includes = [
+ "include",
+ ".",
+ ],
+ deps = [
+ ":gpr",
+ ],
+)
+
+
+
+
diff --git a/Makefile b/Makefile
index 0742994..0b2fe07 100644
--- a/Makefile
+++ b/Makefile
@@ -616,10 +616,12 @@
transport_security_test: $(BINDIR)/$(CONFIG)/transport_security_test
async_end2end_test: $(BINDIR)/$(CONFIG)/async_end2end_test
channel_arguments_test: $(BINDIR)/$(CONFIG)/channel_arguments_test
+cli_call_test: $(BINDIR)/$(CONFIG)/cli_call_test
credentials_test: $(BINDIR)/$(CONFIG)/credentials_test
cxx_time_test: $(BINDIR)/$(CONFIG)/cxx_time_test
end2end_test: $(BINDIR)/$(CONFIG)/end2end_test
generic_end2end_test: $(BINDIR)/$(CONFIG)/generic_end2end_test
+grpc_cli: $(BINDIR)/$(CONFIG)/grpc_cli
grpc_cpp_plugin: $(BINDIR)/$(CONFIG)/grpc_cpp_plugin
grpc_python_plugin: $(BINDIR)/$(CONFIG)/grpc_python_plugin
grpc_ruby_plugin: $(BINDIR)/$(CONFIG)/grpc_ruby_plugin
@@ -1070,7 +1072,7 @@
buildtests_c: privatelibs_c $(BINDIR)/$(CONFIG)/alarm_heap_test $(BINDIR)/$(CONFIG)/alarm_list_test $(BINDIR)/$(CONFIG)/alarm_test $(BINDIR)/$(CONFIG)/alpn_test $(BINDIR)/$(CONFIG)/bin_encoder_test $(BINDIR)/$(CONFIG)/census_hash_table_test $(BINDIR)/$(CONFIG)/census_statistics_multiple_writers_circular_buffer_test $(BINDIR)/$(CONFIG)/census_statistics_multiple_writers_test $(BINDIR)/$(CONFIG)/census_statistics_performance_test $(BINDIR)/$(CONFIG)/census_statistics_quick_test $(BINDIR)/$(CONFIG)/census_statistics_small_log_test $(BINDIR)/$(CONFIG)/census_stub_test $(BINDIR)/$(CONFIG)/census_window_stats_test $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test $(BINDIR)/$(CONFIG)/chttp2_stream_encoder_test $(BINDIR)/$(CONFIG)/chttp2_stream_map_test $(BINDIR)/$(CONFIG)/chttp2_transport_end2end_test $(BINDIR)/$(CONFIG)/dualstack_socket_test $(BINDIR)/$(CONFIG)/echo_client $(BINDIR)/$(CONFIG)/echo_server $(BINDIR)/$(CONFIG)/echo_test $(BINDIR)/$(CONFIG)/fd_posix_test $(BINDIR)/$(CONFIG)/fling_client $(BINDIR)/$(CONFIG)/fling_server $(BINDIR)/$(CONFIG)/fling_stream_test $(BINDIR)/$(CONFIG)/fling_test $(BINDIR)/$(CONFIG)/gpr_cancellable_test $(BINDIR)/$(CONFIG)/gpr_cmdline_test $(BINDIR)/$(CONFIG)/gpr_env_test $(BINDIR)/$(CONFIG)/gpr_file_test $(BINDIR)/$(CONFIG)/gpr_histogram_test $(BINDIR)/$(CONFIG)/gpr_host_port_test $(BINDIR)/$(CONFIG)/gpr_log_test $(BINDIR)/$(CONFIG)/gpr_slice_buffer_test $(BINDIR)/$(CONFIG)/gpr_slice_test $(BINDIR)/$(CONFIG)/gpr_string_test $(BINDIR)/$(CONFIG)/gpr_sync_test $(BINDIR)/$(CONFIG)/gpr_thd_test $(BINDIR)/$(CONFIG)/gpr_time_test $(BINDIR)/$(CONFIG)/gpr_useful_test $(BINDIR)/$(CONFIG)/grpc_base64_test $(BINDIR)/$(CONFIG)/grpc_byte_buffer_reader_test $(BINDIR)/$(CONFIG)/grpc_channel_stack_test $(BINDIR)/$(CONFIG)/grpc_completion_queue_test $(BINDIR)/$(CONFIG)/grpc_credentials_test $(BINDIR)/$(CONFIG)/grpc_json_token_test $(BINDIR)/$(CONFIG)/grpc_stream_op_test $(BINDIR)/$(CONFIG)/hpack_parser_test $(BINDIR)/$(CONFIG)/hpack_table_test $(BINDIR)/$(CONFIG)/httpcli_format_request_test $(BINDIR)/$(CONFIG)/httpcli_parser_test $(BINDIR)/$(CONFIG)/httpcli_test $(BINDIR)/$(CONFIG)/json_rewrite $(BINDIR)/$(CONFIG)/json_rewrite_test $(BINDIR)/$(CONFIG)/json_test $(BINDIR)/$(CONFIG)/lame_client_test $(BINDIR)/$(CONFIG)/message_compress_test $(BINDIR)/$(CONFIG)/metadata_buffer_test $(BINDIR)/$(CONFIG)/multi_init_test $(BINDIR)/$(CONFIG)/murmur_hash_test $(BINDIR)/$(CONFIG)/no_server_test $(BINDIR)/$(CONFIG)/poll_kick_posix_test $(BINDIR)/$(CONFIG)/resolve_address_test $(BINDIR)/$(CONFIG)/secure_endpoint_test $(BINDIR)/$(CONFIG)/sockaddr_utils_test $(BINDIR)/$(CONFIG)/tcp_client_posix_test $(BINDIR)/$(CONFIG)/tcp_posix_test $(BINDIR)/$(CONFIG)/tcp_server_posix_test $(BINDIR)/$(CONFIG)/time_averaged_stats_test $(BINDIR)/$(CONFIG)/time_test $(BINDIR)/$(CONFIG)/timeout_encoding_test $(BINDIR)/$(CONFIG)/transport_metadata_test $(BINDIR)/$(CONFIG)/transport_security_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_bad_hostname_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_after_accept_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_after_accept_and_writes_closed_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_after_invoke_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_before_invoke_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_in_a_vacuum_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_census_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_disappearing_server_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_early_server_shutdown_finishes_inflight_calls_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_early_server_shutdown_finishes_tags_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_empty_batch_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_graceful_server_shutdown_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_invoke_large_request_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_max_concurrent_streams_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_no_op_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_ping_pong_streaming_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_response_with_binary_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_response_with_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_response_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_with_large_metadata_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_simple_delayed_request_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_thread_stress_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_writes_done_hangs_with_pending_read_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_after_accept_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_after_accept_and_writes_closed_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_after_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_before_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_cancel_in_a_vacuum_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_census_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_disappearing_server_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_early_server_shutdown_finishes_inflight_calls_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_early_server_shutdown_finishes_tags_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_graceful_server_shutdown_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_invoke_large_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_max_concurrent_streams_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_no_op_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_ping_pong_streaming_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_response_with_binary_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_response_with_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_response_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_response_with_trailing_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_with_large_metadata_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_request_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_simple_delayed_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_thread_stress_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fake_security_writes_done_hangs_with_pending_read_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_bad_hostname_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_after_accept_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_after_accept_and_writes_closed_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_after_invoke_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_before_invoke_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_in_a_vacuum_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_census_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_disappearing_server_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_early_server_shutdown_finishes_inflight_calls_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_early_server_shutdown_finishes_tags_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_empty_batch_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_graceful_server_shutdown_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_invoke_large_request_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_max_concurrent_streams_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_no_op_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_ping_pong_streaming_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_response_with_binary_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_response_with_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_response_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_with_large_metadata_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_simple_delayed_request_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_thread_stress_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_writes_done_hangs_with_pending_read_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_after_accept_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_after_accept_and_writes_closed_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_after_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_before_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_cancel_in_a_vacuum_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_census_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_disappearing_server_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_early_server_shutdown_finishes_inflight_calls_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_early_server_shutdown_finishes_tags_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_graceful_server_shutdown_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_invoke_large_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_max_concurrent_streams_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_no_op_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_ping_pong_streaming_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_response_with_binary_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_response_with_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_response_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_response_with_trailing_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_with_large_metadata_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_request_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_simple_delayed_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_thread_stress_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_writes_done_hangs_with_pending_read_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_bad_hostname_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_after_accept_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_after_accept_and_writes_closed_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_after_invoke_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_before_invoke_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_in_a_vacuum_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_census_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_disappearing_server_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_early_server_shutdown_finishes_inflight_calls_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_early_server_shutdown_finishes_tags_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_empty_batch_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_graceful_server_shutdown_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_invoke_large_request_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_max_concurrent_streams_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_no_op_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_ping_pong_streaming_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_response_with_binary_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_response_with_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_response_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_with_large_metadata_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_simple_delayed_request_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_thread_stress_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_writes_done_hangs_with_pending_read_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_after_accept_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_after_accept_and_writes_closed_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_after_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_before_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_cancel_in_a_vacuum_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_census_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_disappearing_server_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_early_server_shutdown_finishes_inflight_calls_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_early_server_shutdown_finishes_tags_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_graceful_server_shutdown_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_invoke_large_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_max_concurrent_streams_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_no_op_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_ping_pong_streaming_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_response_with_binary_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_response_with_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_response_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_response_with_trailing_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_with_large_metadata_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_request_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_simple_delayed_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_thread_stress_legacy_test $(BINDIR)/$(CONFIG)/chttp2_fullstack_uds_writes_done_hangs_with_pending_read_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_bad_hostname_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_accept_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_accept_and_writes_closed_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_invoke_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_before_invoke_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_in_a_vacuum_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_census_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_disappearing_server_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_early_server_shutdown_finishes_inflight_calls_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_early_server_shutdown_finishes_tags_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_empty_batch_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_graceful_server_shutdown_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_invoke_large_request_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_max_concurrent_streams_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_no_op_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_ping_pong_streaming_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_binary_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_with_large_metadata_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_simple_delayed_request_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_thread_stress_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_writes_done_hangs_with_pending_read_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_accept_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_accept_and_writes_closed_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_before_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_in_a_vacuum_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_census_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_disappearing_server_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_early_server_shutdown_finishes_inflight_calls_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_early_server_shutdown_finishes_tags_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_graceful_server_shutdown_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_invoke_large_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_max_concurrent_streams_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_no_op_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_ping_pong_streaming_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_binary_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_trailing_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_with_large_metadata_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_request_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_simple_delayed_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_thread_stress_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_fullstack_writes_done_hangs_with_pending_read_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_bad_hostname_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_and_writes_closed_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_invoke_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_before_invoke_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_in_a_vacuum_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_census_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_disappearing_server_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_early_server_shutdown_finishes_inflight_calls_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_early_server_shutdown_finishes_tags_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_empty_batch_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_graceful_server_shutdown_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_invoke_large_request_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_max_concurrent_streams_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_no_op_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_ping_pong_streaming_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_binary_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_with_large_metadata_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_simple_delayed_request_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_thread_stress_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_writes_done_hangs_with_pending_read_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_and_writes_closed_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_before_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_in_a_vacuum_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_census_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_disappearing_server_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_early_server_shutdown_finishes_inflight_calls_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_early_server_shutdown_finishes_tags_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_graceful_server_shutdown_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_invoke_large_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_max_concurrent_streams_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_no_op_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_ping_pong_streaming_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_binary_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_trailing_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_with_large_metadata_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_simple_delayed_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_thread_stress_legacy_test $(BINDIR)/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_writes_done_hangs_with_pending_read_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_bad_hostname_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_after_accept_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_after_accept_and_writes_closed_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_after_invoke_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_before_invoke_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_in_a_vacuum_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_census_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_disappearing_server_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_early_server_shutdown_finishes_inflight_calls_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_early_server_shutdown_finishes_tags_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_empty_batch_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_graceful_server_shutdown_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_invoke_large_request_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_max_concurrent_streams_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_no_op_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_ping_pong_streaming_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_response_with_binary_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_response_with_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_response_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_with_large_metadata_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_simple_delayed_request_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_thread_stress_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_writes_done_hangs_with_pending_read_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_after_accept_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_after_accept_and_writes_closed_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_after_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_before_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_cancel_in_a_vacuum_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_census_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_disappearing_server_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_early_server_shutdown_finishes_inflight_calls_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_early_server_shutdown_finishes_tags_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_graceful_server_shutdown_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_invoke_large_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_max_concurrent_streams_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_no_op_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_ping_pong_streaming_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_response_with_binary_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_response_with_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_response_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_response_with_trailing_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_with_large_metadata_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_request_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_simple_delayed_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_thread_stress_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_writes_done_hangs_with_pending_read_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_bad_hostname_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_and_writes_closed_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_invoke_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_before_invoke_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_in_a_vacuum_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_census_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_disappearing_server_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_early_server_shutdown_finishes_inflight_calls_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_early_server_shutdown_finishes_tags_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_empty_batch_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_graceful_server_shutdown_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_invoke_large_request_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_max_concurrent_streams_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_no_op_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_ping_pong_streaming_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_binary_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_metadata_and_payload_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_with_large_metadata_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_with_payload_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_simple_delayed_request_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_simple_request_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_thread_stress_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_writes_done_hangs_with_pending_read_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_and_writes_closed_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_before_invoke_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_in_a_vacuum_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_census_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_disappearing_server_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_early_server_shutdown_finishes_inflight_calls_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_early_server_shutdown_finishes_tags_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_graceful_server_shutdown_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_invoke_large_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_max_concurrent_streams_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_no_op_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_ping_pong_streaming_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_binary_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_trailing_metadata_and_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_with_large_metadata_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_with_payload_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_simple_delayed_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_simple_request_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_thread_stress_legacy_test $(BINDIR)/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_writes_done_hangs_with_pending_read_legacy_test
-buildtests_cxx: privatelibs_cxx $(BINDIR)/$(CONFIG)/async_end2end_test $(BINDIR)/$(CONFIG)/channel_arguments_test $(BINDIR)/$(CONFIG)/credentials_test $(BINDIR)/$(CONFIG)/cxx_time_test $(BINDIR)/$(CONFIG)/end2end_test $(BINDIR)/$(CONFIG)/generic_end2end_test $(BINDIR)/$(CONFIG)/interop_client $(BINDIR)/$(CONFIG)/interop_server $(BINDIR)/$(CONFIG)/interop_test $(BINDIR)/$(CONFIG)/pubsub_client $(BINDIR)/$(CONFIG)/pubsub_publisher_test $(BINDIR)/$(CONFIG)/pubsub_subscriber_test $(BINDIR)/$(CONFIG)/qps_driver $(BINDIR)/$(CONFIG)/qps_worker $(BINDIR)/$(CONFIG)/status_test $(BINDIR)/$(CONFIG)/thread_pool_test
+buildtests_cxx: privatelibs_cxx $(BINDIR)/$(CONFIG)/async_end2end_test $(BINDIR)/$(CONFIG)/channel_arguments_test $(BINDIR)/$(CONFIG)/cli_call_test $(BINDIR)/$(CONFIG)/credentials_test $(BINDIR)/$(CONFIG)/cxx_time_test $(BINDIR)/$(CONFIG)/end2end_test $(BINDIR)/$(CONFIG)/generic_end2end_test $(BINDIR)/$(CONFIG)/grpc_cli $(BINDIR)/$(CONFIG)/interop_client $(BINDIR)/$(CONFIG)/interop_server $(BINDIR)/$(CONFIG)/interop_test $(BINDIR)/$(CONFIG)/pubsub_client $(BINDIR)/$(CONFIG)/pubsub_publisher_test $(BINDIR)/$(CONFIG)/pubsub_subscriber_test $(BINDIR)/$(CONFIG)/qps_driver $(BINDIR)/$(CONFIG)/qps_worker $(BINDIR)/$(CONFIG)/status_test $(BINDIR)/$(CONFIG)/thread_pool_test
test: test_c test_cxx
@@ -1902,6 +1904,8 @@
$(Q) $(BINDIR)/$(CONFIG)/async_end2end_test || ( echo test async_end2end_test failed ; exit 1 )
$(E) "[RUN] Testing channel_arguments_test"
$(Q) $(BINDIR)/$(CONFIG)/channel_arguments_test || ( echo test channel_arguments_test failed ; exit 1 )
+ $(E) "[RUN] Testing cli_call_test"
+ $(Q) $(BINDIR)/$(CONFIG)/cli_call_test || ( echo test cli_call_test failed ; exit 1 )
$(E) "[RUN] Testing credentials_test"
$(Q) $(BINDIR)/$(CONFIG)/credentials_test || ( echo test credentials_test failed ; exit 1 )
$(E) "[RUN] Testing cxx_time_test"
@@ -2553,6 +2557,7 @@
src/core/surface/byte_buffer_reader.c \
src/core/surface/call.c \
src/core/surface/call_details.c \
+ src/core/surface/call_log_batch.c \
src/core/surface/channel.c \
src/core/surface/channel_create.c \
src/core/surface/client.c \
@@ -2699,6 +2704,7 @@
src/core/surface/byte_buffer_reader.c: $(OPENSSL_DEP)
src/core/surface/call.c: $(OPENSSL_DEP)
src/core/surface/call_details.c: $(OPENSSL_DEP)
+src/core/surface/call_log_batch.c: $(OPENSSL_DEP)
src/core/surface/channel.c: $(OPENSSL_DEP)
src/core/surface/channel_create.c: $(OPENSSL_DEP)
src/core/surface/client.c: $(OPENSSL_DEP)
@@ -2861,6 +2867,7 @@
$(OBJDIR)/$(CONFIG)/src/core/surface/byte_buffer_reader.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/call.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/call_details.o:
+$(OBJDIR)/$(CONFIG)/src/core/surface/call_log_batch.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/channel.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/channel_create.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/client.o:
@@ -3036,6 +3043,7 @@
src/core/surface/byte_buffer_reader.c \
src/core/surface/call.c \
src/core/surface/call_details.c \
+ src/core/surface/call_log_batch.c \
src/core/surface/channel.c \
src/core/surface/channel_create.c \
src/core/surface/client.c \
@@ -3175,6 +3183,7 @@
$(OBJDIR)/$(CONFIG)/src/core/surface/byte_buffer_reader.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/call.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/call_details.o:
+$(OBJDIR)/$(CONFIG)/src/core/surface/call_log_batch.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/channel.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/channel_create.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/client.o:
@@ -3218,6 +3227,7 @@
src/cpp/client/client_unary_call.cc \
src/cpp/client/create_channel.cc \
src/cpp/client/credentials.cc \
+ src/cpp/client/generic_stub.cc \
src/cpp/client/insecure_credentials.cc \
src/cpp/client/internal_stub.cc \
src/cpp/common/call.cc \
@@ -3306,6 +3316,7 @@
src/cpp/client/client_unary_call.cc: $(OPENSSL_DEP)
src/cpp/client/create_channel.cc: $(OPENSSL_DEP)
src/cpp/client/credentials.cc: $(OPENSSL_DEP)
+src/cpp/client/generic_stub.cc: $(OPENSSL_DEP)
src/cpp/client/insecure_credentials.cc: $(OPENSSL_DEP)
src/cpp/client/internal_stub.cc: $(OPENSSL_DEP)
src/cpp/common/call.cc: $(OPENSSL_DEP)
@@ -3372,6 +3383,7 @@
$(OBJDIR)/$(CONFIG)/src/cpp/client/client_unary_call.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/create_channel.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/credentials.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/generic_stub.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/insecure_credentials.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/internal_stub.o:
$(OBJDIR)/$(CONFIG)/src/cpp/common/call.o:
@@ -3395,6 +3407,7 @@
$(GENDIR)/test/cpp/util/messages.pb.cc \
$(GENDIR)/test/cpp/util/echo.pb.cc \
$(GENDIR)/test/cpp/util/echo_duplicate.pb.cc \
+ test/cpp/util/cli_call.cc \
test/cpp/util/create_test_channel.cc \
@@ -3425,6 +3438,7 @@
test/cpp/util/messages.proto: $(OPENSSL_DEP)
test/cpp/util/echo.proto: $(OPENSSL_DEP)
test/cpp/util/echo_duplicate.proto: $(OPENSSL_DEP)
+test/cpp/util/cli_call.cc: $(OPENSSL_DEP)
test/cpp/util/create_test_channel.cc: $(OPENSSL_DEP)
endif
@@ -3453,6 +3467,7 @@
+$(OBJDIR)/$(CONFIG)/test/cpp/util/cli_call.o: $(GENDIR)/test/cpp/util/messages.pb.cc $(GENDIR)/test/cpp/util/echo.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/test/cpp/util/messages.pb.cc $(GENDIR)/test/cpp/util/echo.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.pb.cc
@@ -3463,6 +3478,7 @@
src/cpp/client/client_unary_call.cc \
src/cpp/client/create_channel.cc \
src/cpp/client/credentials.cc \
+ src/cpp/client/generic_stub.cc \
src/cpp/client/insecure_credentials.cc \
src/cpp/client/internal_stub.cc \
src/cpp/common/call.cc \
@@ -3566,6 +3582,7 @@
$(OBJDIR)/$(CONFIG)/src/cpp/client/client_unary_call.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/create_channel.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/credentials.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/generic_stub.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/insecure_credentials.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/internal_stub.o:
$(OBJDIR)/$(CONFIG)/src/cpp/common/call.o:
@@ -3585,30 +3602,30 @@
$(OBJDIR)/$(CONFIG)/src/cpp/util/time.o:
-LIBGRPC_PYTHON_PLUGIN_SUPPORT_SRC = \
+LIBGRPC_PLUGIN_SUPPORT_SRC = \
+ src/compiler/cpp_generator.cc \
src/compiler/python_generator.cc \
+ src/compiler/ruby_generator.cc \
-PUBLIC_HEADERS_CXX += \
- src/compiler/python_generator.h \
-LIBGRPC_PYTHON_PLUGIN_SUPPORT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC_PYTHON_PLUGIN_SUPPORT_SRC))))
+LIBGRPC_PLUGIN_SUPPORT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC_PLUGIN_SUPPORT_SRC))))
ifeq ($(NO_PROTOBUF),true)
# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
-$(LIBDIR)/$(CONFIG)/libgrpc_python_plugin_support.a: protobuf_dep_error
+$(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a: protobuf_dep_error
else
-$(LIBDIR)/$(CONFIG)/libgrpc_python_plugin_support.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBGRPC_PYTHON_PLUGIN_SUPPORT_OBJS)
+$(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBGRPC_PLUGIN_SUPPORT_OBJS)
$(E) "[AR] Creating $@"
$(Q) mkdir -p `dirname $@`
- $(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc_python_plugin_support.a
- $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/libgrpc_python_plugin_support.a $(LIBGRPC_PYTHON_PLUGIN_SUPPORT_OBJS)
+ $(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a
+ $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a $(LIBGRPC_PLUGIN_SUPPORT_OBJS)
ifeq ($(SYSTEM),Darwin)
- $(Q) ranlib $(LIBDIR)/$(CONFIG)/libgrpc_python_plugin_support.a
+ $(Q) ranlib $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a
endif
@@ -3617,10 +3634,12 @@
endif
ifneq ($(NO_DEPS),true)
--include $(LIBGRPC_PYTHON_PLUGIN_SUPPORT_OBJS:.o=.dep)
+-include $(LIBGRPC_PLUGIN_SUPPORT_OBJS:.o=.dep)
endif
+$(OBJDIR)/$(CONFIG)/src/compiler/cpp_generator.o:
$(OBJDIR)/$(CONFIG)/src/compiler/python_generator.o:
+$(OBJDIR)/$(CONFIG)/src/compiler/ruby_generator.o:
LIBPUBSUB_CLIENT_LIB_SRC = \
@@ -8019,6 +8038,48 @@
endif
+CLI_CALL_TEST_SRC = \
+ test/cpp/util/cli_call_test.cc \
+
+CLI_CALL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CLI_CALL_TEST_SRC))))
+
+ifeq ($(NO_SECURE),true)
+
+# You can't build secure targets if you don't have OpenSSL with ALPN.
+
+$(BINDIR)/$(CONFIG)/cli_call_test: openssl_dep_error
+
+else
+
+
+ifeq ($(NO_PROTOBUF),true)
+
+# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
+
+$(BINDIR)/$(CONFIG)/cli_call_test: protobuf_dep_error
+
+else
+
+$(BINDIR)/$(CONFIG)/cli_call_test: $(PROTOBUF_DEP) $(CLI_CALL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
+ $(E) "[LD] Linking $@"
+ $(Q) mkdir -p `dirname $@`
+ $(Q) $(LDXX) $(LDFLAGS) $(CLI_CALL_TEST_OBJS) $(GTEST_LIB) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/cli_call_test
+
+endif
+
+endif
+
+$(OBJDIR)/$(CONFIG)/test/cpp/util/cli_call_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
+
+deps_cli_call_test: $(CLI_CALL_TEST_OBJS:.o=.dep)
+
+ifneq ($(NO_SECURE),true)
+ifneq ($(NO_DEPS),true)
+-include $(CLI_CALL_TEST_OBJS:.o=.dep)
+endif
+endif
+
+
CREDENTIALS_TEST_SRC = \
test/cpp/client/credentials_test.cc \
@@ -8187,8 +8248,49 @@
endif
+GRPC_CLI_SRC = \
+ test/cpp/util/grpc_cli.cc \
+
+GRPC_CLI_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_CLI_SRC))))
+
+ifeq ($(NO_SECURE),true)
+
+# You can't build secure targets if you don't have OpenSSL with ALPN.
+
+$(BINDIR)/$(CONFIG)/grpc_cli: openssl_dep_error
+
+else
+
+
+ifeq ($(NO_PROTOBUF),true)
+
+# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
+
+$(BINDIR)/$(CONFIG)/grpc_cli: protobuf_dep_error
+
+else
+
+$(BINDIR)/$(CONFIG)/grpc_cli: $(PROTOBUF_DEP) $(GRPC_CLI_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
+ $(E) "[LD] Linking $@"
+ $(Q) mkdir -p `dirname $@`
+ $(Q) $(LDXX) $(LDFLAGS) $(GRPC_CLI_OBJS) $(GTEST_LIB) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/grpc_cli
+
+endif
+
+endif
+
+$(OBJDIR)/$(CONFIG)/test/cpp/util/grpc_cli.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
+
+deps_grpc_cli: $(GRPC_CLI_OBJS:.o=.dep)
+
+ifneq ($(NO_SECURE),true)
+ifneq ($(NO_DEPS),true)
+-include $(GRPC_CLI_OBJS:.o=.dep)
+endif
+endif
+
+
GRPC_CPP_PLUGIN_SRC = \
- src/compiler/cpp_generator.cc \
src/compiler/cpp_plugin.cc \
GRPC_CPP_PLUGIN_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_CPP_PLUGIN_SRC))))
@@ -8202,15 +8304,14 @@
else
-$(BINDIR)/$(CONFIG)/grpc_cpp_plugin: $(PROTOBUF_DEP) $(GRPC_CPP_PLUGIN_OBJS)
+$(BINDIR)/$(CONFIG)/grpc_cpp_plugin: $(PROTOBUF_DEP) $(GRPC_CPP_PLUGIN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a
$(E) "[HOSTLD] Linking $@"
$(Q) mkdir -p `dirname $@`
- $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(GRPC_CPP_PLUGIN_OBJS) $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC) $(HOST_LDLIBS) $(HOST_LDLIBS_PROTOC) -o $(BINDIR)/$(CONFIG)/grpc_cpp_plugin
+ $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(GRPC_CPP_PLUGIN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC) $(HOST_LDLIBS) $(HOST_LDLIBS_PROTOC) -o $(BINDIR)/$(CONFIG)/grpc_cpp_plugin
endif
-$(OBJDIR)/$(CONFIG)/src/compiler/cpp_generator.o:
-$(OBJDIR)/$(CONFIG)/src/compiler/cpp_plugin.o:
+$(OBJDIR)/$(CONFIG)/src/compiler/cpp_plugin.o: $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a
deps_grpc_cpp_plugin: $(GRPC_CPP_PLUGIN_OBJS:.o=.dep)
@@ -8233,14 +8334,14 @@
else
-$(BINDIR)/$(CONFIG)/grpc_python_plugin: $(PROTOBUF_DEP) $(GRPC_PYTHON_PLUGIN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_python_plugin_support.a
+$(BINDIR)/$(CONFIG)/grpc_python_plugin: $(PROTOBUF_DEP) $(GRPC_PYTHON_PLUGIN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a
$(E) "[HOSTLD] Linking $@"
$(Q) mkdir -p `dirname $@`
- $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(GRPC_PYTHON_PLUGIN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_python_plugin_support.a $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC) $(HOST_LDLIBS) $(HOST_LDLIBS_PROTOC) -o $(BINDIR)/$(CONFIG)/grpc_python_plugin
+ $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(GRPC_PYTHON_PLUGIN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC) $(HOST_LDLIBS) $(HOST_LDLIBS_PROTOC) -o $(BINDIR)/$(CONFIG)/grpc_python_plugin
endif
-$(OBJDIR)/$(CONFIG)/src/compiler/python_plugin.o: $(LIBDIR)/$(CONFIG)/libgrpc_python_plugin_support.a
+$(OBJDIR)/$(CONFIG)/src/compiler/python_plugin.o: $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a
deps_grpc_python_plugin: $(GRPC_PYTHON_PLUGIN_OBJS:.o=.dep)
@@ -8250,7 +8351,6 @@
GRPC_RUBY_PLUGIN_SRC = \
- src/compiler/ruby_generator.cc \
src/compiler/ruby_plugin.cc \
GRPC_RUBY_PLUGIN_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_RUBY_PLUGIN_SRC))))
@@ -8264,15 +8364,14 @@
else
-$(BINDIR)/$(CONFIG)/grpc_ruby_plugin: $(PROTOBUF_DEP) $(GRPC_RUBY_PLUGIN_OBJS)
+$(BINDIR)/$(CONFIG)/grpc_ruby_plugin: $(PROTOBUF_DEP) $(GRPC_RUBY_PLUGIN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a
$(E) "[HOSTLD] Linking $@"
$(Q) mkdir -p `dirname $@`
- $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(GRPC_RUBY_PLUGIN_OBJS) $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC) $(HOST_LDLIBS) $(HOST_LDLIBS_PROTOC) -o $(BINDIR)/$(CONFIG)/grpc_ruby_plugin
+ $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(GRPC_RUBY_PLUGIN_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC) $(HOST_LDLIBS) $(HOST_LDLIBS_PROTOC) -o $(BINDIR)/$(CONFIG)/grpc_ruby_plugin
endif
-$(OBJDIR)/$(CONFIG)/src/compiler/ruby_generator.o:
-$(OBJDIR)/$(CONFIG)/src/compiler/ruby_plugin.o:
+$(OBJDIR)/$(CONFIG)/src/compiler/ruby_plugin.o: $(LIBDIR)/$(CONFIG)/libgrpc_plugin_support.a
deps_grpc_ruby_plugin: $(GRPC_RUBY_PLUGIN_OBJS:.o=.dep)
diff --git a/build.json b/build.json
index a468662..1e7ab96 100644
--- a/build.json
+++ b/build.json
@@ -52,6 +52,7 @@
"src/cpp/client/client_unary_call.cc",
"src/cpp/client/create_channel.cc",
"src/cpp/client/credentials.cc",
+ "src/cpp/client/generic_stub.cc",
"src/cpp/client/insecure_credentials.cc",
"src/cpp/client/internal_stub.cc",
"src/cpp/common/call.cc",
@@ -233,6 +234,7 @@
"src/core/surface/byte_buffer_reader.c",
"src/core/surface/call.c",
"src/core/surface/call_details.c",
+ "src/core/surface/call_log_batch.c",
"src/core/surface/channel.c",
"src/core/surface/channel_create.c",
"src/core/surface/client.c",
@@ -348,6 +350,9 @@
"name": "gpr_test_util",
"build": "private",
"language": "c",
+ "headers": [
+ "test/core/util/test_config.h"
+ ],
"src": [
"test/core/util/test_config.c"
],
@@ -432,6 +437,7 @@
],
"deps": [
"gpr",
+ "gpr_test_util",
"grpc"
],
"vs_project_guid": "{17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}"
@@ -480,6 +486,7 @@
"test/cpp/util/messages.proto",
"test/cpp/util/echo.proto",
"test/cpp/util/echo_duplicate.proto",
+ "test/cpp/util/cli_call.cc",
"test/cpp/util/create_test_channel.cc"
]
},
@@ -498,14 +505,24 @@
"secure": "no"
},
{
- "name": "grpc_python_plugin_support",
+ "name": "grpc_plugin_support",
"build": "protoc",
"language": "c++",
- "public_headers": [
- "src/compiler/python_generator.h"
+ "headers": [
+ "src/compiler/config.h",
+ "src/compiler/cpp_generator.h",
+ "src/compiler/cpp_generator_helpers.h",
+ "src/compiler/generator_helpers.h",
+ "src/compiler/python_generator.h",
+ "src/compiler/ruby_generator.h",
+ "src/compiler/ruby_generator_helpers-inl.h",
+ "src/compiler/ruby_generator_map-inl.h",
+ "src/compiler/ruby_generator_string-inl.h"
],
"src": [
- "src/compiler/python_generator.cc"
+ "src/compiler/cpp_generator.cc",
+ "src/compiler/python_generator.cc",
+ "src/compiler/ruby_generator.cc"
],
"deps": [],
"secure": "no"
@@ -1695,6 +1712,22 @@
]
},
{
+ "name": "cli_call_test",
+ "build": "test",
+ "language": "c++",
+ "src": [
+ "test/cpp/util/cli_call_test.cc"
+ ],
+ "deps": [
+ "grpc++_test_util",
+ "grpc_test_util",
+ "grpc++",
+ "grpc",
+ "gpr_test_util",
+ "gpr"
+ ]
+ },
+ {
"name": "credentials_test",
"build": "test",
"language": "c++",
@@ -1755,18 +1788,32 @@
]
},
{
+ "name": "grpc_cli",
+ "build": "test",
+ "run": false,
+ "language": "c++",
+ "src": [
+ "test/cpp/util/grpc_cli.cc"
+ ],
+ "deps": [
+ "grpc++_test_util",
+ "grpc_test_util",
+ "grpc++",
+ "grpc",
+ "gpr_test_util",
+ "gpr"
+ ]
+ },
+ {
"name": "grpc_cpp_plugin",
"build": "protoc",
"language": "c++",
- "headers": [
- "src/compiler/cpp_generator.h",
- "src/compiler/cpp_generator_helpers.h"
- ],
"src": [
- "src/compiler/cpp_generator.cc",
"src/compiler/cpp_plugin.cc"
],
- "deps": [],
+ "deps": [
+ "grpc_plugin_support"
+ ],
"secure": "no"
},
{
@@ -1777,7 +1824,7 @@
"src/compiler/python_plugin.cc"
],
"deps": [
- "grpc_python_plugin_support"
+ "grpc_plugin_support"
],
"secure": "no"
},
@@ -1786,10 +1833,11 @@
"build": "protoc",
"language": "c++",
"src": [
- "src/compiler/ruby_generator.cc",
"src/compiler/ruby_plugin.cc"
],
- "deps": [],
+ "deps": [
+ "grpc_plugin_support"
+ ],
"secure": "no"
},
{
diff --git a/examples/pubsub/main.cc b/examples/pubsub/main.cc
index 6f7737e..cc5076f 100644
--- a/examples/pubsub/main.cc
+++ b/examples/pubsub/main.cc
@@ -51,14 +51,14 @@
#include "examples/pubsub/subscriber.h"
DEFINE_int32(server_port, 443, "Server port.");
-DEFINE_string(server_host,
- "pubsub-staging.googleapis.com", "Server host to connect to");
+DEFINE_string(server_host, "pubsub-staging.googleapis.com",
+ "Server host to connect to");
DEFINE_string(project_id, "", "GCE project id such as stoked-keyword-656");
// In some distros, gflags is in the namespace google, and in some others,
// in gflags. This hack is enabling us to find both.
-namespace google { }
-namespace gflags { }
+namespace google {}
+namespace gflags {}
using namespace google;
using namespace gflags;
@@ -92,32 +92,32 @@
grpc::string topic = ss.str();
ss.str("");
- ss << FLAGS_project_id << "/" << kSubscriptionName;
+ ss << FLAGS_project_id << "/" << kSubscriptionName;
grpc::string subscription_name = ss.str();
// Clean up test topic and subcription if they exist before.
grpc::string subscription_topic;
- if (subscriber.GetSubscription(
- subscription_name, &subscription_topic).IsOk()) {
+ if (subscriber.GetSubscription(subscription_name, &subscription_topic)
+ .IsOk()) {
subscriber.DeleteSubscription(subscription_name);
}
if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic);
grpc::Status s = publisher.CreateTopic(topic);
- gpr_log(GPR_INFO, "Create topic returns code %d, %s",
- s.code(), s.details().c_str());
+ gpr_log(GPR_INFO, "Create topic returns code %d, %s", s.code(),
+ s.details().c_str());
GPR_ASSERT(s.IsOk());
s = publisher.GetTopic(topic);
- gpr_log(GPR_INFO, "Get topic returns code %d, %s",
- s.code(), s.details().c_str());
+ gpr_log(GPR_INFO, "Get topic returns code %d, %s", s.code(),
+ s.details().c_str());
GPR_ASSERT(s.IsOk());
std::vector<grpc::string> topics;
s = publisher.ListTopics(FLAGS_project_id, &topics);
- gpr_log(GPR_INFO, "List topic returns code %d, %s",
- s.code(), s.details().c_str());
+ gpr_log(GPR_INFO, "List topic returns code %d, %s", s.code(),
+ s.details().c_str());
bool topic_found = false;
for (unsigned int i = 0; i < topics.size(); i++) {
if (topics[i] == topic) topic_found = true;
@@ -127,27 +127,27 @@
GPR_ASSERT(topic_found);
s = subscriber.CreateSubscription(topic, subscription_name);
- gpr_log(GPR_INFO, "create subscrption returns code %d, %s",
- s.code(), s.details().c_str());
+ gpr_log(GPR_INFO, "create subscrption returns code %d, %s", s.code(),
+ s.details().c_str());
GPR_ASSERT(s.IsOk());
s = publisher.Publish(topic, kMessageData);
- gpr_log(GPR_INFO, "Publish %s returns code %d, %s",
- kMessageData, s.code(), s.details().c_str());
+ gpr_log(GPR_INFO, "Publish %s returns code %d, %s", kMessageData, s.code(),
+ s.details().c_str());
GPR_ASSERT(s.IsOk());
grpc::string data;
s = subscriber.Pull(subscription_name, &data);
gpr_log(GPR_INFO, "Pull %s", data.c_str());
- s = subscriber.DeleteSubscription(subscription_name);
- gpr_log(GPR_INFO, "Delete subscription returns code %d, %s",
- s.code(), s.details().c_str());
+ s = subscriber.DeleteSubscription(subscription_name);
+ gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", s.code(),
+ s.details().c_str());
GPR_ASSERT(s.IsOk());
s = publisher.DeleteTopic(topic);
- gpr_log(GPR_INFO, "Delete topic returns code %d, %s",
- s.code(), s.details().c_str());
+ gpr_log(GPR_INFO, "Delete topic returns code %d, %s", s.code(),
+ s.details().c_str());
GPR_ASSERT(s.IsOk());
subscriber.Shutdown();
diff --git a/examples/pubsub/publisher.cc b/examples/pubsub/publisher.cc
index 308f9a7..458050a 100644
--- a/examples/pubsub/publisher.cc
+++ b/examples/pubsub/publisher.cc
@@ -51,12 +51,9 @@
namespace pubsub {
Publisher::Publisher(std::shared_ptr<ChannelInterface> channel)
- : stub_(PublisherService::NewStub(channel)) {
-}
+ : stub_(PublisherService::NewStub(channel)) {}
-void Publisher::Shutdown() {
- stub_.reset();
-}
+void Publisher::Shutdown() { stub_.reset(); }
Status Publisher::CreateTopic(const grpc::string& topic) {
Topic request;
diff --git a/examples/pubsub/publisher_test.cc b/examples/pubsub/publisher_test.cc
index 62442c7..ac49212 100644
--- a/examples/pubsub/publisher_test.cc
+++ b/examples/pubsub/publisher_test.cc
@@ -31,8 +31,6 @@
*
*/
-#include <google/protobuf/stubs/common.h>
-
#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@@ -84,20 +82,19 @@
Status ListTopics(
ServerContext* context, const ::tech::pubsub::ListTopicsRequest* request,
::tech::pubsub::ListTopicsResponse* response) GRPC_OVERRIDE {
- std::ostringstream ss;
- ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")";
- EXPECT_EQ(request->query(), ss.str());
- response->add_topic()->set_name(kTopic);
- return Status::OK;
- }
+ std::ostringstream ss;
+ ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")";
+ EXPECT_EQ(request->query(), ss.str());
+ response->add_topic()->set_name(kTopic);
+ return Status::OK;
+ }
- Status DeleteTopic(ServerContext* context,
- const ::tech::pubsub::DeleteTopicRequest* request,
- ::proto2::Empty* response) GRPC_OVERRIDE {
+ Status DeleteTopic(ServerContext* context,
+ const ::tech::pubsub::DeleteTopicRequest* request,
+ ::proto2::Empty* response) GRPC_OVERRIDE {
EXPECT_EQ(request->topic(), kTopic);
return Status::OK;
- }
-
+ }
};
class PublisherTest : public ::testing::Test {
@@ -107,11 +104,13 @@
int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port;
ServerBuilder builder;
- builder.AddListeningPort(server_address_.str(), grpc::InsecureServerCredentials());
+ builder.AddListeningPort(server_address_.str(),
+ grpc::InsecureServerCredentials());
builder.RegisterService(&service_);
server_ = builder.BuildAndStart();
- channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(), ChannelArguments());
+ channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(),
+ ChannelArguments());
publisher_.reset(new grpc::examples::pubsub::Publisher(channel_));
}
diff --git a/examples/pubsub/subscriber.cc b/examples/pubsub/subscriber.cc
index 29f6635..d9e0292 100644
--- a/examples/pubsub/subscriber.cc
+++ b/examples/pubsub/subscriber.cc
@@ -49,12 +49,9 @@
namespace pubsub {
Subscriber::Subscriber(std::shared_ptr<ChannelInterface> channel)
- : stub_(SubscriberService::NewStub(channel)) {
-}
+ : stub_(SubscriberService::NewStub(channel)) {}
-void Subscriber::Shutdown() {
- stub_.reset();
-}
+void Subscriber::Shutdown() { stub_.reset(); }
Status Subscriber::CreateSubscription(const grpc::string& topic,
const grpc::string& name) {
diff --git a/examples/pubsub/subscriber_test.cc b/examples/pubsub/subscriber_test.cc
index b8dd1f9..9ab60ed 100644
--- a/examples/pubsub/subscriber_test.cc
+++ b/examples/pubsub/subscriber_test.cc
@@ -31,8 +31,6 @@
*
*/
-#include <google/protobuf/stubs/common.h>
-
#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@@ -95,7 +93,6 @@
proto2::Empty* response) GRPC_OVERRIDE {
return Status::OK;
}
-
};
class SubscriberTest : public ::testing::Test {
@@ -105,11 +102,13 @@
int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port;
ServerBuilder builder;
- builder.AddListeningPort(server_address_.str(), grpc::InsecureServerCredentials());
+ builder.AddListeningPort(server_address_.str(),
+ grpc::InsecureServerCredentials());
builder.RegisterService(&service_);
server_ = builder.BuildAndStart();
- channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(), ChannelArguments());
+ channel_ = CreateChannel(server_address_.str(), grpc::InsecureCredentials(),
+ ChannelArguments());
subscriber_.reset(new grpc::examples::pubsub::Subscriber(channel_));
}
@@ -129,17 +128,15 @@
};
TEST_F(SubscriberTest, TestSubscriber) {
- EXPECT_TRUE(subscriber_->CreateSubscription(kTopic,
- kSubscriptionName).IsOk());
+ EXPECT_TRUE(
+ subscriber_->CreateSubscription(kTopic, kSubscriptionName).IsOk());
grpc::string topic;
- EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName,
- &topic).IsOk());
+ EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, &topic).IsOk());
EXPECT_EQ(topic, kTopic);
grpc::string data;
- EXPECT_TRUE(subscriber_->Pull(kSubscriptionName,
- &data).IsOk());
+ EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, &data).IsOk());
EXPECT_TRUE(subscriber_->DeleteSubscription(kSubscriptionName).IsOk());
}
diff --git a/include/grpc++/config.h b/include/grpc++/config.h
index 35bf507..8ef5d71 100644
--- a/include/grpc++/config.h
+++ b/include/grpc++/config.h
@@ -65,6 +65,28 @@
::google::protobuf::io::ZeroCopyInputStream
#endif
+#ifndef __clang__
+#ifdef __GNUC__
+#if (__GNUC__ * 100 + __GNUC_MINOR__ < 406)
+#define GRPC_NO_NULLPTR
+#endif
+#endif
+#endif
+
+#ifdef GRPC_NO_NULLPTR
+#include <memory>
+const class {
+public:
+ template <class T> operator T*() const {return static_cast<T *>(0);}
+ template <class T> operator std::unique_ptr<T>() const {
+ return std::unique_ptr<T>(static_cast<T *>(0));
+ }
+ operator bool() const {return false;}
+private:
+ void operator&() const = delete;
+} nullptr = {};
+#endif
+
namespace grpc {
typedef GRPC_CUSTOM_STRING string;
diff --git a/include/grpc++/generic_stub.h b/include/grpc++/generic_stub.h
index d4c8380..c34e1fc 100644
--- a/include/grpc++/generic_stub.h
+++ b/include/grpc++/generic_stub.h
@@ -39,6 +39,7 @@
namespace grpc {
+class CompletionQueue;
typedef ClientAsyncReaderWriter<ByteBuffer, ByteBuffer>
GenericClientAsyncReaderWriter;
@@ -51,7 +52,8 @@
// begin a call to a named method
std::unique_ptr<GenericClientAsyncReaderWriter> Call(
- ClientContext* context, const grpc::string& method);
+ ClientContext* context, const grpc::string& method,
+ CompletionQueue* cq, void* tag);
private:
std::shared_ptr<ChannelInterface> channel_;
diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h
index 9b639cf..41185db 100644
--- a/include/grpc/support/port_platform.h
+++ b/include/grpc/support/port_platform.h
@@ -199,7 +199,7 @@
#endif
#if defined(GPR_POSIX_SOCKET) + defined(GPR_WIN32) != 1
-#error Must define exactly one of GPR_POSIX_POLLSET, GPR_WIN32
+#error Must define exactly one of GPR_POSIX_SOCKET, GPR_WIN32
#endif
typedef int16_t gpr_int16;
diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc
index d500462..0a84c73 100644
--- a/src/compiler/cpp_generator.cc
+++ b/src/compiler/cpp_generator.cc
@@ -111,7 +111,8 @@
}
} // namespace
-grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file) {
+grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file,
+ const Parameters ¶ms) {
grpc::string temp =
"#include <grpc++/impl/internal_stub.h>\n"
"#include <grpc++/impl/service_type.h>\n"
@@ -158,7 +159,7 @@
return temp;
}
-grpc::string GetSourceIncludes() {
+grpc::string GetSourceIncludes(const Parameters ¶m) {
return "#include <grpc++/async_unary_call.h>\n"
"#include <grpc++/channel_interface.h>\n"
"#include <grpc++/impl/client_unary_call.h>\n"
@@ -353,16 +354,27 @@
printer->Print("};\n");
}
-grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file) {
+grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file,
+ const Parameters ¶ms) {
grpc::string output;
grpc::protobuf::io::StringOutputStream output_stream(&output);
grpc::protobuf::io::Printer printer(&output_stream, '$');
std::map<grpc::string, grpc::string> vars;
+ if (!params.services_namespace.empty()) {
+ vars["services_namespace"] = params.services_namespace;
+ printer.Print(vars, "\nnamespace $services_namespace$ {\n\n");
+ }
+
for (int i = 0; i < file->service_count(); ++i) {
PrintHeaderService(&printer, file->service(i), &vars);
printer.Print("\n");
}
+
+ if (!params.services_namespace.empty()) {
+ printer.Print(vars, "} // namespace $services_namespace$\n\n");
+ }
+
return output;
}
@@ -376,18 +388,18 @@
grpc_cpp_generator::ClassName(method->output_type(), true);
if (NoStreaming(method)) {
printer->Print(*vars,
- "::grpc::Status $Service$::Stub::$Method$("
+ "::grpc::Status $ns$$Service$::Stub::$Method$("
"::grpc::ClientContext* context, "
"const $Request$& request, $Response$* response) {\n");
printer->Print(*vars,
" return ::grpc::BlockingUnaryCall(channel(),"
- "::grpc::RpcMethod($Service$_method_names[$Idx$]), "
+ "::grpc::RpcMethod($prefix$$Service$_method_names[$Idx$]), "
"context, request, response);\n"
"}\n\n");
printer->Print(
*vars,
"std::unique_ptr< ::grpc::ClientAsyncResponseReader< $Response$>> "
- "$Service$::Stub::Async$Method$(::grpc::ClientContext* context, "
+ "$ns$$Service$::Stub::Async$Method$(::grpc::ClientContext* context, "
"const $Request$& request, "
"::grpc::CompletionQueue* cq, void* tag) {\n");
printer->Print(*vars,
@@ -395,32 +407,32 @@
"::grpc::ClientAsyncResponseReader< $Response$>>(new "
"::grpc::ClientAsyncResponseReader< $Response$>("
"channel(), cq, "
- "::grpc::RpcMethod($Service$_method_names[$Idx$]), "
+ "::grpc::RpcMethod($prefix$$Service$_method_names[$Idx$]), "
"context, request, tag));\n"
"}\n\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(*vars,
"std::unique_ptr< ::grpc::ClientWriter< $Request$>> "
- "$Service$::Stub::$Method$("
+ "$ns$$Service$::Stub::$Method$("
"::grpc::ClientContext* context, $Response$* response) {\n");
printer->Print(*vars,
" return std::unique_ptr< ::grpc::ClientWriter< "
"$Request$>>(new ::grpc::ClientWriter< $Request$>("
"channel(),"
- "::grpc::RpcMethod($Service$_method_names[$Idx$], "
+ "::grpc::RpcMethod($prefix$$Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::CLIENT_STREAMING), "
"context, response));\n"
"}\n\n");
printer->Print(*vars,
"std::unique_ptr< ::grpc::ClientAsyncWriter< $Request$>> "
- "$Service$::Stub::Async$Method$("
+ "$ns$$Service$::Stub::Async$Method$("
"::grpc::ClientContext* context, $Response$* response, "
"::grpc::CompletionQueue* cq, void* tag) {\n");
printer->Print(*vars,
" return std::unique_ptr< ::grpc::ClientAsyncWriter< "
"$Request$>>(new ::grpc::ClientAsyncWriter< $Request$>("
"channel(), cq, "
- "::grpc::RpcMethod($Service$_method_names[$Idx$], "
+ "::grpc::RpcMethod($prefix$$Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::CLIENT_STREAMING), "
"context, response, tag));\n"
"}\n\n");
@@ -428,26 +440,26 @@
printer->Print(
*vars,
"std::unique_ptr< ::grpc::ClientReader< $Response$>> "
- "$Service$::Stub::$Method$("
+ "$ns$$Service$::Stub::$Method$("
"::grpc::ClientContext* context, const $Request$& request) {\n");
printer->Print(*vars,
" return std::unique_ptr< ::grpc::ClientReader< "
"$Response$>>(new ::grpc::ClientReader< $Response$>("
"channel(),"
- "::grpc::RpcMethod($Service$_method_names[$Idx$], "
+ "::grpc::RpcMethod($prefix$$Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::SERVER_STREAMING), "
"context, request));\n"
"}\n\n");
printer->Print(*vars,
"std::unique_ptr< ::grpc::ClientAsyncReader< $Response$>> "
- "$Service$::Stub::Async$Method$("
+ "$ns$$Service$::Stub::Async$Method$("
"::grpc::ClientContext* context, const $Request$& request, "
"::grpc::CompletionQueue* cq, void* tag) {\n");
printer->Print(*vars,
" return std::unique_ptr< ::grpc::ClientAsyncReader< "
"$Response$>>(new ::grpc::ClientAsyncReader< $Response$>("
"channel(), cq, "
- "::grpc::RpcMethod($Service$_method_names[$Idx$], "
+ "::grpc::RpcMethod($prefix$$Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::SERVER_STREAMING), "
"context, request, tag));\n"
"}\n\n");
@@ -455,27 +467,27 @@
printer->Print(
*vars,
"std::unique_ptr< ::grpc::ClientReaderWriter< $Request$, $Response$>> "
- "$Service$::Stub::$Method$(::grpc::ClientContext* context) {\n");
+ "$ns$$Service$::Stub::$Method$(::grpc::ClientContext* context) {\n");
printer->Print(*vars,
" return std::unique_ptr< ::grpc::ClientReaderWriter< "
"$Request$, $Response$>>(new ::grpc::ClientReaderWriter< "
"$Request$, $Response$>("
"channel(),"
- "::grpc::RpcMethod($Service$_method_names[$Idx$], "
+ "::grpc::RpcMethod($prefix$$Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::BIDI_STREAMING), "
"context));\n"
"}\n\n");
printer->Print(*vars,
"std::unique_ptr< ::grpc::ClientAsyncReaderWriter< "
"$Request$, $Response$>> "
- "$Service$::Stub::Async$Method$(::grpc::ClientContext* context, "
+ "$ns$$Service$::Stub::Async$Method$(::grpc::ClientContext* context, "
"::grpc::CompletionQueue* cq, void* tag) {\n");
printer->Print(*vars,
" return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< "
"$Request$, $Response$>>(new "
"::grpc::ClientAsyncReaderWriter< $Request$, $Response$>("
"channel(), cq, "
- "::grpc::RpcMethod($Service$_method_names[$Idx$], "
+ "::grpc::RpcMethod($prefix$$Service$_method_names[$Idx$], "
"::grpc::RpcMethod::RpcType::BIDI_STREAMING), "
"context, tag));\n"
"}\n\n");
@@ -492,7 +504,7 @@
grpc_cpp_generator::ClassName(method->output_type(), true);
if (NoStreaming(method)) {
printer->Print(*vars,
- "::grpc::Status $Service$::Service::$Method$("
+ "::grpc::Status $ns$$Service$::Service::$Method$("
"::grpc::ServerContext* context, "
"const $Request$* request, $Response$* response) {\n");
printer->Print(
@@ -501,7 +513,7 @@
printer->Print("}\n\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(*vars,
- "::grpc::Status $Service$::Service::$Method$("
+ "::grpc::Status $ns$$Service$::Service::$Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerReader< $Request$>* reader, "
"$Response$* response) {\n");
@@ -511,7 +523,7 @@
printer->Print("}\n\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(*vars,
- "::grpc::Status $Service$::Service::$Method$("
+ "::grpc::Status $ns$$Service$::Service::$Method$("
"::grpc::ServerContext* context, "
"const $Request$* request, "
"::grpc::ServerWriter< $Response$>* writer) {\n");
@@ -521,7 +533,7 @@
printer->Print("}\n\n");
} else if (BidiStreaming(method)) {
printer->Print(*vars,
- "::grpc::Status $Service$::Service::$Method$("
+ "::grpc::Status $ns$$Service$::Service::$Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerReaderWriter< $Response$, $Request$>* "
"stream) {\n");
@@ -543,7 +555,7 @@
grpc_cpp_generator::ClassName(method->output_type(), true);
if (NoStreaming(method)) {
printer->Print(*vars,
- "void $Service$::AsyncService::Request$Method$("
+ "void $ns$$Service$::AsyncService::Request$Method$("
"::grpc::ServerContext* context, "
"$Request$* request, "
"::grpc::ServerAsyncResponseWriter< $Response$>* response, "
@@ -554,7 +566,7 @@
printer->Print("}\n\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(*vars,
- "void $Service$::AsyncService::Request$Method$("
+ "void $ns$$Service$::AsyncService::Request$Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerAsyncReader< $Response$, $Request$>* reader, "
"::grpc::CompletionQueue* cq, void* tag) {\n");
@@ -564,7 +576,7 @@
printer->Print("}\n\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(*vars,
- "void $Service$::AsyncService::Request$Method$("
+ "void $ns$$Service$::AsyncService::Request$Method$("
"::grpc::ServerContext* context, "
"$Request$* request, "
"::grpc::ServerAsyncWriter< $Response$>* writer, "
@@ -576,7 +588,7 @@
} else if (BidiStreaming(method)) {
printer->Print(
*vars,
- "void $Service$::AsyncService::Request$Method$("
+ "void $ns$$Service$::AsyncService::Request$Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerAsyncReaderWriter< $Response$, $Request$>* stream, "
"::grpc::CompletionQueue* cq, void *tag) {\n");
@@ -592,7 +604,7 @@
std::map<grpc::string, grpc::string> *vars) {
(*vars)["Service"] = service->name();
- printer->Print(*vars, "static const char* $Service$_method_names[] = {\n");
+ printer->Print(*vars, "static const char* $prefix$$Service$_method_names[] = {\n");
for (int i = 0; i < service->method_count(); ++i) {
(*vars)["Method"] = service->method(i)->name();
printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n");
@@ -601,9 +613,9 @@
printer->Print(
*vars,
- "std::unique_ptr< $Service$::Stub> $Service$::NewStub("
+ "std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub("
"const std::shared_ptr< ::grpc::ChannelInterface>& channel) {\n"
- " std::unique_ptr< $Service$::Stub> stub(new $Service$::Stub());\n"
+ " std::unique_ptr< $ns$$Service$::Stub> stub(new $ns$$Service$::Stub());\n"
" stub->set_channel(channel);\n"
" return stub;\n"
"}\n\n");
@@ -615,12 +627,12 @@
(*vars)["MethodCount"] = as_string(service->method_count());
printer->Print(
*vars,
- "$Service$::AsyncService::AsyncService(::grpc::CompletionQueue* cq) : "
- "::grpc::AsynchronousService(cq, $Service$_method_names, $MethodCount$) "
+ "$ns$$Service$::AsyncService::AsyncService(::grpc::CompletionQueue* cq) : "
+ "::grpc::AsynchronousService(cq, $prefix$$Service$_method_names, $MethodCount$) "
"{}\n\n");
printer->Print(*vars,
- "$Service$::Service::~Service() {\n"
+ "$ns$$Service$::Service::~Service() {\n"
" delete service_;\n"
"}\n\n");
for (int i = 0; i < service->method_count(); ++i) {
@@ -629,7 +641,7 @@
PrintSourceServerAsyncMethod(printer, service->method(i), vars);
}
printer->Print(*vars,
- "::grpc::RpcService* $Service$::Service::service() {\n");
+ "::grpc::RpcService* $ns$$Service$::Service::service() {\n");
printer->Indent();
printer->Print(
"if (service_ != nullptr) {\n"
@@ -648,52 +660,52 @@
printer->Print(
*vars,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
- " $Service$_method_names[$Idx$],\n"
+ " $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::RpcMethod::NORMAL_RPC,\n"
- " new ::grpc::RpcMethodHandler< $Service$::Service, $Request$, "
+ " new ::grpc::RpcMethodHandler< $ns$$Service$::Service, $Request$, "
"$Response$>(\n"
- " std::function< ::grpc::Status($Service$::Service*, "
+ " std::function< ::grpc::Status($ns$$Service$::Service*, "
"::grpc::ServerContext*, const $Request$*, $Response$*)>("
- "&$Service$::Service::$Method$), this),\n"
+ "&$ns$$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(
*vars,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
- " $Service$_method_names[$Idx$],\n"
+ " $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::RpcMethod::CLIENT_STREAMING,\n"
" new ::grpc::ClientStreamingHandler< "
- "$Service$::Service, $Request$, $Response$>(\n"
- " std::function< ::grpc::Status($Service$::Service*, "
+ "$ns$$Service$::Service, $Request$, $Response$>(\n"
+ " std::function< ::grpc::Status($ns$$Service$::Service*, "
"::grpc::ServerContext*, "
"::grpc::ServerReader< $Request$>*, $Response$*)>("
- "&$Service$::Service::$Method$), this),\n"
+ "&$ns$$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(
*vars,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
- " $Service$_method_names[$Idx$],\n"
+ " $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::RpcMethod::SERVER_STREAMING,\n"
" new ::grpc::ServerStreamingHandler< "
- "$Service$::Service, $Request$, $Response$>(\n"
- " std::function< ::grpc::Status($Service$::Service*, "
+ "$ns$$Service$::Service, $Request$, $Response$>(\n"
+ " std::function< ::grpc::Status($ns$$Service$::Service*, "
"::grpc::ServerContext*, "
"const $Request$*, ::grpc::ServerWriter< $Response$>*)>("
- "&$Service$::Service::$Method$), this),\n"
+ "&$ns$$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n");
} else if (BidiStreaming(method)) {
printer->Print(
*vars,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
- " $Service$_method_names[$Idx$],\n"
+ " $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::RpcMethod::BIDI_STREAMING,\n"
" new ::grpc::BidiStreamingHandler< "
- "$Service$::Service, $Request$, $Response$>(\n"
- " std::function< ::grpc::Status($Service$::Service*, "
+ "$ns$$Service$::Service, $Request$, $Response$>(\n"
+ " std::function< ::grpc::Status($ns$$Service$::Service*, "
"::grpc::ServerContext*, "
"::grpc::ServerReaderWriter< $Response$, $Request$>*)>("
- "&$Service$::Service::$Method$), this),\n"
+ "&$ns$$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n");
}
}
@@ -702,7 +714,8 @@
printer->Print("}\n\n");
}
-grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file) {
+grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file,
+ const Parameters ¶ms) {
grpc::string output;
grpc::protobuf::io::StringOutputStream output_stream(&output);
grpc::protobuf::io::Printer printer(&output_stream, '$');
@@ -713,6 +726,13 @@
if (!file->package().empty()) {
vars["Package"].append(".");
}
+ if (!params.services_namespace.empty()) {
+ vars["ns"] = params.services_namespace + "::";
+ vars["prefix"] = params.services_namespace;
+ } else {
+ vars["ns"] = "";
+ vars["prefix"] = "";
+ }
for (int i = 0; i < file->service_count(); ++i) {
PrintSourceService(&printer, file->service(i), &vars);
diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h
index 2ecdb5c..04ad71c 100644
--- a/src/compiler/cpp_generator.h
+++ b/src/compiler/cpp_generator.h
@@ -38,17 +38,26 @@
namespace grpc_cpp_generator {
+// Contains all the parameters that are parsed from the command line.
+struct Parameters {
+ // Puts the service into a namespace
+ grpc::string services_namespace;
+};
+
// Return the includes needed for generated header file.
-grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file);
+grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file,
+ const Parameters ¶ms);
// Return the includes needed for generated source file.
-grpc::string GetSourceIncludes();
+grpc::string GetSourceIncludes(const Parameters ¶ms);
// Return the services for generated header file.
-grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file);
+grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file,
+ const Parameters ¶ms);
// Return the services for generated source file.
-grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file);
+grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file,
+ const Parameters ¶ms);
} // namespace grpc_cpp_generator
diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc
index 5b83aa8..acbe128 100644
--- a/src/compiler/cpp_plugin.cc
+++ b/src/compiler/cpp_plugin.cc
@@ -58,18 +58,42 @@
return false;
}
+ if (file->service_count() == 0) {
+ // No services. Do nothing.
+ return true;
+ }
+
+ grpc_cpp_generator::Parameters generator_parameters;
+
+ if (!parameter.empty()) {
+ std::vector<grpc::string> parameters_list =
+ grpc_generator::tokenize(parameter, ",");
+ for (auto parameter_string = parameters_list.begin();
+ parameter_string != parameters_list.end();
+ parameter_string++) {
+ std::vector<grpc::string> param =
+ grpc_generator::tokenize(*parameter_string, "=");
+ if (param[0] == "services_namespace") {
+ generator_parameters.services_namespace = param[1];
+ } else {
+ *error = grpc::string("Unknown parameter: ") + *parameter_string;
+ return false;
+ }
+ }
+ }
+
grpc::string file_name = grpc_generator::StripProto(file->name());
// Generate .pb.h
Insert(context, file_name + ".pb.h", "includes",
- grpc_cpp_generator::GetHeaderIncludes(file));
+ grpc_cpp_generator::GetHeaderIncludes(file, generator_parameters));
Insert(context, file_name + ".pb.h", "namespace_scope",
- grpc_cpp_generator::GetHeaderServices(file));
+ grpc_cpp_generator::GetHeaderServices(file, generator_parameters));
// Generate .pb.cc
Insert(context, file_name + ".pb.cc", "includes",
- grpc_cpp_generator::GetSourceIncludes());
+ grpc_cpp_generator::GetSourceIncludes(generator_parameters));
Insert(context, file_name + ".pb.cc", "namespace_scope",
- grpc_cpp_generator::GetSourceServices(file));
+ grpc_cpp_generator::GetSourceServices(file, generator_parameters));
return true;
}
diff --git a/src/compiler/generator_helpers.h b/src/compiler/generator_helpers.h
index 1e6727d..3085789 100644
--- a/src/compiler/generator_helpers.h
+++ b/src/compiler/generator_helpers.h
@@ -75,6 +75,26 @@
return str;
}
+inline std::vector<grpc::string> tokenize(const grpc::string &input,
+ const grpc::string &delimiters) {
+ std::vector<grpc::string> tokens;
+ size_t pos, last_pos = 0;
+
+ for (;;) {
+ bool done = false;
+ pos = input.find_first_of(delimiters, last_pos);
+ if (pos == grpc::string::npos) {
+ done = true;
+ pos = input.length();
+ }
+
+ tokens.push_back(input.substr(last_pos, pos - last_pos));
+ if (done) return tokens;
+
+ last_pos = pos + 1;
+ }
+}
+
} // namespace grpc_generator
#endif // GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H
diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc
index c2d4cda..d32213f 100644
--- a/src/compiler/python_generator.cc
+++ b/src/compiler/python_generator.cc
@@ -271,7 +271,7 @@
bool PrintServerFactory(const grpc::string& package_qualified_service_name,
const ServiceDescriptor* service, Printer* out) {
out->Print("def early_adopter_create_$Service$_server(servicer, port, "
- "root_certificates, key_chain_pairs):\n",
+ "private_key=None, certificate_chain=None):\n",
"Service", service->name());
{
IndentScope raii_create_server_indent(out);
@@ -309,17 +309,20 @@
make_pair(method->name(), output_message_module_and_class));
}
out->Print("method_service_descriptions = {\n");
- for (auto& name_and_description_constructor :
- method_description_constructors) {
+ for (auto name_and_description_constructor =
+ method_description_constructors.begin();
+ name_and_description_constructor !=
+ method_description_constructors.end();
+ name_and_description_constructor++) {
IndentScope raii_descriptions_indent(out);
- const grpc::string method_name = name_and_description_constructor.first;
+ const grpc::string method_name = name_and_description_constructor->first;
auto input_message_module_and_class =
input_message_modules_and_classes.find(method_name);
auto output_message_module_and_class =
output_message_modules_and_classes.find(method_name);
out->Print("\"$Method$\": utilities.$Constructor$(\n", "Method",
method_name, "Constructor",
- name_and_description_constructor.second);
+ name_and_description_constructor->second);
{
IndentScope raii_description_arguments_indent(out);
out->Print("servicer.$Method$,\n", "Method", method_name);
@@ -336,10 +339,10 @@
}
out->Print("}\n");
out->Print(
- "return implementations.secure_server("
+ "return implementations.server("
"\"$PackageQualifiedServiceName$\","
- " method_service_descriptions, port, root_certificates,"
- " key_chain_pairs)\n",
+ " method_service_descriptions, port, private_key=private_key,"
+ " certificate_chain=certificate_chain)\n",
"PackageQualifiedServiceName", package_qualified_service_name);
}
return true;
@@ -350,7 +353,9 @@
map<grpc::string, grpc::string> dict = ListToDict({
"Service", service->name(),
});
- out->Print(dict, "def early_adopter_create_$Service$_stub(host, port):\n");
+ out->Print(dict, "def early_adopter_create_$Service$_stub(host, port,"
+ " secure=False, root_certificates=None, private_key=None,"
+ " certificate_chain=None, server_host_override=None):\n");
{
IndentScope raii_create_server_indent(out);
map<grpc::string, grpc::string> method_description_constructors;
@@ -387,17 +392,20 @@
make_pair(method->name(), output_message_module_and_class));
}
out->Print("method_invocation_descriptions = {\n");
- for (auto& name_and_description_constructor :
- method_description_constructors) {
+ for (auto name_and_description_constructor =
+ method_description_constructors.begin();
+ name_and_description_constructor !=
+ method_description_constructors.end();
+ name_and_description_constructor++) {
IndentScope raii_descriptions_indent(out);
- const grpc::string method_name = name_and_description_constructor.first;
+ const grpc::string method_name = name_and_description_constructor->first;
auto input_message_module_and_class =
input_message_modules_and_classes.find(method_name);
auto output_message_module_and_class =
output_message_modules_and_classes.find(method_name);
out->Print("\"$Method$\": utilities.$Constructor$(\n", "Method",
method_name, "Constructor",
- name_and_description_constructor.second);
+ name_and_description_constructor->second);
{
IndentScope raii_description_arguments_indent(out);
out->Print(
@@ -413,9 +421,12 @@
}
out->Print("}\n");
out->Print(
- "return implementations.insecure_stub("
+ "return implementations.stub("
"\"$PackageQualifiedServiceName$\","
- " method_invocation_descriptions, host, port)\n",
+ " method_invocation_descriptions, host, port, secure=secure,"
+ " root_certificates=root_certificates, private_key=private_key,"
+ " certificate_chain=certificate_chain,"
+ " server_host_override=server_host_override)\n",
"PackageQualifiedServiceName", package_qualified_service_name);
}
return true;
diff --git a/src/compiler/ruby_generator.cc b/src/compiler/ruby_generator.cc
index 32b6a8d..a0bb928 100644
--- a/src/compiler/ruby_generator.cc
+++ b/src/compiler/ruby_generator.cc
@@ -32,24 +32,20 @@
*/
#include <cctype>
-#include <string>
#include <map>
#include <vector>
+#include "src/compiler/config.h"
#include "src/compiler/ruby_generator.h"
#include "src/compiler/ruby_generator_helpers-inl.h"
#include "src/compiler/ruby_generator_map-inl.h"
#include "src/compiler/ruby_generator_string-inl.h"
-#include <google/protobuf/io/printer.h>
-#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
-#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/descriptor.h>
-using google::protobuf::FileDescriptor;
-using google::protobuf::ServiceDescriptor;
-using google::protobuf::MethodDescriptor;
-using google::protobuf::io::Printer;
-using google::protobuf::io::StringOutputStream;
+using grpc::protobuf::FileDescriptor;
+using grpc::protobuf::ServiceDescriptor;
+using grpc::protobuf::MethodDescriptor;
+using grpc::protobuf::io::Printer;
+using grpc::protobuf::io::StringOutputStream;
using std::map;
using std::vector;
@@ -57,38 +53,38 @@
namespace {
// Prints out the method using the ruby gRPC DSL.
-void PrintMethod(const MethodDescriptor *method, const std::string &package,
+void PrintMethod(const MethodDescriptor *method, const grpc::string &package,
Printer *out) {
- std::string input_type = RubyTypeOf(method->input_type()->name(), package);
+ grpc::string input_type = RubyTypeOf(method->input_type()->name(), package);
if (method->client_streaming()) {
input_type = "stream(" + input_type + ")";
}
- std::string output_type = RubyTypeOf(method->output_type()->name(), package);
+ grpc::string output_type = RubyTypeOf(method->output_type()->name(), package);
if (method->server_streaming()) {
output_type = "stream(" + output_type + ")";
}
- std::map<std::string, std::string> method_vars =
+ std::map<grpc::string, grpc::string> method_vars =
ListToDict({"mth.name", method->name(), "input.type", input_type,
"output.type", output_type, });
out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n");
}
// Prints out the service using the ruby gRPC DSL.
-void PrintService(const ServiceDescriptor *service, const std::string &package,
+void PrintService(const ServiceDescriptor *service, const grpc::string &package,
Printer *out) {
if (service->method_count() == 0) {
return;
}
// Begin the service module
- std::map<std::string, std::string> module_vars =
+ std::map<grpc::string, grpc::string> module_vars =
ListToDict({"module.name", CapitalizeFirst(service->name()), });
out->Print(module_vars, "module $module.name$\n");
out->Indent();
// TODO(temiola): add documentation
- std::string doc = "TODO: add proto service documentation here";
- std::map<std::string, std::string> template_vars =
+ grpc::string doc = "TODO: add proto service documentation here";
+ std::map<grpc::string, grpc::string> template_vars =
ListToDict({"Documentation", doc, });
out->Print("\n");
out->Print(template_vars, "# $Documentation$\n");
@@ -101,7 +97,7 @@
out->Print("\n");
out->Print("self.marshal_class_method = :encode\n");
out->Print("self.unmarshal_class_method = :decode\n");
- std::map<std::string, std::string> pkg_vars =
+ std::map<grpc::string, grpc::string> pkg_vars =
ListToDict({"service.name", service->name(), "pkg.name", package, });
out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n");
out->Print("\n");
@@ -121,8 +117,8 @@
} // namespace
-std::string GetServices(const FileDescriptor *file) {
- std::string output;
+grpc::string GetServices(const FileDescriptor *file) {
+ grpc::string output;
StringOutputStream output_stream(&output);
Printer out(&output_stream, '$');
@@ -133,7 +129,7 @@
}
// Write out a file header.
- std::map<std::string, std::string> header_comment_vars = ListToDict(
+ std::map<grpc::string, grpc::string> header_comment_vars = ListToDict(
{"file.name", file->name(), "file.package", file->package(), });
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
out.Print(header_comment_vars,
@@ -144,15 +140,15 @@
// Write out require statemment to import the separately generated file
// that defines the messages used by the service. This is generated by the
// main ruby plugin.
- std::map<std::string, std::string> dep_vars =
+ std::map<grpc::string, grpc::string> dep_vars =
ListToDict({"dep.name", MessagesRequireName(file), });
out.Print(dep_vars, "require '$dep.name$'\n");
// Write out services within the modules
out.Print("\n");
- std::vector<std::string> modules = Split(file->package(), '.');
+ std::vector<grpc::string> modules = Split(file->package(), '.');
for (size_t i = 0; i < modules.size(); ++i) {
- std::map<std::string, std::string> module_vars =
+ std::map<grpc::string, grpc::string> module_vars =
ListToDict({"module.name", CapitalizeFirst(modules[i]), });
out.Print(module_vars, "module $module.name$\n");
out.Indent();
diff --git a/src/compiler/ruby_generator.h b/src/compiler/ruby_generator.h
index 4dd38e0..a2ab36d 100644
--- a/src/compiler/ruby_generator.h
+++ b/src/compiler/ruby_generator.h
@@ -34,17 +34,11 @@
#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_H
#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_H
-#include <string>
-
-namespace google {
-namespace protobuf {
-class FileDescriptor;
-} // namespace protobuf
-} // namespace google
+#include "src/compiler/config.h"
namespace grpc_ruby_generator {
-std::string GetServices(const google::protobuf::FileDescriptor *file);
+grpc::string GetServices(const grpc::protobuf::FileDescriptor *file);
} // namespace grpc_ruby_generator
diff --git a/src/compiler/ruby_generator_helpers-inl.h b/src/compiler/ruby_generator_helpers-inl.h
index f3a087b..9da7cab 100644
--- a/src/compiler/ruby_generator_helpers-inl.h
+++ b/src/compiler/ruby_generator_helpers-inl.h
@@ -34,15 +34,13 @@
#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
-#include <string>
-
-#include <google/protobuf/descriptor.h>
+#include "src/compiler/config.h"
#include "src/compiler/ruby_generator_string-inl.h"
namespace grpc_ruby_generator {
-inline bool ServicesFilename(const google::protobuf::FileDescriptor *file,
- std::string *file_name_or_error) {
+inline bool ServicesFilename(const grpc::protobuf::FileDescriptor *file,
+ grpc::string *file_name_or_error) {
// Get output file name.
static const unsigned proto_suffix_length = 6; // length of ".proto"
if (file->name().size() > proto_suffix_length &&
@@ -57,8 +55,8 @@
}
}
-inline std::string MessagesRequireName(
- const google::protobuf::FileDescriptor *file) {
+inline grpc::string MessagesRequireName(
+ const grpc::protobuf::FileDescriptor *file) {
return Replace(file->name(), ".proto", "");
}
diff --git a/src/compiler/ruby_generator_map-inl.h b/src/compiler/ruby_generator_map-inl.h
index f902b6d..6b87774 100644
--- a/src/compiler/ruby_generator_map-inl.h
+++ b/src/compiler/ruby_generator_map-inl.h
@@ -34,11 +34,12 @@
#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
+#include "src/compiler/config.h"
+
#include <iostream>
#include <initializer_list>
#include <map>
#include <ostream> // NOLINT
-#include <string>
#include <vector>
using std::initializer_list;
@@ -49,18 +50,18 @@
// Converts an initializer list of the form { key0, value0, key1, value1, ... }
// into a map of key* to value*. Is merely a readability helper for later code.
-inline std::map<std::string, std::string> ListToDict(
- const initializer_list<std::string> &values) {
+inline std::map<grpc::string, grpc::string> ListToDict(
+ const initializer_list<grpc::string> &values) {
if (values.size() % 2 != 0) {
std::cerr << "Not every 'key' has a value in `values`."
<< std::endl;
}
- std::map<std::string, std::string> value_map;
+ std::map<grpc::string, grpc::string> value_map;
auto value_iter = values.begin();
for (unsigned i = 0; i < values.size() / 2; ++i) {
- std::string key = *value_iter;
+ grpc::string key = *value_iter;
++value_iter;
- std::string value = *value_iter;
+ grpc::string value = *value_iter;
value_map[key] = value;
++value_iter;
}
diff --git a/src/compiler/ruby_generator_string-inl.h b/src/compiler/ruby_generator_string-inl.h
index bdd314c..8da3a88 100644
--- a/src/compiler/ruby_generator_string-inl.h
+++ b/src/compiler/ruby_generator_string-inl.h
@@ -34,8 +34,9 @@
#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
+#include "src/compiler/config.h"
+
#include <algorithm>
-#include <string>
#include <sstream>
#include <vector>
@@ -45,10 +46,10 @@
namespace grpc_ruby_generator {
// Split splits a string using char into elems.
-inline std::vector<std::string> &Split(const std::string &s, char delim,
- std::vector<std::string> *elems) {
+inline std::vector<grpc::string> &Split(const grpc::string &s, char delim,
+ std::vector<grpc::string> *elems) {
std::stringstream ss(s);
- std::string item;
+ grpc::string item;
while (getline(ss, item, delim)) {
elems->push_back(item);
}
@@ -56,17 +57,17 @@
}
// Split splits a string using char, returning the result in a vector.
-inline std::vector<std::string> Split(const std::string &s, char delim) {
- std::vector<std::string> elems;
+inline std::vector<grpc::string> Split(const grpc::string &s, char delim) {
+ std::vector<grpc::string> elems;
Split(s, delim, &elems);
return elems;
}
// Replace replaces from with to in s.
-inline std::string Replace(std::string s, const std::string &from,
- const std::string &to) {
+inline grpc::string Replace(grpc::string s, const grpc::string &from,
+ const grpc::string &to) {
size_t start_pos = s.find(from);
- if (start_pos == std::string::npos) {
+ if (start_pos == grpc::string::npos) {
return s;
}
s.replace(start_pos, from.length(), to);
@@ -74,10 +75,10 @@
}
// ReplaceAll replaces all instances of search with replace in s.
-inline std::string ReplaceAll(std::string s, const std::string &search,
- const std::string &replace) {
+inline grpc::string ReplaceAll(grpc::string s, const grpc::string &search,
+ const grpc::string &replace) {
size_t pos = 0;
- while ((pos = s.find(search, pos)) != std::string::npos) {
+ while ((pos = s.find(search, pos)) != grpc::string::npos) {
s.replace(pos, search.length(), replace);
pos += replace.length();
}
@@ -85,10 +86,10 @@
}
// ReplacePrefix replaces from with to in s if search is a prefix of s.
-inline bool ReplacePrefix(std::string *s, const std::string &from,
- const std::string &to) {
+inline bool ReplacePrefix(grpc::string *s, const grpc::string &from,
+ const grpc::string &to) {
size_t start_pos = s->find(from);
- if (start_pos == std::string::npos || start_pos != 0) {
+ if (start_pos == grpc::string::npos || start_pos != 0) {
return false;
}
s->replace(start_pos, from.length(), to);
@@ -96,7 +97,7 @@
}
// CapitalizeFirst capitalizes the first char in a string.
-inline std::string CapitalizeFirst(std::string s) {
+inline grpc::string CapitalizeFirst(grpc::string s) {
if (s.empty()) {
return s;
}
@@ -105,15 +106,15 @@
}
// RubyTypeOf updates a proto type to the required ruby equivalent.
-inline std::string RubyTypeOf(const std::string &a_type,
- const std::string &package) {
- std::string res(a_type);
+inline grpc::string RubyTypeOf(const grpc::string &a_type,
+ const grpc::string &package) {
+ grpc::string res(a_type);
ReplacePrefix(&res, package, ""); // remove the leading package if present
ReplacePrefix(&res, ".", ""); // remove the leading . (no package)
- if (res.find('.') == std::string::npos) {
+ if (res.find('.') == grpc::string::npos) {
return res;
} else {
- std::vector<std::string> prefixes_and_type = Split(res, '.');
+ std::vector<grpc::string> prefixes_and_type = Split(res, '.');
for (unsigned int i = 0; i < prefixes_and_type.size(); ++i) {
if (i != 0) {
res += "::"; // switch '.' to the ruby module delim
diff --git a/src/compiler/ruby_plugin.cc b/src/compiler/ruby_plugin.cc
index 4a6e9f7..bd10d46 100644
--- a/src/compiler/ruby_plugin.cc
+++ b/src/compiler/ruby_plugin.cc
@@ -32,43 +32,35 @@
*/
// Generates Ruby gRPC service interface out of Protobuf IDL.
-//
-// This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto
-// and net/proto2/compiler/public/plugin.h for more information on plugins.
#include <memory>
-#include <string>
+#include "src/compiler/config.h"
#include "src/compiler/ruby_generator.h"
#include "src/compiler/ruby_generator_helpers-inl.h"
-#include <google/protobuf/compiler/code_generator.h>
-#include <google/protobuf/compiler/plugin.h>
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/io/zero_copy_stream.h>
-#include <google/protobuf/descriptor.h>
-class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
+class RubyGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
public:
RubyGrpcGenerator() {}
~RubyGrpcGenerator() {}
- bool Generate(const google::protobuf::FileDescriptor *file,
- const std::string ¶meter,
- google::protobuf::compiler::GeneratorContext *context,
- std::string *error) const {
- std::string code = grpc_ruby_generator::GetServices(file);
+ bool Generate(const grpc::protobuf::FileDescriptor *file,
+ const grpc::string ¶meter,
+ grpc::protobuf::compiler::GeneratorContext *context,
+ grpc::string *error) const {
+ grpc::string code = grpc_ruby_generator::GetServices(file);
if (code.size() == 0) {
return true; // don't generate a file if there are no services
}
// Get output file name.
- std::string file_name;
+ grpc::string file_name;
if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) {
return false;
}
- std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
+ std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(
context->Open(file_name));
- google::protobuf::io::CodedOutputStream coded_out(output.get());
+ grpc::protobuf::io::CodedOutputStream coded_out(output.get());
coded_out.WriteRaw(code.data(), code.size());
return true;
}
@@ -76,5 +68,5 @@
int main(int argc, char *argv[]) {
RubyGrpcGenerator generator;
- return google::protobuf::compiler::PluginMain(argc, argv, &generator);
+ return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
}
diff --git a/src/core/channel/http_server_filter.c b/src/core/channel/http_server_filter.c
index f565cbf..9da8b33 100644
--- a/src/core/channel/http_server_filter.c
+++ b/src/core/channel/http_server_filter.c
@@ -189,7 +189,8 @@
/* translate host to :authority since :authority may be
omitted */
grpc_mdelem *authority = grpc_mdelem_from_metadata_strings(
- channeld->mdctx, channeld->authority_key, op->data.metadata->value);
+ channeld->mdctx, grpc_mdstr_ref(channeld->authority_key),
+ grpc_mdstr_ref(op->data.metadata->value));
grpc_mdelem_unref(op->data.metadata);
op->data.metadata = authority;
/* pass the event up */
diff --git a/src/core/iomgr/iocp_windows.c b/src/core/iomgr/iocp_windows.c
index 8b019e8..aec6265 100644
--- a/src/core/iomgr/iocp_windows.c
+++ b/src/core/iomgr/iocp_windows.c
@@ -52,10 +52,11 @@
static gpr_event g_shutdown_iocp;
static gpr_event g_iocp_done;
+static gpr_atm g_orphans = 0;
static HANDLE g_iocp;
-static int do_iocp_work() {
+static void do_iocp_work() {
BOOL success;
DWORD bytes = 0;
DWORD flags = 0;
@@ -71,14 +72,14 @@
gpr_time_to_millis(wait_time));
if (!success && !overlapped) {
/* The deadline got attained. */
- return 0;
+ return;
}
GPR_ASSERT(completion_key && overlapped);
if (overlapped == &g_iocp_custom_overlap) {
if (completion_key == (ULONG_PTR) &g_iocp_kick_token) {
/* We were awoken from a kick. */
gpr_log(GPR_DEBUG, "do_iocp_work - got a kick");
- return 1;
+ return;
}
gpr_log(GPR_ERROR, "Unknown custom completion key.");
abort();
@@ -97,8 +98,13 @@
}
success = WSAGetOverlappedResult(socket->socket, &info->overlapped, &bytes,
FALSE, &flags);
- gpr_log(GPR_DEBUG, "bytes: %u, flags: %u - op %s", bytes, flags,
- success ? "succeeded" : "failed");
+ gpr_log(GPR_DEBUG, "bytes: %u, flags: %u - op %s %s", bytes, flags,
+ success ? "succeeded" : "failed", socket->orphan ? "orphan" : "");
+ if (socket->orphan) {
+ grpc_winsocket_destroy(socket);
+ gpr_atm_full_fetch_add(&g_orphans, -1);
+ return;
+ }
info->bytes_transfered = bytes;
info->wsa_error = success ? 0 : WSAGetLastError();
GPR_ASSERT(overlapped == &info->overlapped);
@@ -113,12 +119,10 @@
}
gpr_mu_unlock(&socket->state_mu);
if (f) f(opaque, 1);
-
- return 1;
}
static void iocp_loop(void *p) {
- while (!gpr_event_get(&g_shutdown_iocp)) {
+ while (gpr_atm_acq_load(&g_orphans) || !gpr_event_get(&g_shutdown_iocp)) {
grpc_maybe_call_delayed_callbacks(NULL, 1);
do_iocp_work();
}
@@ -138,13 +142,19 @@
gpr_thd_new(&id, iocp_loop, NULL, NULL);
}
-void grpc_iocp_shutdown(void) {
+void grpc_iocp_kick(void) {
BOOL success;
- gpr_event_set(&g_shutdown_iocp, (void *)1);
+
success = PostQueuedCompletionStatus(g_iocp, 0,
(ULONG_PTR) &g_iocp_kick_token,
&g_iocp_custom_overlap);
GPR_ASSERT(success);
+}
+
+void grpc_iocp_shutdown(void) {
+ BOOL success;
+ gpr_event_set(&g_shutdown_iocp, (void *)1);
+ grpc_iocp_kick();
gpr_event_wait(&g_iocp_done, gpr_inf_future);
success = CloseHandle(g_iocp);
GPR_ASSERT(success);
@@ -166,6 +176,10 @@
GPR_ASSERT(ret == g_iocp);
}
+void grpc_iocp_socket_orphan(grpc_winsocket *socket) {
+ gpr_atm_full_fetch_add(&g_orphans, 1);
+}
+
static void socket_notify_on_iocp(grpc_winsocket *socket,
void(*cb)(void *, int), void *opaque,
grpc_winsocket_callback_info *info) {
diff --git a/src/core/iomgr/iocp_windows.h b/src/core/iomgr/iocp_windows.h
index 3313319..fa3f5ee 100644
--- a/src/core/iomgr/iocp_windows.h
+++ b/src/core/iomgr/iocp_windows.h
@@ -42,6 +42,7 @@
void grpc_iocp_init(void);
void grpc_iocp_shutdown(void);
void grpc_iocp_add_socket(grpc_winsocket *);
+void grpc_iocp_socket_orphan(grpc_winsocket *);
void grpc_socket_notify_on_write(grpc_winsocket *, void(*cb)(void *, int success),
void *opaque);
diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c
index 058685b..d0e6706 100644
--- a/src/core/iomgr/iomgr.c
+++ b/src/core/iomgr/iomgr.c
@@ -117,7 +117,16 @@
gpr_mu_lock(&g_mu);
}
if (g_refs) {
- if (gpr_cv_wait(&g_rcv, &g_mu, shutdown_deadline) && g_cbs_head == NULL) {
+ int timeout = 0;
+ gpr_timespec short_deadline = gpr_time_add(gpr_now(),
+ gpr_time_from_millis(100));
+ while (gpr_cv_wait(&g_rcv, &g_mu, short_deadline) && g_cbs_head == NULL) {
+ if (gpr_time_cmp(gpr_now(), shutdown_deadline) > 0) {
+ timeout = 1;
+ break;
+ }
+ }
+ if (timeout) {
gpr_log(GPR_DEBUG,
"Failed to free %d iomgr objects before shutdown deadline: "
"memory leaks are likely",
diff --git a/src/core/iomgr/socket_windows.c b/src/core/iomgr/socket_windows.c
index 99f38b0..22dad41 100644
--- a/src/core/iomgr/socket_windows.c
+++ b/src/core/iomgr/socket_windows.c
@@ -55,7 +55,7 @@
return r;
}
-void shutdown_op(grpc_winsocket_callback_info *info) {
+static void shutdown_op(grpc_winsocket_callback_info *info) {
if (!info->cb) return;
grpc_iomgr_add_delayed_callback(info->cb, info->opaque, 0);
}
@@ -68,8 +68,13 @@
void grpc_winsocket_orphan(grpc_winsocket *socket) {
gpr_log(GPR_DEBUG, "grpc_winsocket_orphan");
+ grpc_iocp_socket_orphan(socket);
+ socket->orphan = 1;
grpc_iomgr_unref();
closesocket(socket->socket);
+}
+
+void grpc_winsocket_destroy(grpc_winsocket *socket) {
gpr_mu_destroy(&socket->state_mu);
gpr_free(socket);
}
diff --git a/src/core/iomgr/socket_windows.h b/src/core/iomgr/socket_windows.h
index d4776ab..cbae916 100644
--- a/src/core/iomgr/socket_windows.h
+++ b/src/core/iomgr/socket_windows.h
@@ -57,12 +57,13 @@
typedef struct grpc_winsocket {
SOCKET socket;
- int added_to_iocp;
-
grpc_winsocket_callback_info write_info;
grpc_winsocket_callback_info read_info;
gpr_mu state_mu;
+
+ int added_to_iocp;
+ int orphan;
} grpc_winsocket;
/* Create a wrapped windows handle.
@@ -71,5 +72,6 @@
void grpc_winsocket_shutdown(grpc_winsocket *socket);
void grpc_winsocket_orphan(grpc_winsocket *socket);
+void grpc_winsocket_destroy(grpc_winsocket *socket);
#endif /* GRPC_INTERNAL_CORE_IOMGR_SOCKET_WINDOWS_H */
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index cfce943..dba6305 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -1006,6 +1006,8 @@
const grpc_op *op;
grpc_ioreq *req;
+ GRPC_CALL_LOG_BATCH(GPR_INFO, call, ops, nops, tag);
+
if (nops == 0) {
grpc_cq_begin_op(call->cq, call, GRPC_OP_COMPLETE);
grpc_cq_end_op_complete(call->cq, tag, call, do_nothing, NULL, GRPC_OP_OK);
diff --git a/src/core/surface/call.h b/src/core/surface/call.h
index cb81cb5..06434f8 100644
--- a/src/core/surface/call.h
+++ b/src/core/surface/call.h
@@ -119,4 +119,13 @@
/* Given the top call_element, get the call object. */
grpc_call *grpc_call_from_top_element(grpc_call_element *surface_element);
+extern int grpc_trace_batch;
+
+void grpc_call_log_batch(char *file, int line, gpr_log_severity severity,
+ grpc_call *call, const grpc_op *ops, size_t nops,
+ void *tag);
+
+#define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \
+ if (grpc_trace_batch) grpc_call_log_batch(sev, call, ops, nops, tag)
+
#endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_H */
diff --git a/src/core/surface/call_log_batch.c b/src/core/surface/call_log_batch.c
new file mode 100644
index 0000000..a33583a
--- /dev/null
+++ b/src/core/surface/call_log_batch.c
@@ -0,0 +1,121 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/core/surface/call.h"
+
+#include "src/core/support/string.h"
+#include <grpc/support/alloc.h>
+
+int grpc_trace_batch = 0;
+
+static void add_metadata(gpr_strvec *b, const grpc_metadata *md, size_t count) {
+ size_t i;
+ for(i = 0; i < count; i++) {
+ gpr_strvec_add(b, gpr_strdup("\nkey="));
+ gpr_strvec_add(b, gpr_strdup(md[i].key));
+
+ gpr_strvec_add(b, gpr_strdup(" value="));
+ gpr_strvec_add(b, gpr_hexdump(md[i].value, md[i].value_length,
+ GPR_HEXDUMP_PLAINTEXT));
+ }
+}
+
+char *grpc_op_string(const grpc_op *op) {
+ char *tmp;
+ char *out;
+
+ gpr_strvec b;
+ gpr_strvec_init(&b);
+
+ switch (op->op) {
+ case GRPC_OP_SEND_INITIAL_METADATA:
+ gpr_strvec_add(&b, gpr_strdup("SEND_INITIAL_METADATA"));
+ add_metadata(&b, op->data.send_initial_metadata.metadata,
+ op->data.send_initial_metadata.count);
+ break;
+ case GRPC_OP_SEND_MESSAGE:
+ gpr_asprintf(&tmp, "SEND_MESSAGE ptr=%p", op->data.send_message);
+ gpr_strvec_add(&b, tmp);
+ break;
+ case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
+ gpr_strvec_add(&b, gpr_strdup("SEND_CLOSE_FROM_CLIENT"));
+ break;
+ case GRPC_OP_SEND_STATUS_FROM_SERVER:
+ gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=%s",
+ op->data.send_status_from_server.status,
+ op->data.send_status_from_server.status_details);
+ gpr_strvec_add(&b, tmp);
+ add_metadata(&b, op->data.send_status_from_server.trailing_metadata,
+ op->data.send_status_from_server.trailing_metadata_count);
+ break;
+ case GRPC_OP_RECV_INITIAL_METADATA:
+ gpr_asprintf(&tmp, "RECV_INITIAL_METADATA ptr=%p",
+ op->data.recv_initial_metadata);
+ gpr_strvec_add(&b, tmp);
+ break;
+ case GRPC_OP_RECV_MESSAGE:
+ gpr_asprintf(&tmp, "RECV_MESSAGE ptr=%p", op->data.recv_message);
+ gpr_strvec_add(&b, tmp);
+ break;
+ case GRPC_OP_RECV_STATUS_ON_CLIENT:
+ gpr_asprintf(&tmp,
+ "RECV_STATUS_ON_CLIENT metadata=%p status=%p details=%p",
+ op->data.recv_status_on_client.trailing_metadata,
+ op->data.recv_status_on_client.status,
+ op->data.recv_status_on_client.status_details);
+ gpr_strvec_add(&b, tmp);
+ break;
+ case GRPC_OP_RECV_CLOSE_ON_SERVER:
+ gpr_asprintf(&tmp, "RECV_CLOSE_ON_SERVER cancelled=%p",
+ op->data.recv_close_on_server.cancelled);
+ gpr_strvec_add(&b, tmp);
+ }
+ out = gpr_strvec_flatten(&b, NULL);
+ gpr_strvec_destroy(&b);
+
+ return out;
+}
+
+void grpc_call_log_batch(char *file, int line, gpr_log_severity severity,
+ grpc_call *call, const grpc_op *ops, size_t nops,
+ void *tag) {
+ char *tmp;
+ size_t i;
+ gpr_log(file, line, severity,
+ "grpc_call_start_batch(%p, %p, %d, 0x%x)", call, ops, nops, tag);
+ for(i = 0; i < nops; i++) {
+ tmp = grpc_op_string(&ops[i]);
+ gpr_log(file, line, severity, "ops[%d]: %s", i, tmp);
+ gpr_free(tmp);
+ }
+}
diff --git a/src/core/surface/init.c b/src/core/surface/init.c
index e48c420..d4f0eb4 100644
--- a/src/core/surface/init.c
+++ b/src/core/surface/init.c
@@ -36,6 +36,7 @@
#include "src/core/debug/trace.h"
#include "src/core/statistics/census_interface.h"
#include "src/core/channel/channel_stack.h"
+#include "src/core/surface/call.h"
#include "src/core/surface/init.h"
#include "src/core/surface/surface_trace.h"
#include "src/core/transport/chttp2_transport.h"
@@ -57,6 +58,7 @@
grpc_register_tracer("channel", &grpc_trace_channel);
grpc_register_tracer("surface", &grpc_surface_trace);
grpc_register_tracer("http", &grpc_http_trace);
+ grpc_register_tracer("batch", &grpc_trace_batch);
grpc_security_pre_init();
grpc_tracer_init("GRPC_TRACE");
grpc_iomgr_init();
@@ -82,4 +84,3 @@
gpr_mu_unlock(&g_init_mu);
return r;
}
-
diff --git a/src/core/tsi/ssl_transport_security.c b/src/core/tsi/ssl_transport_security.c
index 33645ca..018ddc4 100644
--- a/src/core/tsi/ssl_transport_security.c
+++ b/src/core/tsi/ssl_transport_security.c
@@ -567,7 +567,8 @@
EC_KEY* ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
if (!SSL_CTX_set_tmp_ecdh(context, ecdh)) {
gpr_log(GPR_ERROR, "Could not set ephemeral ECDH key.");
- result = TSI_INTERNAL_ERROR;
+ EC_KEY_free(ecdh);
+ return TSI_INTERNAL_ERROR;
}
SSL_CTX_set_options(context, SSL_OP_SINGLE_ECDH_USE);
EC_KEY_free(ecdh);
@@ -604,6 +605,7 @@
unsigned char* current;
*protocol_name_list = NULL;
*protocol_name_list_length = 0;
+ if (num_alpn_protocols == 0) return TSI_INVALID_ARGUMENT;
for (i = 0; i < num_alpn_protocols; i++) {
if (alpn_protocols_lengths[i] == 0) {
gpr_log(GPR_ERROR, "Invalid 0-length protocol name.");
diff --git a/src/php/ext/grpc/event.h b/src/cpp/client/generic_stub.cc
old mode 100755
new mode 100644
similarity index 76%
rename from src/php/ext/grpc/event.h
rename to src/cpp/client/generic_stub.cc
index ef5846a..3bf7bdf
--- a/src/php/ext/grpc/event.h
+++ b/src/cpp/client/generic_stub.cc
@@ -31,21 +31,21 @@
*
*/
-#ifndef NET_GRPC_PHP_GRPC_EVENT_H_
-#define NET_GRPC_PHP_GRPC_EVENT_H_
+#include <grpc++/generic_stub.h>
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include <grpc++/impl/rpc_method.h>
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "php_grpc.h"
+namespace grpc {
-#include "grpc/grpc.h"
+// begin a call to a named method
+std::unique_ptr<GenericClientAsyncReaderWriter> GenericStub::Call(
+ ClientContext* context, const grpc::string& method,
+ CompletionQueue* cq, void* tag) {
+ return std::unique_ptr<GenericClientAsyncReaderWriter>(
+ new GenericClientAsyncReaderWriter(
+ channel_.get(), cq, RpcMethod(method.c_str()), context, tag));
+}
-/* Create a new Event object that wraps an existing grpc_event struct */
-zval *grpc_php_convert_event(grpc_event *event);
-#endif /* NET_GRPC_PHP_GRPC_COMPLETION_CHANNEL_H */
+} // namespace grpc
+
diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc
index f3ca430..8945b03 100644
--- a/src/cpp/client/insecure_credentials.cc
+++ b/src/cpp/client/insecure_credentials.cc
@@ -31,8 +31,6 @@
*
*/
-#include <string>
-
#include <grpc/grpc.h>
#include <grpc/support/log.h>
diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc
index e3c6637..d6f9acc 100644
--- a/src/cpp/client/secure_credentials.cc
+++ b/src/cpp/client/secure_credentials.cc
@@ -31,8 +31,6 @@
*
*/
-#include <string>
-
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc
index 5c26a1a..1599e51 100644
--- a/src/cpp/common/call.cc
+++ b/src/cpp/common/call.cc
@@ -148,7 +148,7 @@
// TODO(yangg) handle duplicates?
metadata->insert(std::pair<grpc::string, grpc::string>(
arr->metadata[i].key,
- {arr->metadata[i].value, arr->metadata[i].value_length}));
+ grpc::string(arr->metadata[i].value, arr->metadata[i].value_length)));
}
grpc_metadata_array_destroy(arr);
grpc_metadata_array_init(arr);
@@ -186,6 +186,7 @@
void CallOpBuffer::AddRecvMessage(ByteBuffer* message) {
recv_message_buffer_ = message;
+ recv_message_buffer_->Clear();
}
void CallOpBuffer::AddClientSendClose() { client_send_close_ = true; }
diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc
index 88f7a9b..49d69a3 100644
--- a/src/cpp/server/secure_server_credentials.cc
+++ b/src/cpp/server/secure_server_credentials.cc
@@ -59,9 +59,12 @@
std::shared_ptr<ServerCredentials> SslServerCredentials(
const SslServerCredentialsOptions& options) {
std::vector<grpc_ssl_pem_key_cert_pair> pem_key_cert_pairs;
- for (const auto& key_cert_pair : options.pem_key_cert_pairs) {
- pem_key_cert_pairs.push_back(
- {key_cert_pair.private_key.c_str(), key_cert_pair.cert_chain.c_str()});
+ for (auto key_cert_pair = options.pem_key_cert_pairs.begin();
+ key_cert_pair != options.pem_key_cert_pairs.end();
+ key_cert_pair++) {
+ grpc_ssl_pem_key_cert_pair p = {key_cert_pair->private_key.c_str(),
+ key_cert_pair->cert_chain.c_str()};
+ pem_key_cert_pairs.push_back(p);
}
grpc_server_credentials* c_creds = grpc_ssl_server_credentials_create(
options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(),
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 5a4ca69..bd0a237 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -107,6 +107,7 @@
request_payload_(mrd->request_payload_),
method_(mrd->method_) {
ctx_.call_ = mrd->call_;
+ ctx_.cq_ = &cq_;
GPR_ASSERT(mrd->in_flight_);
mrd->in_flight_ = false;
mrd->request_metadata_.count = 0;
@@ -247,8 +248,8 @@
// Start processing rpcs.
if (!sync_methods_.empty()) {
- for (auto& m : sync_methods_) {
- m.Request(server_);
+ for (auto m = sync_methods_.begin(); m != sync_methods_.end(); m++) {
+ m->Request(server_);
}
ScheduleCallback();
@@ -364,6 +365,7 @@
}
}
ctx->call_ = call_;
+ ctx->cq_ = cq_;
Call call(call_, server_, cq_);
if (orig_status && call_) {
ctx->BeginCompletionOp(&call);
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc
index 58bf9d9..c5e115f 100644
--- a/src/cpp/server/server_builder.cc
+++ b/src/cpp/server/server_builder.cc
@@ -86,24 +86,26 @@
thread_pool_owned = true;
}
std::unique_ptr<Server> server(new Server(thread_pool_, thread_pool_owned));
- for (auto* service : services_) {
- if (!server->RegisterService(service)) {
+ for (auto service = services_.begin(); service != services_.end();
+ service++) {
+ if (!server->RegisterService(*service)) {
return nullptr;
}
}
- for (auto* service : async_services_) {
- if (!server->RegisterAsyncService(service)) {
+ for (auto service = async_services_.begin();
+ service != async_services_.end(); service++) {
+ if (!server->RegisterAsyncService(*service)) {
return nullptr;
}
}
if (generic_service_) {
server->RegisterAsyncGenericService(generic_service_);
}
- for (auto& port : ports_) {
- int r = server->AddListeningPort(port.addr, port.creds.get());
+ for (auto port = ports_.begin(); port != ports_.end(); port++) {
+ int r = server->AddListeningPort(port->addr, port->creds.get());
if (!r) return nullptr;
- if (port.selected_port != nullptr) {
- *port.selected_port = r;
+ if (port->selected_port != nullptr) {
+ *port->selected_port = r;
}
}
if (!server->Start()) {
diff --git a/src/cpp/server/thread_pool.cc b/src/cpp/server/thread_pool.cc
index d3013b8..80c9611 100644
--- a/src/cpp/server/thread_pool.cc
+++ b/src/cpp/server/thread_pool.cc
@@ -35,28 +35,29 @@
namespace grpc {
+void ThreadPool::ThreadFunc() {
+ for (;;) {
+ // Wait until work is available or we are shutting down.
+ std::unique_lock<std::mutex> lock(mu_);
+ if (!shutdown_ && callbacks_.empty()) {
+ cv_.wait(lock);
+ }
+ // Drain callbacks before considering shutdown to ensure all work
+ // gets completed.
+ if (!callbacks_.empty()) {
+ auto cb = callbacks_.front();
+ callbacks_.pop();
+ lock.unlock();
+ cb();
+ } else if (shutdown_) {
+ return;
+ }
+ }
+}
+
ThreadPool::ThreadPool(int num_threads) : shutdown_(false) {
for (int i = 0; i < num_threads; i++) {
- threads_.push_back(std::thread([this]() {
- for (;;) {
- // Wait until work is available or we are shutting down.
- auto have_work = [this]() { return shutdown_ || !callbacks_.empty(); };
- std::unique_lock<std::mutex> lock(mu_);
- if (!have_work()) {
- cv_.wait(lock, have_work);
- }
- // Drain callbacks before considering shutdown to ensure all work
- // gets completed.
- if (!callbacks_.empty()) {
- auto cb = callbacks_.front();
- callbacks_.pop();
- lock.unlock();
- cb();
- } else if (shutdown_) {
- return;
- }
- }
- }));
+ threads_.push_back(std::thread(&ThreadPool::ThreadFunc, this));
}
}
@@ -66,8 +67,8 @@
shutdown_ = true;
cv_.notify_all();
}
- for (auto& t : threads_) {
- t.join();
+ for (auto t = threads_.begin(); t != threads_.end(); t++) {
+ t->join();
}
}
diff --git a/src/cpp/server/thread_pool.h b/src/cpp/server/thread_pool.h
index 6225d82..41e2009 100644
--- a/src/cpp/server/thread_pool.h
+++ b/src/cpp/server/thread_pool.h
@@ -58,6 +58,8 @@
bool shutdown_;
std::queue<std::function<void()>> callbacks_;
std::vector<std::thread> threads_;
+
+ void ThreadFunc();
};
} // namespace grpc
diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index 77804cf..3341486 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -318,8 +318,8 @@
empty_stream: emptyStream,
cancel_after_begin: cancelAfterBegin,
cancel_after_first_response: cancelAfterFirstResponse,
- compute_engine_creds: _.partial(authTest, AUTH_USER),
- service_account_creds: _.partial(authTest, COMPUTE_ENGINE_USER)
+ compute_engine_creds: _.partial(authTest, COMPUTE_ENGINE_USER),
+ service_account_creds: _.partial(authTest, AUTH_USER)
};
/**
diff --git a/src/php/bin/interop_client.sh b/src/php/bin/interop_client.sh
index 2c61ea8..22e4a49 100755
--- a/src/php/bin/interop_client.sh
+++ b/src/php/bin/interop_client.sh
@@ -31,5 +31,8 @@
set +e
cd $(dirname $0)
-php -d extension_dir=../ext/grpc/modules/ -d extension=grpc.so \
+
+module_dir=`php --version | grep -q 'PHP 5.6' && echo '../ext/grpc' || echo '../ext/grpc/modules'`
+
+php -d extension_dir=$module_dir -d extension=grpc.so \
../tests/interop/interop_client.php $@ 1>&2
diff --git a/src/php/bin/run_tests.sh b/src/php/bin/run_tests.sh
index c3358ed..1335672 100755
--- a/src/php/bin/run_tests.sh
+++ b/src/php/bin/run_tests.sh
@@ -34,13 +34,15 @@
cd $(dirname $0)
default_extension_dir=`php -i | grep extension_dir | sed 's/.*=> //g'`
+module_dir=`php --version | grep -q 'PHP 5.6' && echo '../ext/grpc' || echo '../ext/grpc/modules'`
+
# sym-link in system supplied extensions
for f in $default_extension_dir/*.so
do
- ln -s $f ../ext/grpc/modules/$(basename $f) &> /dev/null || true
+ ln -s $f $module_dir/$(basename $f) &> /dev/null || true
done
php \
- -d extension_dir=../ext/grpc/modules/ \
+ -d extension_dir=$module_dir \
-d extension=grpc.so \
`which phpunit` -v --debug --strict ../tests/unit_tests
diff --git a/src/php/composer.json b/src/php/composer.json
new file mode 100644
index 0000000..dca61a9
--- /dev/null
+++ b/src/php/composer.json
@@ -0,0 +1,15 @@
+{
+ "name": "grpc/grpc",
+ "description": "gRPC library for PHP",
+ "version": "0.2.0",
+ "homepage": "http://grpc.io",
+ "license": "BSD-3-Clause",
+ "require": {
+ "php": ">=5.5.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "Grpc\\": "lib/Grpc/"
+ }
+ }
+}
diff --git a/src/php/composer.lock b/src/php/composer.lock
new file mode 100644
index 0000000..47fc70f
--- /dev/null
+++ b/src/php/composer.lock
@@ -0,0 +1,19 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
+ ],
+ "hash": "65467a098f5fd8b8fe5f7f6e10226f8a",
+ "packages": [],
+ "packages-dev": [],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": {
+ "php": ">=5.5.0"
+ },
+ "platform-dev": []
+}
diff --git a/src/php/ext/grpc/byte_buffer.c b/src/php/ext/grpc/byte_buffer.c
index 1ced1bf..4f3e6b6 100644
--- a/src/php/ext/grpc/byte_buffer.c
+++ b/src/php/ext/grpc/byte_buffer.c
@@ -35,18 +35,18 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "ext/spl/spl_exceptions.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
+#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
#include <string.h>
#include "byte_buffer.h"
-#include "grpc/grpc.h"
-#include "grpc/support/slice.h"
+#include <grpc/grpc.h>
+#include <grpc/support/slice.h>
grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) {
gpr_slice slice = gpr_slice_from_copied_buffer(string, length);
@@ -57,6 +57,11 @@
void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,
size_t *out_length) {
+ if (buffer == NULL) {
+ *out_string = NULL;
+ *out_length = 0;
+ return;
+ }
size_t length = grpc_byte_buffer_length(buffer);
char *string = ecalloc(length + 1, sizeof(char));
size_t offset = 0;
diff --git a/src/php/ext/grpc/byte_buffer.h b/src/php/ext/grpc/byte_buffer.h
index 7a40638..0e9d1e7 100644
--- a/src/php/ext/grpc/byte_buffer.h
+++ b/src/php/ext/grpc/byte_buffer.h
@@ -34,7 +34,7 @@
#ifndef NET_GRPC_PHP_GRPC_BYTE_BUFFER_H_
#define NET_GRPC_PHP_GRPC_BYTE_BUFFER_H_
-#include "grpc/grpc.h"
+#include <grpc/grpc.h>
grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length);
diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c
index 7987471..6e83e79 100644
--- a/src/php/ext/grpc/call.c
+++ b/src/php/ext/grpc/call.c
@@ -37,23 +37,23 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "ext/spl/spl_exceptions.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
+#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
-#include "zend_exceptions.h"
-#include "zend_hash.h"
+#include <zend_exceptions.h>
+#include <zend_hash.h>
#include <stdbool.h>
-#include "grpc/support/log.h"
-#include "grpc/grpc.h"
+#include <grpc/support/log.h>
+#include <grpc/support/alloc.h>
+#include <grpc/grpc.h>
#include "timeval.h"
#include "channel.h"
-#include "completion_queue.h"
#include "byte_buffer.h"
zend_class_entry *grpc_ce_call;
@@ -61,7 +61,19 @@
/* 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;
+ grpc_event *event;
if (call->owned && call->wrapped != NULL) {
+ if (call->queue != NULL) {
+ grpc_completion_queue_shutdown(call->queue);
+ event = grpc_completion_queue_next(call->queue, gpr_inf_future);
+ while (event != NULL) {
+ if (event->type == GRPC_QUEUE_SHUTDOWN) {
+ break;
+ }
+ event = grpc_completion_queue_next(call->queue, gpr_inf_future);
+ }
+ grpc_completion_queue_destroy(call->queue);
+ }
grpc_call_destroy(call->wrapped);
}
efree(call);
@@ -88,17 +100,23 @@
/* 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 *grpc_php_wrap_call(grpc_call *wrapped, grpc_completion_queue *queue,
+ bool owned) {
zval *call_object;
MAKE_STD_ZVAL(call_object);
object_init_ex(call_object, grpc_ce_call);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(call_object TSRMLS_CC);
call->wrapped = wrapped;
+ call->queue = queue;
return call_object;
}
-zval *grpc_call_create_metadata_array(int count, grpc_metadata *elements) {
+/* Creates and returns a PHP array object with the data in a
+ * grpc_metadata_array. Returns NULL on failure */
+zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array) {
+ int count = metadata_array->count;
+ grpc_metadata *elements = metadata_array->metadata;
int i;
zval *array;
zval **data = NULL;
@@ -139,6 +157,64 @@
return array;
}
+/* Populates a grpc_metadata_array with the data in a PHP array object.
+ Returns true on success and false on failure */
+bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
+ zval **inner_array;
+ zval **value;
+ HashTable *array_hash;
+ HashPosition array_pointer;
+ HashTable *inner_array_hash;
+ HashPosition inner_array_pointer;
+ char *key;
+ uint key_len;
+ ulong index;
+ if (Z_TYPE_P(array) != IS_ARRAY) {
+ return false;
+ }
+ grpc_metadata_array_init(metadata);
+ array_hash = Z_ARRVAL_P(array);
+ for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer);
+ zend_hash_get_current_data_ex(array_hash, (void**)&inner_array,
+ &array_pointer) == SUCCESS;
+ zend_hash_move_forward_ex(array_hash, &array_pointer)) {
+ if (zend_hash_get_current_key_ex(array_hash, &key, &key_len, &index, 0,
+ &array_pointer) != HASH_KEY_IS_STRING) {
+ return false;
+ }
+ if (Z_TYPE_P(*inner_array) != IS_ARRAY) {
+ return false;
+ }
+ inner_array_hash = Z_ARRVAL_P(*inner_array);
+ metadata->capacity += zend_hash_num_elements(inner_array_hash);
+ }
+ metadata->metadata = gpr_malloc(metadata->capacity * sizeof(grpc_metadata));
+ for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer);
+ zend_hash_get_current_data_ex(array_hash, (void**)&inner_array,
+ &array_pointer) == SUCCESS;
+ zend_hash_move_forward_ex(array_hash, &array_pointer)) {
+ if (zend_hash_get_current_key_ex(array_hash, &key, &key_len, &index, 0,
+ &array_pointer) != HASH_KEY_IS_STRING) {
+ return false;
+ }
+ inner_array_hash = Z_ARRVAL_P(*inner_array);
+ for (zend_hash_internal_pointer_reset_ex(inner_array_hash,
+ &inner_array_pointer);
+ zend_hash_get_current_data_ex(inner_array_hash, (void**)&value,
+ &inner_array_pointer) == SUCCESS;
+ zend_hash_move_forward_ex(inner_array_hash, &inner_array_pointer)) {
+ if (Z_TYPE_P(*value) != IS_STRING) {
+ return false;
+ }
+ metadata->metadata[metadata->count].key = key;
+ metadata->metadata[metadata->count].value = Z_STRVAL_P(*value);
+ metadata->metadata[metadata->count].value_length = Z_STRLEN_P(*value);
+ metadata->count += 1;
+ }
+ }
+ return true;
+}
+
/**
* Constructs a new instance of the Call class.
* @param Channel $channel The channel to associate the call with. Must not be
@@ -157,9 +233,10 @@
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OsO", &channel_obj,
grpc_ce_channel, &method, &method_len,
&deadline_obj, grpc_ce_timeval) == FAILURE) {
- zend_throw_exception(spl_ce_InvalidArgumentException,
- "Call expects a Channel, a String, and a Timeval",
- 1 TSRMLS_CC);
+ zend_throw_exception(
+ spl_ce_InvalidArgumentException,
+ "Call expects a Channel, a String, and a Timeval",
+ 1 TSRMLS_CC);
return;
}
wrapped_grpc_channel *channel =
@@ -175,289 +252,250 @@
wrapped_grpc_timeval *deadline =
(wrapped_grpc_timeval *)zend_object_store_get_object(
deadline_obj TSRMLS_CC);
- call->wrapped = grpc_channel_create_call_old(
- channel->wrapped, method, channel->target, deadline->wrapped);
+ call->queue = grpc_completion_queue_create();
+ call->wrapped = grpc_channel_create_call(
+ channel->wrapped, call->queue, method, channel->target,
+ deadline->wrapped);
}
/**
- * Add metadata to the call. All array keys must be strings. If the value is a
- * string, it is added as a key/value pair. If it is an array, each value is
- * added paired with the same string
- * @param array $metadata The metadata to add
- * @param long $flags A bitwise combination of the Grpc\WRITE_* constants
- * (optional)
- * @return Void
+ * Start a batch of RPC actions.
+ * @param array batch Array of actions to take
+ * @return object Object with results of all actions
*/
-PHP_METHOD(Call, add_metadata) {
+PHP_METHOD(Call, start_batch) {
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
- grpc_metadata metadata;
- grpc_call_error error_code;
+ grpc_op ops[8];
+ size_t op_num = 0;
zval *array;
- zval **inner_array;
zval **value;
+ zval **inner_value;
HashTable *array_hash;
HashPosition array_pointer;
- HashTable *inner_array_hash;
- HashPosition inner_array_pointer;
+ HashTable *status_hash;
char *key;
uint key_len;
ulong index;
- long flags = 0;
- /* "a|l" == 1 array, 1 optional long */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &flags) ==
+ grpc_metadata_array metadata;
+ grpc_metadata_array trailing_metadata;
+ grpc_metadata_array recv_metadata;
+ grpc_metadata_array recv_trailing_metadata;
+ grpc_status_code status;
+ char *status_details = NULL;
+ size_t status_details_capacity = 0;
+ grpc_byte_buffer *message;
+ int cancelled;
+ grpc_call_error error;
+ grpc_event *event;
+ zval *result;
+ char *message_str;
+ size_t message_len;
+ zval *recv_status;
+ grpc_metadata_array_init(&metadata);
+ grpc_metadata_array_init(&trailing_metadata);
+ grpc_metadata_array_init(&recv_metadata);
+ grpc_metadata_array_init(&recv_trailing_metadata);
+ MAKE_STD_ZVAL(result);
+ object_init(result);
+ /* "a" == 1 array */
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) ==
FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
- "add_metadata expects an array and an optional long",
- 1 TSRMLS_CC);
- return;
+ "start_batch expects an array", 1 TSRMLS_CC);
+ goto cleanup;
}
array_hash = Z_ARRVAL_P(array);
for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer);
- zend_hash_get_current_data_ex(array_hash, (void**)&inner_array,
+ zend_hash_get_current_data_ex(array_hash, (void**)&value,
&array_pointer) == SUCCESS;
zend_hash_move_forward_ex(array_hash, &array_pointer)) {
if (zend_hash_get_current_key_ex(array_hash, &key, &key_len, &index, 0,
- &array_pointer) != HASH_KEY_IS_STRING) {
+ &array_pointer) != HASH_KEY_IS_LONG) {
zend_throw_exception(spl_ce_InvalidArgumentException,
- "metadata keys must be strings", 1 TSRMLS_CC);
- return;
+ "batch keys must be integers", 1 TSRMLS_CC);
+ goto cleanup;
}
- if (Z_TYPE_P(*inner_array) != IS_ARRAY) {
- zend_throw_exception(spl_ce_InvalidArgumentException,
- "metadata values must be arrays",
- 1 TSRMLS_CC);
- return;
- }
- inner_array_hash = Z_ARRVAL_P(*inner_array);
- for (zend_hash_internal_pointer_reset_ex(inner_array_hash,
- &inner_array_pointer);
- zend_hash_get_current_data_ex(inner_array_hash, (void**)&value,
- &inner_array_pointer) == SUCCESS;
- zend_hash_move_forward_ex(inner_array_hash, &inner_array_pointer)) {
- if (Z_TYPE_P(*value) != IS_STRING) {
+ switch(index) {
+ case GRPC_OP_SEND_INITIAL_METADATA:
+ if (!create_metadata_array(*value, &metadata)) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "Bad metadata value given", 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ ops[op_num].data.send_initial_metadata.count =
+ metadata.count;
+ ops[op_num].data.send_initial_metadata.metadata =
+ metadata.metadata;
+ break;
+ case GRPC_OP_SEND_MESSAGE:
+ if (Z_TYPE_PP(value) != IS_STRING) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "Expected a string for send message",
+ 1 TSRMLS_CC);
+ }
+ ops[op_num].data.send_message =
+ string_to_byte_buffer(Z_STRVAL_PP(value), Z_STRLEN_PP(value));
+ break;
+ case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
+ break;
+ case GRPC_OP_SEND_STATUS_FROM_SERVER:
+ status_hash = Z_ARRVAL_PP(value);
+ if (zend_hash_find(status_hash, "metadata", sizeof("metadata"),
+ (void **)&inner_value) == SUCCESS) {
+ if (!create_metadata_array(*inner_value, &trailing_metadata)) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "Bad trailing metadata value given",
+ 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ ops[op_num].data.send_status_from_server.trailing_metadata =
+ trailing_metadata.metadata;
+ ops[op_num].data.send_status_from_server.trailing_metadata_count =
+ trailing_metadata.count;
+ }
+ if (zend_hash_find(status_hash, "code", sizeof("code"),
+ (void**)&inner_value) == SUCCESS) {
+ if (Z_TYPE_PP(inner_value) != IS_LONG) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "Status code must be an integer",
+ 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ ops[op_num].data.send_status_from_server.status =
+ Z_LVAL_PP(inner_value);
+ } else {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "Integer status code is required",
+ 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ if (zend_hash_find(status_hash, "details", sizeof("details"),
+ (void**)&inner_value) == SUCCESS) {
+ if (Z_TYPE_PP(inner_value) != IS_STRING) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "Status details must be a string",
+ 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ ops[op_num].data.send_status_from_server.status_details =
+ Z_STRVAL_PP(inner_value);
+ } else {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ "String status details is required",
+ 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ break;
+ case GRPC_OP_RECV_INITIAL_METADATA:
+ ops[op_num].data.recv_initial_metadata = &recv_metadata;
+ break;
+ case GRPC_OP_RECV_MESSAGE:
+ ops[op_num].data.recv_message = &message;
+ break;
+ case GRPC_OP_RECV_STATUS_ON_CLIENT:
+ ops[op_num].data.recv_status_on_client.trailing_metadata =
+ &recv_trailing_metadata;
+ ops[op_num].data.recv_status_on_client.status = &status;
+ ops[op_num].data.recv_status_on_client.status_details =
+ &status_details;
+ ops[op_num].data.recv_status_on_client.status_details_capacity =
+ &status_details_capacity;
+ break;
+ case GRPC_OP_RECV_CLOSE_ON_SERVER:
+ ops[op_num].data.recv_close_on_server.cancelled = &cancelled;
+ break;
+ default:
zend_throw_exception(spl_ce_InvalidArgumentException,
- "metadata values must be arrays of strings",
- 1 TSRMLS_CC);
- return;
- }
- metadata.key = key;
- metadata.value = Z_STRVAL_P(*value);
- metadata.value_length = Z_STRLEN_P(*value);
- error_code = grpc_call_add_metadata_old(call->wrapped, &metadata, 0u);
- MAYBE_THROW_CALL_ERROR(add_metadata, error_code);
+ "Unrecognized key in batch", 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ ops[op_num].op = (grpc_op_type)index;
+ op_num++;
+ }
+ error = grpc_call_start_batch(call->wrapped, ops, op_num, call->wrapped);
+ if (error != GRPC_CALL_OK) {
+ zend_throw_exception(spl_ce_LogicException,
+ "start_batch was called incorrectly",
+ (long)error TSRMLS_CC);
+ goto cleanup;
+ }
+ event = grpc_completion_queue_pluck(call->queue, call->wrapped,
+ gpr_inf_future);
+ if (event->data.op_complete != GRPC_OP_OK) {
+ zend_throw_exception(spl_ce_LogicException,
+ "The batch failed for some reason",
+ 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ for (int i = 0; i < op_num; i++) {
+ switch(ops[i].op) {
+ case GRPC_OP_SEND_INITIAL_METADATA:
+ add_property_bool(result, "send_metadata", true);
+ break;
+ case GRPC_OP_SEND_MESSAGE:
+ add_property_bool(result, "send_message", true);
+ break;
+ case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
+ add_property_bool(result, "send_close", true);
+ break;
+ case GRPC_OP_SEND_STATUS_FROM_SERVER:
+ add_property_bool(result, "send_status", true);
+ break;
+ case GRPC_OP_RECV_INITIAL_METADATA:
+ add_property_zval(result, "metadata",
+ grpc_parse_metadata_array(&recv_metadata));
+ break;
+ case GRPC_OP_RECV_MESSAGE:
+ byte_buffer_to_string(message, &message_str, &message_len);
+ if (message_str == NULL) {
+ add_property_null(result, "message");
+ } else {
+ add_property_stringl(result, "message", message_str, message_len,
+ false);
+ }
+ break;
+ case GRPC_OP_RECV_STATUS_ON_CLIENT:
+ MAKE_STD_ZVAL(recv_status);
+ object_init(recv_status);
+ add_property_zval(recv_status, "metadata",
+ grpc_parse_metadata_array(&recv_trailing_metadata));
+ add_property_long(recv_status, "code", status);
+ add_property_string(recv_status, "details", status_details, true);
+ add_property_zval(result, "status", recv_status);
+ break;
+ case GRPC_OP_RECV_CLOSE_ON_SERVER:
+ add_property_bool(result, "cancelled", cancelled);
+ break;
+ default:
+ break;
}
}
+cleanup:
+ grpc_metadata_array_destroy(&metadata);
+ grpc_metadata_array_destroy(&trailing_metadata);
+ grpc_metadata_array_destroy(&recv_metadata);
+ grpc_metadata_array_destroy(&recv_trailing_metadata);
+ if (status_details != NULL) {
+ gpr_free(status_details);
+ }
+ RETURN_DESTROY_ZVAL(result);
}
/**
- * Invoke the RPC. Starts sending metadata and request headers over the wire
- * @param CompletionQueue $queue The completion queue to use with this call
- * @param long $metadata_tag The tag to associate with returned 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 Void
- */
-PHP_METHOD(Call, invoke) {
- grpc_call_error error_code;
- long tag1;
- long tag2;
- zval *queue_obj;
- long flags = 0;
- /* "Oll|l" == 1 Object, 3 mandatory longs, 1 optional long */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Oll|l", &queue_obj,
- grpc_ce_completion_queue, &tag1, &tag2,
- &flags) == FAILURE) {
- zend_throw_exception(
- spl_ce_InvalidArgumentException,
- "invoke needs a CompletionQueue, 2 longs, and an optional long",
- 1 TSRMLS_CC);
- return;
- }
- add_property_zval(getThis(), "completion_queue", queue_obj);
- wrapped_grpc_call *call =
- (wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
- wrapped_grpc_completion_queue *queue =
- (wrapped_grpc_completion_queue *)zend_object_store_get_object(
- queue_obj TSRMLS_CC);
- error_code = grpc_call_invoke_old(call->wrapped, queue->wrapped, (void *)tag1,
- (void *)tag2, (gpr_uint32)flags);
- MAYBE_THROW_CALL_ERROR(invoke, error_code);
-}
-
-/**
- * Accept an incoming RPC, binding a completion queue to it. To be called after
- * adding metadata to the call, but before sending messages. Can only be called
- * on the server
- * @param CompletionQueue $queue The completion queue to use with this call
- * @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 Void
- */
-PHP_METHOD(Call, server_accept) {
- long tag;
- zval *queue_obj;
- grpc_call_error error_code;
- /* "Ol|l" == 1 Object, 1 long */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &queue_obj,
- grpc_ce_completion_queue, &tag) == FAILURE) {
- zend_throw_exception(
- spl_ce_InvalidArgumentException,
- "server_accept expects a CompletionQueue, a long, and an optional long",
- 1 TSRMLS_CC);
- return;
- }
- add_property_zval(getThis(), "completion_queue", queue_obj);
- wrapped_grpc_call *call =
- (wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
- wrapped_grpc_completion_queue *queue =
- (wrapped_grpc_completion_queue *)zend_object_store_get_object(
- queue_obj TSRMLS_CC);
- error_code =
- grpc_call_server_accept_old(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_old(call->wrapped, flags);
- MAYBE_THROW_CALL_ERROR(server_end_initial_metadata, error_code);
-}
-
-/**
- * Called by clients to cancel an RPC on the server.
- * @return Void
+ * 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_error error_code = grpc_call_cancel(call->wrapped);
- MAYBE_THROW_CALL_ERROR(cancel, error_code);
-}
-
-/**
- * Queue a byte buffer for writing
- * @param string $buffer The buffer to queue for writing
- * @param long $tag The tag to associate with this write
- * @param long $flags A bitwise combination of the Grpc\WRITE_* constants
- * (optional)
- * @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;
- int buffer_len;
- long tag;
- long flags = 0;
- /* "Ol|l" == 1 Object, 1 mandatory long, 1 optional long */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &buffer,
- &buffer_len, &tag, &flags) == FAILURE) {
- zend_throw_exception(spl_ce_InvalidArgumentException,
- "start_write expects a string and an optional long",
- 1 TSRMLS_CC);
- return;
- }
- error_code = grpc_call_start_write_old(
- call->wrapped, string_to_byte_buffer(buffer, buffer_len), (void *)tag,
- (gpr_uint32)flags);
- MAYBE_THROW_CALL_ERROR(start_write, error_code);
-}
-
-/**
- * Queue a status for writing
- * @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 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;
- int status_details_length;
- long tag;
- char *status_details;
- /* "lsl" == 1 long, 1 string, 1 long */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsl", &status_code,
- &status_details, &status_details_length,
- &tag) == FAILURE) {
- zend_throw_exception(
- spl_ce_InvalidArgumentException,
- "start_write_status expects a long, a string, and a long", 1 TSRMLS_CC);
- return;
- }
- error_code = grpc_call_start_write_status_old(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 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;
- /* "l" == 1 long */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag) == FAILURE) {
- zend_throw_exception(spl_ce_InvalidArgumentException,
- "writes_done expects a long", 1 TSRMLS_CC);
- return;
- }
- error_code = grpc_call_writes_done_old(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 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;
- /* "l" == 1 long */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag) == FAILURE) {
- zend_throw_exception(spl_ce_InvalidArgumentException,
- "start_read expects a long", 1 TSRMLS_CC);
- return;
- }
- error_code = grpc_call_start_read_old(call->wrapped, (void *)tag);
- MAYBE_THROW_CALL_ERROR(start_read, error_code);
+ grpc_call_cancel(call->wrapped);
}
static zend_function_entry call_methods[] = {
PHP_ME(Call, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
- 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, invoke, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Call, start_read, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Call, start_write, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Call, start_write_status, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(Call, writes_done, 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) {
zend_class_entry ce;
diff --git a/src/php/ext/grpc/call.h b/src/php/ext/grpc/call.h
index bce5d82..e7eb9a7 100644
--- a/src/php/ext/grpc/call.h
+++ b/src/php/ext/grpc/call.h
@@ -38,23 +38,12 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
#include "php_grpc.h"
-#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); \
- return; \
- } \
- } while (0)
+#include <grpc/grpc.h>
/* Class entry for the Call PHP class */
extern zend_class_entry *grpc_ce_call;
@@ -65,16 +54,18 @@
bool owned;
grpc_call *wrapped;
+ grpc_completion_queue *queue;
} wrapped_grpc_call;
/* Initializes the Call PHP class */
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, bool owned);
+zval *grpc_php_wrap_call(grpc_call *wrapped, grpc_completion_queue *queue,
+ bool owned);
/* Creates and returns a PHP associative array of metadata from a C array of
* call metadata */
-zval *grpc_call_create_metadata_array(int count, grpc_metadata *elements);
+zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array);
#endif /* NET_GRPC_PHP_GRPC_CHANNEL_H_ */
diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c
index 5e99332..51a3eae 100644
--- a/src/php/ext/grpc/channel.c
+++ b/src/php/ext/grpc/channel.c
@@ -37,21 +37,20 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "ext/spl/spl_exceptions.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
+#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
-#include "zend_exceptions.h"
+#include <zend_exceptions.h>
#include <stdbool.h>
-#include "grpc/grpc.h"
-#include "grpc/support/log.h"
-#include "grpc/grpc_security.h"
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <grpc/grpc_security.h>
-#include "completion_queue.h"
#include "server.h"
#include "credentials.h"
@@ -139,6 +138,9 @@
HashTable *array_hash;
zval **creds_obj = NULL;
wrapped_grpc_credentials *creds = NULL;
+ zval **override_obj;
+ char *override;
+ int override_len;
/* "s|a" == 1 string, 1 optional array */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &target,
&target_length, &args_array) == FAILURE) {
@@ -146,6 +148,8 @@
"Channel expects a string and an array", 1 TSRMLS_CC);
return;
}
+ override = target;
+ override_len = target_length;
if (args_array == NULL) {
channel->wrapped = grpc_channel_create(target, NULL);
} else {
@@ -162,6 +166,19 @@
*creds_obj TSRMLS_CC);
zend_hash_del(array_hash, "credentials", 12);
}
+ if (zend_hash_find(array_hash, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
+ sizeof(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
+ (void **)&override_obj) == SUCCESS) {
+ if (Z_TYPE_PP(override_obj) != IS_STRING) {
+ zend_throw_exception(spl_ce_InvalidArgumentException,
+ GRPC_SSL_TARGET_NAME_OVERRIDE_ARG
+ " must be a string",
+ 1 TSRMLS_CC);
+ return;
+ }
+ override = Z_STRVAL_PP(override_obj);
+ override_len = Z_STRLEN_PP(override_obj);
+ }
php_grpc_read_args_array(args_array, &args);
if (creds == NULL) {
channel->wrapped = grpc_channel_create(target, &args);
@@ -172,8 +189,8 @@
}
efree(args.args);
}
- channel->target = ecalloc(target_length + 1, sizeof(char));
- memcpy(channel->target, target, target_length);
+ channel->target = ecalloc(override_len + 1, sizeof(char));
+ memcpy(channel->target, override, override_len);
}
/**
diff --git a/src/php/ext/grpc/channel.h b/src/php/ext/grpc/channel.h
index 2c79668..c13fa4c 100755
--- a/src/php/ext/grpc/channel.h
+++ b/src/php/ext/grpc/channel.h
@@ -38,12 +38,12 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
#include "php_grpc.h"
-#include "grpc/grpc.h"
+#include <grpc/grpc.h>
/* Class entry for the PHP Channel class */
extern zend_class_entry *grpc_ce_channel;
diff --git a/src/php/ext/grpc/completion_queue.c b/src/php/ext/grpc/completion_queue.c
deleted file mode 100644
index 93abf5d..0000000
--- a/src/php/ext/grpc/completion_queue.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "completion_queue.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 "zend_exceptions.h"
-
-#include <stdbool.h>
-
-#include "grpc/grpc.h"
-
-#include "event.h"
-#include "timeval.h"
-
-zend_class_entry *grpc_ce_completion_queue;
-
-/* Frees and destroys a wrapped instance of grpc_completion_queue */
-void free_wrapped_grpc_completion_queue(void *object TSRMLS_DC) {
- wrapped_grpc_completion_queue *queue = NULL;
- grpc_event *event;
- queue = (wrapped_grpc_completion_queue *)object;
- if (queue->wrapped != NULL) {
- grpc_completion_queue_shutdown(queue->wrapped);
- event = grpc_completion_queue_next(queue->wrapped, gpr_inf_future);
- while (event != NULL) {
- if (event->type == GRPC_QUEUE_SHUTDOWN) {
- break;
- }
- event = grpc_completion_queue_next(queue->wrapped, gpr_inf_future);
- }
- grpc_completion_queue_destroy(queue->wrapped);
- }
- efree(queue);
-}
-
-/* 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_completion_queue(
- zend_class_entry *class_type TSRMLS_DC) {
- zend_object_value retval;
- wrapped_grpc_completion_queue *intern;
-
- intern = (wrapped_grpc_completion_queue *)emalloc(
- sizeof(wrapped_grpc_completion_queue));
- memset(intern, 0, sizeof(wrapped_grpc_completion_queue));
-
- 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_completion_queue, NULL TSRMLS_CC);
- retval.handlers = zend_get_std_object_handlers();
- return retval;
-}
-
-/**
- * Construct an instance of CompletionQueue
- */
-PHP_METHOD(CompletionQueue, __construct) {
- wrapped_grpc_completion_queue *queue =
- (wrapped_grpc_completion_queue *)zend_object_store_get_object(getThis()
- TSRMLS_CC);
- queue->wrapped = grpc_completion_queue_create();
-}
-
-/**
- * Blocks until an event is available, the completion queue is being shutdown,
- * or timeout is reached. Returns NULL on timeout, otherwise the event that
- * occurred. Callers should call event.finish once they have processed the
- * event.
- * @param Timeval $timeout The timeout for the event
- * @return Event The event that occurred
- */
-PHP_METHOD(CompletionQueue, next) {
- zval *timeout;
- /* "O" == 1 Object */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &timeout,
- grpc_ce_timeval) == FAILURE) {
- zend_throw_exception(spl_ce_InvalidArgumentException,
- "next needs a Timeval", 1 TSRMLS_CC);
- return;
- }
- wrapped_grpc_completion_queue *completion_queue =
- (wrapped_grpc_completion_queue *)zend_object_store_get_object(getThis()
- TSRMLS_CC);
- wrapped_grpc_timeval *wrapped_timeout =
- (wrapped_grpc_timeval *)zend_object_store_get_object(timeout TSRMLS_CC);
- grpc_event *event = grpc_completion_queue_next(completion_queue->wrapped,
- wrapped_timeout->wrapped);
- if (event == NULL) {
- RETURN_NULL();
- }
- zval *wrapped_event = grpc_php_convert_event(event);
- RETURN_DESTROY_ZVAL(wrapped_event);
-}
-
-PHP_METHOD(CompletionQueue, pluck) {
- long tag;
- zval *timeout;
- /* "lO" == 1 long, 1 Object */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lO", &tag, &timeout,
- grpc_ce_timeval) == FAILURE) {
- zend_throw_exception(spl_ce_InvalidArgumentException,
- "pluck needs a long and a Timeval", 1 TSRMLS_CC);
- }
- wrapped_grpc_completion_queue *completion_queue =
- (wrapped_grpc_completion_queue *)zend_object_store_get_object(getThis()
- TSRMLS_CC);
- wrapped_grpc_timeval *wrapped_timeout =
- (wrapped_grpc_timeval *)zend_object_store_get_object(timeout TSRMLS_CC);
- grpc_event *event = grpc_completion_queue_pluck(
- completion_queue->wrapped, (void *)tag, wrapped_timeout->wrapped);
- if (event == NULL) {
- RETURN_NULL();
- }
- zval *wrapped_event = grpc_php_convert_event(event);
- RETURN_DESTROY_ZVAL(wrapped_event);
-}
-
-static zend_function_entry completion_queue_methods[] = {
- PHP_ME(CompletionQueue, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
- PHP_ME(CompletionQueue, next, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(CompletionQueue, pluck, NULL, ZEND_ACC_PUBLIC) PHP_FE_END};
-
-void grpc_init_completion_queue(TSRMLS_D) {
- zend_class_entry ce;
- INIT_CLASS_ENTRY(ce, "Grpc\\CompletionQueue", completion_queue_methods);
- ce.create_object = create_wrapped_grpc_completion_queue;
- grpc_ce_completion_queue = zend_register_internal_class(&ce TSRMLS_CC);
-}
diff --git a/src/php/ext/grpc/completion_queue.h b/src/php/ext/grpc/completion_queue.h
deleted file mode 100755
index 1d386cc..0000000
--- a/src/php/ext/grpc/completion_queue.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef NET_GRPC_PHP_GRPC_COMPLETION_QUEUE_H_
-#define NET_GRPC_PHP_GRPC_COMPLETION_QUEUE_H_
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "php_grpc.h"
-
-#include "grpc/grpc.h"
-
-/* Class entry for the PHP CompletionQueue class */
-extern zend_class_entry *grpc_ce_completion_queue;
-
-/* Wrapper class for grpc_completion_queue that can be associated with a
- PHP object */
-typedef struct wrapped_grpc_completion_queue {
- zend_object std;
-
- grpc_completion_queue *wrapped;
-} wrapped_grpc_completion_queue;
-
-/* Initialize the CompletionQueue class */
-void grpc_init_completion_queue(TSRMLS_D);
-
-#endif /* NET_GRPC_PHP_GRPC_COMPLETION_QUEUE_H_ */
diff --git a/src/php/ext/grpc/config.m4 b/src/php/ext/grpc/config.m4
index 27c6778..11778e3 100755
--- a/src/php/ext/grpc/config.m4
+++ b/src/php/ext/grpc/config.m4
@@ -66,5 +66,5 @@
PHP_SUBST(GRPC_SHARED_LIBADD)
- PHP_NEW_EXTENSION(grpc, byte_buffer.c call.c channel.c completion_queue.c credentials.c event.c timeval.c server.c server_credentials.c php_grpc.c, $ext_shared, , -Wall -Werror -pedantic -std=c99)
+ PHP_NEW_EXTENSION(grpc, byte_buffer.c call.c channel.c credentials.c timeval.c server.c server_credentials.c php_grpc.c, $ext_shared, , -Wall -Werror -std=c11)
fi
diff --git a/src/php/ext/grpc/credentials.c b/src/php/ext/grpc/credentials.c
index a94b0ea..a262b99 100644
--- a/src/php/ext/grpc/credentials.c
+++ b/src/php/ext/grpc/credentials.c
@@ -37,17 +37,17 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "ext/spl/spl_exceptions.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
+#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
-#include "zend_exceptions.h"
-#include "zend_hash.h"
+#include <zend_exceptions.h>
+#include <zend_hash.h>
-#include "grpc/grpc.h"
-#include "grpc/grpc_security.h"
+#include <grpc/grpc.h>
+#include <grpc/grpc_security.h>
zend_class_entry *grpc_ce_credentials;
diff --git a/src/php/ext/grpc/event.c b/src/php/ext/grpc/event.c
deleted file mode 100644
index 452c4b8..0000000
--- a/src/php/ext/grpc/event.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "event.h"
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "php_grpc.h"
-
-#include <stdbool.h>
-
-#include "grpc/grpc.h"
-
-#include "byte_buffer.h"
-#include "call.h"
-#include "timeval.h"
-
-/* 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;
- size_t method_len;
- char *host_string;
- size_t host_len;
- 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:
- add_property_null(event_object, "data");
- break;
- case GRPC_READ:
- if (event->data.read == NULL) {
- add_property_null(event_object, "data");
- } else {
- byte_buffer_to_string(event->data.read, &read_string, &read_len);
- add_property_stringl(event_object, "data", read_string, read_len, true);
- }
- break;
- case GRPC_WRITE_ACCEPTED:
- add_property_long(event_object, "data", (long)event->data.write_accepted);
- break;
- case GRPC_FINISH_ACCEPTED:
- add_property_long(event_object, "data",
- (long)event->data.finish_accepted);
- break;
- case GRPC_CLIENT_METADATA_READ:
- 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(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(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(data_object, "details", detail_string, true);
- }
- 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(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(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(data_object, "host", host_string, false);
- add_property_zval(
- data_object, "absolute_timeout",
- grpc_php_wrap_timeval(event->data.server_rpc_new.deadline));
- 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:
- add_property_null(event_object, "data");
- break;
- }
- grpc_event_finish(event);
- return event_object;
-}
diff --git a/src/php/ext/grpc/php_grpc.c b/src/php/ext/grpc/php_grpc.c
index 67e366c..3e669ec 100644
--- a/src/php/ext/grpc/php_grpc.c
+++ b/src/php/ext/grpc/php_grpc.c
@@ -34,8 +34,6 @@
#include "call.h"
#include "channel.h"
#include "server.h"
-#include "completion_queue.h"
-#include "event.h"
#include "timeval.h"
#include "credentials.h"
#include "server_credentials.h"
@@ -44,9 +42,9 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
#include "php_grpc.h"
// ZEND_DECLARE_MODULE_GLOBALS(grpc)
@@ -127,27 +125,12 @@
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_INVALID_FLAGS",
GRPC_CALL_ERROR_INVALID_FLAGS, CONST_CS);
- /* Register op error constants */
- REGISTER_LONG_CONSTANT("Grpc\\OP_OK", GRPC_OP_OK, CONST_CS);
- REGISTER_LONG_CONSTANT("Grpc\\OP_ERROR", GRPC_OP_ERROR, CONST_CS);
-
/* Register flag constants */
REGISTER_LONG_CONSTANT("Grpc\\WRITE_BUFFER_HINT", GRPC_WRITE_BUFFER_HINT,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\WRITE_NO_COMPRESS", GRPC_WRITE_NO_COMPRESS,
CONST_CS);
- /* Register completion type constants */
- REGISTER_LONG_CONSTANT("Grpc\\QUEUE_SHUTDOWN", GRPC_QUEUE_SHUTDOWN, CONST_CS);
- REGISTER_LONG_CONSTANT("Grpc\\READ", GRPC_READ, CONST_CS);
- REGISTER_LONG_CONSTANT("Grpc\\FINISH_ACCEPTED", GRPC_FINISH_ACCEPTED,
- CONST_CS);
- REGISTER_LONG_CONSTANT("Grpc\\WRITE_ACCEPTED", GRPC_WRITE_ACCEPTED, CONST_CS);
- REGISTER_LONG_CONSTANT("Grpc\\CLIENT_METADATA_READ",
- GRPC_CLIENT_METADATA_READ, CONST_CS);
- REGISTER_LONG_CONSTANT("Grpc\\FINISHED", GRPC_FINISHED, CONST_CS);
- REGISTER_LONG_CONSTANT("Grpc\\SERVER_RPC_NEW", GRPC_SERVER_RPC_NEW, CONST_CS);
-
/* Register status constants */
REGISTER_LONG_CONSTANT("Grpc\\STATUS_OK", GRPC_STATUS_OK, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_CANCELLED", GRPC_STATUS_CANCELLED,
@@ -181,10 +164,27 @@
REGISTER_LONG_CONSTANT("Grpc\\STATUS_DATA_LOSS", GRPC_STATUS_DATA_LOSS,
CONST_CS);
+ /* Register op type constants */
+ REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_INITIAL_METADATA",
+ GRPC_OP_SEND_INITIAL_METADATA, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_MESSAGE",
+ GRPC_OP_SEND_MESSAGE, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_CLOSE_FROM_CLIENT",
+ GRPC_OP_SEND_CLOSE_FROM_CLIENT, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\OP_SEND_STATUS_FROM_SERVER",
+ GRPC_OP_SEND_STATUS_FROM_SERVER, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_INITIAL_METADATA",
+ GRPC_OP_RECV_INITIAL_METADATA, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_MESSAGE",
+ GRPC_OP_RECV_MESSAGE, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_STATUS_ON_CLIENT",
+ GRPC_OP_RECV_STATUS_ON_CLIENT, CONST_CS);
+ REGISTER_LONG_CONSTANT("Grpc\\OP_RECV_CLOSE_ON_SERVER",
+ GRPC_OP_RECV_CLOSE_ON_SERVER, CONST_CS);
+
grpc_init_call(TSRMLS_C);
grpc_init_channel(TSRMLS_C);
grpc_init_server(TSRMLS_C);
- grpc_init_completion_queue(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 a5cfd95..46fe745 100644
--- a/src/php/ext/grpc/server.c
+++ b/src/php/ext/grpc/server.c
@@ -37,30 +37,42 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "ext/spl/spl_exceptions.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
+#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
-#include "zend_exceptions.h"
+#include <zend_exceptions.h>
#include <stdbool.h>
-#include "grpc/grpc.h"
-#include "grpc/support/log.h"
-#include "grpc/grpc_security.h"
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <grpc/grpc_security.h>
#include "server.h"
-#include "completion_queue.h"
#include "channel.h"
#include "server_credentials.h"
+#include "timeval.h"
zend_class_entry *grpc_ce_server;
/* Frees and destroys an instance of wrapped_grpc_server */
void free_wrapped_grpc_server(void *object TSRMLS_DC) {
wrapped_grpc_server *server = (wrapped_grpc_server *)object;
+ grpc_event *event;
+ if (server->queue != NULL) {
+ grpc_completion_queue_shutdown(server->queue);
+ event = grpc_completion_queue_next(server->queue, gpr_inf_future);
+ while (event != NULL) {
+ if (event->type == GRPC_QUEUE_SHUTDOWN) {
+ break;
+ }
+ event = grpc_completion_queue_next(server->queue, gpr_inf_future);
+ }
+ grpc_completion_queue_destroy(server->queue);
+ }
if (server->wrapped != NULL) {
grpc_server_shutdown(server->wrapped);
grpc_server_destroy(server->wrapped);
@@ -95,26 +107,22 @@
PHP_METHOD(Server, __construct) {
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *queue_obj;
zval *args_array = NULL;
grpc_channel_args args;
- /* "O|a" == 1 Object, 1 optional array */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|a", &queue_obj,
- grpc_ce_completion_queue, &args_array) == FAILURE) {
+ /* "|a" == 1 optional array */
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &args_array) ==
+ FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
- "Server expects a CompletionQueue and an array",
+ "Server expects an array",
1 TSRMLS_CC);
return;
}
- add_property_zval(getThis(), "completion_queue", queue_obj);
- wrapped_grpc_completion_queue *queue =
- (wrapped_grpc_completion_queue *)zend_object_store_get_object(
- queue_obj TSRMLS_CC);
+ server->queue = grpc_completion_queue_create();
if (args_array == NULL) {
- server->wrapped = grpc_server_create(queue->wrapped, NULL);
+ server->wrapped = grpc_server_create(server->queue, NULL);
} else {
php_grpc_read_args_array(args_array, &args);
- server->wrapped = grpc_server_create(queue->wrapped, &args);
+ server->wrapped = grpc_server_create(server->queue, &args);
efree(args.args);
}
}
@@ -129,16 +137,40 @@
grpc_call_error error_code;
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
- long tag_new;
- /* "l" == 1 long */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_new) ==
- FAILURE) {
- zend_throw_exception(spl_ce_InvalidArgumentException,
- "request_call expects a long", 1 TSRMLS_CC);
- return;
+ grpc_call *call;
+ grpc_call_details details;
+ grpc_metadata_array metadata;
+ zval *result;
+ grpc_event *event;
+ MAKE_STD_ZVAL(result);
+ object_init(result);
+ grpc_call_details_init(&details);
+ grpc_metadata_array_init(&metadata);
+ error_code = grpc_server_request_call(server->wrapped, &call, &details,
+ &metadata, server->queue, NULL);
+ if (error_code != GRPC_CALL_OK) {
+ zend_throw_exception(spl_ce_LogicException, "request_call failed",
+ (long)error_code TSRMLS_CC);
+ goto cleanup;
}
- error_code = grpc_server_request_call_old(server->wrapped, (void *)tag_new);
- MAYBE_THROW_CALL_ERROR(request_call, error_code);
+ event = grpc_completion_queue_pluck(server->queue, NULL, gpr_inf_future);
+ if (event->data.op_complete != GRPC_OP_OK) {
+ zend_throw_exception(spl_ce_LogicException,
+ "Failed to request a call for some reason",
+ 1 TSRMLS_CC);
+ goto cleanup;
+ }
+ add_property_zval(result, "call", grpc_php_wrap_call(call, server->queue,
+ true));
+ add_property_string(result, "method", details.method, true);
+ add_property_string(result, "host", details.host, true);
+ add_property_zval(result, "absolute_deadline",
+ grpc_php_wrap_timeval(details.deadline));
+ add_property_zval(result, "metadata", grpc_parse_metadata_array(&metadata));
+cleanup:
+ grpc_call_details_destroy(&details);
+ grpc_metadata_array_destroy(&metadata);
+ RETURN_DESTROY_ZVAL(result);
}
/**
@@ -168,7 +200,7 @@
int addr_len;
zval *creds_obj;
/* "sO" == 1 string, 1 object */
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len,
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO", &addr, &addr_len,
&creds_obj, grpc_ce_server_credentials) ==
FAILURE) {
zend_throw_exception(
diff --git a/src/php/ext/grpc/server.h b/src/php/ext/grpc/server.h
index b55689c..a2ee2ff 100755
--- a/src/php/ext/grpc/server.h
+++ b/src/php/ext/grpc/server.h
@@ -38,12 +38,12 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
#include "php_grpc.h"
-#include "grpc/grpc.h"
+#include <grpc/grpc.h>
/* Class entry for the Server PHP class */
extern zend_class_entry *grpc_ce_server;
@@ -53,6 +53,7 @@
zend_object std;
grpc_server *wrapped;
+ grpc_completion_queue *queue;
} wrapped_grpc_server;
/* Initializes the Server class */
diff --git a/src/php/ext/grpc/server_credentials.c b/src/php/ext/grpc/server_credentials.c
index df64e65..c4c1fab 100644
--- a/src/php/ext/grpc/server_credentials.c
+++ b/src/php/ext/grpc/server_credentials.c
@@ -37,17 +37,17 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "ext/spl/spl_exceptions.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
+#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
-#include "zend_exceptions.h"
-#include "zend_hash.h"
+#include <zend_exceptions.h>
+#include <zend_hash.h>
-#include "grpc/grpc.h"
-#include "grpc/grpc_security.h"
+#include <grpc/grpc.h>
+#include <grpc/grpc_security.h>
zend_class_entry *grpc_ce_server_credentials;
diff --git a/src/php/ext/grpc/server_credentials.h b/src/php/ext/grpc/server_credentials.h
index 8ed3697..7101d65 100755
--- a/src/php/ext/grpc/server_credentials.h
+++ b/src/php/ext/grpc/server_credentials.h
@@ -38,13 +38,13 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
#include "php_grpc.h"
-#include "grpc/grpc.h"
-#include "grpc/grpc_security.h"
+#include <grpc/grpc.h>
+#include <grpc/grpc_security.h>
/* Class entry for the Server_Credentials PHP class */
extern zend_class_entry *grpc_ce_server_credentials;
diff --git a/src/php/ext/grpc/timeval.c b/src/php/ext/grpc/timeval.c
index f90f006..1c9542d 100644
--- a/src/php/ext/grpc/timeval.c
+++ b/src/php/ext/grpc/timeval.c
@@ -37,18 +37,18 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
-#include "ext/spl/spl_exceptions.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
+#include <ext/spl/spl_exceptions.h>
#include "php_grpc.h"
-#include "zend_exceptions.h"
+#include <zend_exceptions.h>
#include <stdbool.h>
-#include "grpc/grpc.h"
-#include "grpc/support/time.h"
+#include <grpc/grpc.h>
+#include <grpc/support/time.h>
zend_class_entry *grpc_ce_timeval;
diff --git a/src/php/ext/grpc/timeval.h b/src/php/ext/grpc/timeval.h
index e3183f6..07cef03 100755
--- a/src/php/ext/grpc/timeval.h
+++ b/src/php/ext/grpc/timeval.h
@@ -38,13 +38,13 @@
#include "config.h"
#endif
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/info.h"
+#include <php.h>
+#include <php_ini.h>
+#include <ext/standard/info.h>
#include "php_grpc.h"
-#include "grpc/grpc.h"
-#include "grpc/support/time.h"
+#include <grpc/grpc.h>
+#include <grpc/support/time.h>
/* Class entry for the Timeval PHP Class */
extern zend_class_entry *grpc_ce_timeval;
diff --git a/src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php b/src/php/lib/Grpc/AbstractCall.php
old mode 100755
new mode 100644
similarity index 63%
rename from src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php
rename to src/php/lib/Grpc/AbstractCall.php
index 0459f21..413d596
--- a/src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php
+++ b/src/php/lib/Grpc/AbstractCall.php
@@ -32,44 +32,47 @@
*
*/
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 {
+abstract class AbstractCall {
+
+ protected $call;
+ protected $deserialize;
+ protected $metadata;
/**
- * Reads the next value from the server.
- * @return The next value from the server, or null if there is none
+ * Create a new Call wrapper object.
+ * @param Channel $channel The channel to communicate on
+ * @param string $method The method to call on the remote server
*/
- public function read() {
- return $this->_read();
+ public function __construct(Channel $channel, $method, $deserialize) {
+ $this->call = new Call($channel, $method, Timeval::inf_future());
+ $this->deserialize = $deserialize;
+ $this->metadata = null;
}
/**
- * Writes a single message to the server. This cannot be called after
- * writesDone is called.
- * @param $value The message to send
+ * @return The metadata sent by the server.
*/
- public function write($value) {
- $this->_write($value);
+ public function getMetadata() {
+ return $this->metadata;
}
/**
- * Indicate that no more writes will be sent
+ * Cancels the call
*/
- public function writesDone() {
- $this->_writesDone();
+ public function cancel() {
+ $this->call->cancel();
}
/**
- * Wait for the server to send the status, and return it.
- * @return object The status object, with integer $code and string $details
- * members
+ * Deserialize a response value to an object.
+ * @param string $value The binary value to deserialize
+ * @return The deserialized value
*/
- public function getStatus() {
- return $this->_getStatus();
+ protected function deserializeResponse($value) {
+ if ($value === null) {
+ return null;
+ }
+ return call_user_func($this->deserialize, $value);
}
-}
+}
\ No newline at end of file
diff --git a/src/php/lib/Grpc/AbstractSurfaceActiveCall.php b/src/php/lib/Grpc/AbstractSurfaceActiveCall.php
deleted file mode 100755
index 9d0af09..0000000
--- a/src/php/lib/Grpc/AbstractSurfaceActiveCall.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-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();
- }
-}
diff --git a/src/php/lib/Grpc/ActiveCall.php b/src/php/lib/Grpc/ActiveCall.php
deleted file mode 100755
index f0d0d55..0000000
--- a/src/php/lib/Grpc/ActiveCall.php
+++ /dev/null
@@ -1,123 +0,0 @@
-<?php
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-namespace Grpc;
-require_once realpath(dirname(__FILE__) . '/../autoload.php');
-
-/**
- * Represents an active call that allows sending and recieving binary data
- */
-class ActiveCall {
- private $completion_queue;
- private $call;
- private $flags;
- private $metadata;
-
- /**
- * Create a new active call.
- * @param Channel $channel The channel to communicate on
- * @param string $method The method to call on the remote server
- * @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,
- $metadata = array(),
- $flags = 0) {
- $this->completion_queue = new CompletionQueue();
- $this->call = new Call($channel, $method, Timeval::inf_future());
- $this->call->add_metadata($metadata, 0);
- $this->flags = $flags;
-
- // Invoke the call.
- $this->call->invoke($this->completion_queue,
- CLIENT_METADATA_READ,
- FINISHED, 0);
- $metadata_event = $this->completion_queue->pluck(CLIENT_METADATA_READ,
- Timeval::inf_future());
- $this->metadata = $metadata_event->data;
- }
-
- /**
- * @return The metadata sent by the server.
- */
- public function getMetadata() {
- return $this->metadata;
- }
-
- /**
- * Cancels the call
- */
- public function cancel() {
- $this->call->cancel();
- }
-
- /**
- * Read a single message from the server.
- * @return The next message from the server, or null if there is none.
- */
- public function read() {
- $this->call->start_read(READ);
- $read_event = $this->completion_queue->pluck(READ, Timeval::inf_future());
- return $read_event->data;
- }
-
- /**
- * Write a single message to the server. This cannot be called after
- * writesDone is called.
- * @param ByteBuffer $data The data to write
- */
- public function write($data) {
- $this->call->start_write($data, WRITE_ACCEPTED, $this->flags);
- $this->completion_queue->pluck(WRITE_ACCEPTED, Timeval::inf_future());
- }
-
- /**
- * Indicate that no more writes will be sent.
- */
- public function writesDone() {
- $this->call->writes_done(FINISH_ACCEPTED);
- $this->completion_queue->pluck(FINISH_ACCEPTED, Timeval::inf_future());
- }
-
- /**
- * Wait for the server to send the status, and return it.
- * @return object The status object, with integer $code, string $details,
- * and array $metadata members
- */
- public function getStatus() {
- $status_event = $this->completion_queue->pluck(FINISHED,
- Timeval::inf_future());
- return $status_event->data;
- }
-}
diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php
index fde055a..fc83dac 100755
--- a/src/php/lib/Grpc/BaseStub.php
+++ b/src/php/lib/Grpc/BaseStub.php
@@ -32,7 +32,6 @@
*
*/
namespace Grpc;
-require_once realpath(dirname(__FILE__) . '/../autoload.php');
/**
* Base class for generated client stubs. Stub methods are expected to call
@@ -69,11 +68,9 @@
$argument,
callable $deserialize,
$metadata = array()) {
- return new SimpleSurfaceActiveCall($this->channel,
- $method,
- $deserialize,
- $argument,
- $metadata);
+ $call = new UnaryCall($this->channel, $method, $deserialize);
+ $call->start($argument, $metadata);
+ return $call;
}
/**
@@ -91,11 +88,9 @@
$arguments,
callable $deserialize,
$metadata = array()) {
- return new ClientStreamingSurfaceActiveCall($this->channel,
- $method,
- $deserialize,
- $arguments,
- $metadata);
+ $call = new ClientStreamingCall($this->channel, $method, $deserialize);
+ $call->start($arguments, $metadata);
+ return $call;
}
/**
@@ -112,11 +107,9 @@
$argument,
callable $deserialize,
$metadata = array()) {
- return new ServerStreamingSurfaceActiveCall($this->channel,
- $method,
- $deserialize,
- $argument,
- $metadata);
+ $call = new ServerStreamingCall($this->channel, $method, $deserialize);
+ $call->start($argument, $metadata);
+ return $call;
}
/**
@@ -130,9 +123,8 @@
public function _bidiRequest($method,
callable $deserialize,
$metadata = array()) {
- return new BidiStreamingSurfaceActiveCall($this->channel,
- $method,
- $deserialize,
- $metadata);
+ $call = new BidiStreamingCall($this->channel, $method, $deserialize);
+ $call->start($metadata);
+ return $call;
}
}
diff --git a/src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php b/src/php/lib/Grpc/BidiStreamingCall.php
old mode 100755
new mode 100644
similarity index 62%
copy from src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php
copy to src/php/lib/Grpc/BidiStreamingCall.php
index 0459f21..2afceaf
--- a/src/php/lib/Grpc/BidiStreamingSurfaceActiveCall.php
+++ b/src/php/lib/Grpc/BidiStreamingCall.php
@@ -32,44 +32,61 @@
*
*/
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 {
+class BidiStreamingCall extends AbstractCall {
+ /**
+ * Start the call
+ * @param array $metadata Metadata to send with the call, if applicable
+ */
+ public function start($metadata) {
+ $this->call->start_batch([OP_SEND_INITIAL_METADATA => $metadata]);
+ }
/**
* 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();
+ $batch = [OP_RECV_MESSAGE => true];
+ if ($this->metadata === null) {
+ $batch[OP_RECV_INITIAL_METADATA] = true;
+ }
+ $read_event = $this->call->start_batch($batch);
+ if ($this->metadata === null) {
+ $this->metadata = $read_event->metadata;
+ }
+ return $this->deserializeResponse($read_event->message);
}
/**
- * Writes a single message to the server. This cannot be called after
+ * Write a single message to the server. This cannot be called after
* writesDone is called.
- * @param $value The message to send
+ * @param ByteBuffer $data The data to write
*/
- public function write($value) {
- $this->_write($value);
+ public function write($data) {
+ $this->call->start_batch([OP_SEND_MESSAGE => $data->serialize()]);
}
/**
- * Indicate that no more writes will be sent
+ * Indicate that no more writes will be sent.
*/
public function writesDone() {
- $this->_writesDone();
+ $this->call->start_batch([OP_SEND_CLOSE_FROM_CLIENT => true]);
}
/**
* Wait for the server to send the status, and return it.
- * @return object The status object, with integer $code and string $details
- * members
+ * @return object The status object, with integer $code, string $details,
+ * and array $metadata members
*/
public function getStatus() {
- return $this->_getStatus();
+ $status_event = $this->call->start_batch([
+ OP_RECV_STATUS_ON_CLIENT => true
+ ]);
+ return $status_event->status;
}
-}
+}
\ No newline at end of file
diff --git a/src/php/lib/Grpc/ClientStreamingSurfaceActiveCall.php b/src/php/lib/Grpc/ClientStreamingCall.php
old mode 100755
new mode 100644
similarity index 69%
rename from src/php/lib/Grpc/ClientStreamingSurfaceActiveCall.php
rename to src/php/lib/Grpc/ClientStreamingCall.php
index d33f09f..ec585da
--- a/src/php/lib/Grpc/ClientStreamingSurfaceActiveCall.php
+++ b/src/php/lib/Grpc/ClientStreamingCall.php
@@ -32,31 +32,23 @@
*
*/
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 {
+class ClientStreamingCall extends AbstractCall {
/**
- * 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
+ * Start the call.
* @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);
+ public function start($arg_iter, $metadata = array()) {
+ $event = $this->call->start_batch([OP_SEND_INITIAL_METADATA => $metadata]);
foreach($arg_iter as $arg) {
- $this->_write($arg);
+ $this->call->start_batch([OP_SEND_MESSAGE => $arg->serialize()]);
}
- $this->_writesDone();
+ $this->call->start_batch([OP_SEND_CLOSE_FROM_CLIENT => true]);
}
/**
@@ -64,8 +56,11 @@
* @return [response data, status]
*/
public function wait() {
- $response = $this->_read();
- $status = $this->_getStatus();
- return array($response, $status);
+ $event = $this->call->start_batch([
+ OP_RECV_INITIAL_METADATA => true,
+ OP_RECV_MESSAGE => true,
+ OP_RECV_STATUS_ON_CLIENT => true]);
+ $this->metadata = $event->metadata;
+ return array($this->deserializeResponse($event->message), $event->status);
}
-}
+}
\ No newline at end of file
diff --git a/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php b/src/php/lib/Grpc/ServerStreamingCall.php
old mode 100755
new mode 100644
similarity index 66%
rename from src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php
rename to src/php/lib/Grpc/ServerStreamingCall.php
index fd08e86..574c1bb
--- a/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php
+++ b/src/php/lib/Grpc/ServerStreamingCall.php
@@ -33,42 +33,45 @@
*/
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 {
+class ServerStreamingCall extends AbstractCall {
/**
- * 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
+ * Start the call
* @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();
+ public function start($arg, $metadata = array()) {
+ $event = $this->call->start_batch([
+ OP_SEND_INITIAL_METADATA => $metadata,
+ OP_RECV_INITIAL_METADATA => true,
+ OP_SEND_MESSAGE => $arg->serialize(),
+ OP_SEND_CLOSE_FROM_CLIENT => true]);
+ $this->metadata = $event->metadata;
}
/**
* @return An iterator of response values
*/
public function responses() {
- while(($response = $this->_read()) !== null) {
- yield $response;
+ $response = $this->call->start_batch([OP_RECV_MESSAGE => true])->message;
+ while($response !== null) {
+ yield $this->deserializeResponse($response);
+ $response = $this->call->start_batch([OP_RECV_MESSAGE => true])->message;
}
}
+ /**
+ * Wait for the server to send the status, and return it.
+ * @return object The status object, with integer $code, string $details,
+ * and array $metadata members
+ */
public function getStatus() {
- return $this->_getStatus();
+ $status_event = $this->call->start_batch([
+ OP_RECV_STATUS_ON_CLIENT => true
+ ]);
+ return $status_event->status;
}
-}
+}
\ No newline at end of file
diff --git a/src/php/lib/Grpc/SimpleSurfaceActiveCall.php b/src/php/lib/Grpc/UnaryCall.php
old mode 100755
new mode 100644
similarity index 68%
rename from src/php/lib/Grpc/SimpleSurfaceActiveCall.php
rename to src/php/lib/Grpc/UnaryCall.php
index ba82f57..814d477
--- a/src/php/lib/Grpc/SimpleSurfaceActiveCall.php
+++ b/src/php/lib/Grpc/UnaryCall.php
@@ -33,30 +33,23 @@
*/
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 {
+class UnaryCall extends AbstractCall {
/**
- * 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
+ * Start the call
* @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();
+ public function start($arg, $metadata = array()) {
+ $event = $this->call->start_batch([
+ OP_SEND_INITIAL_METADATA => $metadata,
+ OP_RECV_INITIAL_METADATA => true,
+ OP_SEND_MESSAGE => $arg->serialize(),
+ OP_SEND_CLOSE_FROM_CLIENT => true]);
+ $this->metadata = $event->metadata;
}
/**
@@ -64,8 +57,9 @@
* @return [response data, status]
*/
public function wait() {
- $response = $this->_read();
- $status = $this->_getStatus();
- return array($response, $status);
+ $event = $this->call->start_batch([
+ OP_RECV_MESSAGE => true,
+ OP_RECV_STATUS_ON_CLIENT => true]);
+ return array($this->deserializeResponse($event->message), $event->status);
}
-}
+}
\ No newline at end of file
diff --git a/src/php/lib/autoload.php b/src/php/lib/autoload.php
deleted file mode 100755
index 42eb33d..0000000
--- a/src/php/lib/autoload.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-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');
diff --git a/src/php/tests/generated_code/GeneratedCodeTest.php b/src/php/tests/generated_code/GeneratedCodeTest.php
index cb2c0e6..afd7f21 100755
--- a/src/php/tests/generated_code/GeneratedCodeTest.php
+++ b/src/php/tests/generated_code/GeneratedCodeTest.php
@@ -31,7 +31,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-require_once realpath(dirname(__FILE__) . '/../../lib/autoload.php');
+require_once realpath(dirname(__FILE__) . '/../../vendor/autoload.php');
require 'DrSlump/Protobuf.php';
\DrSlump\Protobuf::autoload();
require 'math.php';
diff --git a/src/php/tests/generated_code/math.php b/src/php/tests/generated_code/math.php
deleted file mode 100755
index e97a5cf..0000000
--- a/src/php/tests/generated_code/math.php
+++ /dev/null
@@ -1,479 +0,0 @@
-<?php
-// DO NOT EDIT! Generated by Protobuf-PHP protoc plugin 1.0
-// Source: math.proto
-// Date: 2014-11-14 00:00:41
-
-namespace math {
-
- class DivArgs extends \DrSlump\Protobuf\Message {
-
- /** @var int */
- public $dividend = null;
-
- /** @var int */
- public $divisor = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'math.DivArgs');
-
- // REQUIRED INT64 dividend = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "dividend";
- $f->type = \DrSlump\Protobuf::TYPE_INT64;
- $f->rule = \DrSlump\Protobuf::RULE_REQUIRED;
- $descriptor->addField($f);
-
- // REQUIRED INT64 divisor = 2
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 2;
- $f->name = "divisor";
- $f->type = \DrSlump\Protobuf::TYPE_INT64;
- $f->rule = \DrSlump\Protobuf::RULE_REQUIRED;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <dividend> has a value
- *
- * @return boolean
- */
- public function hasDividend(){
- return $this->_has(1);
- }
-
- /**
- * Clear <dividend> value
- *
- * @return \math\DivArgs
- */
- public function clearDividend(){
- return $this->_clear(1);
- }
-
- /**
- * Get <dividend> value
- *
- * @return int
- */
- public function getDividend(){
- return $this->_get(1);
- }
-
- /**
- * Set <dividend> value
- *
- * @param int $value
- * @return \math\DivArgs
- */
- public function setDividend( $value){
- return $this->_set(1, $value);
- }
-
- /**
- * Check if <divisor> has a value
- *
- * @return boolean
- */
- public function hasDivisor(){
- return $this->_has(2);
- }
-
- /**
- * Clear <divisor> value
- *
- * @return \math\DivArgs
- */
- public function clearDivisor(){
- return $this->_clear(2);
- }
-
- /**
- * Get <divisor> value
- *
- * @return int
- */
- public function getDivisor(){
- return $this->_get(2);
- }
-
- /**
- * Set <divisor> value
- *
- * @param int $value
- * @return \math\DivArgs
- */
- public function setDivisor( $value){
- return $this->_set(2, $value);
- }
- }
-}
-
-namespace math {
-
- class DivReply extends \DrSlump\Protobuf\Message {
-
- /** @var int */
- public $quotient = null;
-
- /** @var int */
- public $remainder = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'math.DivReply');
-
- // REQUIRED INT64 quotient = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "quotient";
- $f->type = \DrSlump\Protobuf::TYPE_INT64;
- $f->rule = \DrSlump\Protobuf::RULE_REQUIRED;
- $descriptor->addField($f);
-
- // REQUIRED INT64 remainder = 2
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 2;
- $f->name = "remainder";
- $f->type = \DrSlump\Protobuf::TYPE_INT64;
- $f->rule = \DrSlump\Protobuf::RULE_REQUIRED;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <quotient> has a value
- *
- * @return boolean
- */
- public function hasQuotient(){
- return $this->_has(1);
- }
-
- /**
- * Clear <quotient> value
- *
- * @return \math\DivReply
- */
- public function clearQuotient(){
- return $this->_clear(1);
- }
-
- /**
- * Get <quotient> value
- *
- * @return int
- */
- public function getQuotient(){
- return $this->_get(1);
- }
-
- /**
- * Set <quotient> value
- *
- * @param int $value
- * @return \math\DivReply
- */
- public function setQuotient( $value){
- return $this->_set(1, $value);
- }
-
- /**
- * Check if <remainder> has a value
- *
- * @return boolean
- */
- public function hasRemainder(){
- return $this->_has(2);
- }
-
- /**
- * Clear <remainder> value
- *
- * @return \math\DivReply
- */
- public function clearRemainder(){
- return $this->_clear(2);
- }
-
- /**
- * Get <remainder> value
- *
- * @return int
- */
- public function getRemainder(){
- return $this->_get(2);
- }
-
- /**
- * Set <remainder> value
- *
- * @param int $value
- * @return \math\DivReply
- */
- public function setRemainder( $value){
- return $this->_set(2, $value);
- }
- }
-}
-
-namespace math {
-
- class FibArgs extends \DrSlump\Protobuf\Message {
-
- /** @var int */
- public $limit = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'math.FibArgs');
-
- // OPTIONAL INT64 limit = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "limit";
- $f->type = \DrSlump\Protobuf::TYPE_INT64;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <limit> has a value
- *
- * @return boolean
- */
- public function hasLimit(){
- return $this->_has(1);
- }
-
- /**
- * Clear <limit> value
- *
- * @return \math\FibArgs
- */
- public function clearLimit(){
- return $this->_clear(1);
- }
-
- /**
- * Get <limit> value
- *
- * @return int
- */
- public function getLimit(){
- return $this->_get(1);
- }
-
- /**
- * Set <limit> value
- *
- * @param int $value
- * @return \math\FibArgs
- */
- public function setLimit( $value){
- return $this->_set(1, $value);
- }
- }
-}
-
-namespace math {
-
- class Num extends \DrSlump\Protobuf\Message {
-
- /** @var int */
- public $num = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'math.Num');
-
- // REQUIRED INT64 num = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "num";
- $f->type = \DrSlump\Protobuf::TYPE_INT64;
- $f->rule = \DrSlump\Protobuf::RULE_REQUIRED;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <num> has a value
- *
- * @return boolean
- */
- public function hasNum(){
- return $this->_has(1);
- }
-
- /**
- * Clear <num> value
- *
- * @return \math\Num
- */
- public function clearNum(){
- return $this->_clear(1);
- }
-
- /**
- * Get <num> value
- *
- * @return int
- */
- public function getNum(){
- return $this->_get(1);
- }
-
- /**
- * Set <num> value
- *
- * @param int $value
- * @return \math\Num
- */
- public function setNum( $value){
- return $this->_set(1, $value);
- }
- }
-}
-
-namespace math {
-
- class FibReply extends \DrSlump\Protobuf\Message {
-
- /** @var int */
- public $count = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'math.FibReply');
-
- // REQUIRED INT64 count = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "count";
- $f->type = \DrSlump\Protobuf::TYPE_INT64;
- $f->rule = \DrSlump\Protobuf::RULE_REQUIRED;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <count> has a value
- *
- * @return boolean
- */
- public function hasCount(){
- return $this->_has(1);
- }
-
- /**
- * Clear <count> value
- *
- * @return \math\FibReply
- */
- public function clearCount(){
- return $this->_clear(1);
- }
-
- /**
- * Get <count> value
- *
- * @return int
- */
- public function getCount(){
- return $this->_get(1);
- }
-
- /**
- * Set <count> value
- *
- * @param int $value
- * @return \math\FibReply
- */
- public function setCount( $value){
- return $this->_set(1, $value);
- }
- }
-}
-
-namespace math {
-
- class MathClient extends \Grpc\BaseStub {
- /**
- * @param math\DivArgs $input
- * @return math\DivReply
- */
- public function Div(\math\DivArgs $argument, $metadata = array()) {
- return $this->_simpleRequest('/Math/Div', $argument, '\math\DivReply::deserialize', $metadata);
- }
- /**
- * @param math\DivArgs $input
- * @return math\DivReply
- */
- public function DivMany($metadata = array()) {
- return $this->_bidiRequest('/Math/DivMany', '\math\DivReply::deserialize', $metadata);
- }
- /**
- * @param math\FibArgs $input
- * @return math\Num
- */
- public function Fib($argument, $metadata = array()) {
- return $this->_serverStreamRequest('/Math/Fib', $argument, '\math\Num::deserialize', $metadata);
- }
- /**
- * @param math\Num $input
- * @return math\Num
- */
- public function Sum($arguments, $metadata = array()) {
- return $this->_clientStreamRequest('/Math/Sum', $arguments, '\math\Num::deserialize', $metadata);
- }
- }
-}
diff --git a/src/php/tests/generated_code/math.proto b/src/php/tests/generated_code/math.proto
new file mode 100644
index 0000000..e34ad5e
--- /dev/null
+++ b/src/php/tests/generated_code/math.proto
@@ -0,0 +1,80 @@
+
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto3";
+
+package math;
+
+message DivArgs {
+ optional int64 dividend = 1;
+ optional int64 divisor = 2;
+}
+
+message DivReply {
+ optional int64 quotient = 1;
+ optional int64 remainder = 2;
+}
+
+message FibArgs {
+ optional int64 limit = 1;
+}
+
+message Num {
+ optional int64 num = 1;
+}
+
+message FibReply {
+ optional int64 count = 1;
+}
+
+service Math {
+ // Div divides args.dividend by args.divisor and returns the quotient and
+ // remainder.
+ rpc Div (DivArgs) returns (DivReply) {
+ }
+
+ // DivMany accepts an arbitrary number of division args from the client stream
+ // and sends back the results in the reply stream. The stream continues until
+ // the client closes its end; the server does the same after sending all the
+ // replies. The stream ends immediately if either end aborts.
+ rpc DivMany (stream DivArgs) returns (stream DivReply) {
+ }
+
+ // Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib
+ // generates up to limit numbers; otherwise it continues until the call is
+ // canceled. Unlike Fib above, Fib has no final FibReply.
+ rpc Fib (FibArgs) returns (stream Num) {
+ }
+
+ // Sum sums a stream of numbers, returning the final result once the stream
+ // is closed.
+ rpc Sum (stream Num) returns (Num) {
+ }
+}
diff --git a/src/php/tests/interop/empty.php b/src/php/tests/interop/empty.php
deleted file mode 100755
index 22b1180..0000000
--- a/src/php/tests/interop/empty.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-// DO NOT EDIT! Generated by Protobuf-PHP protoc plugin 1.0
-// Source: test/cpp/interop/empty.proto
-// Date: 2015-01-30 23:30:46
-
-namespace grpc\testing {
-
- class EmptyMessage extends \DrSlump\Protobuf\Message {
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.EmptyMessage');
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
- }
-}
diff --git a/src/php/tests/interop/empty.proto b/src/php/tests/interop/empty.proto
new file mode 100644
index 0000000..4200d7b
--- /dev/null
+++ b/src/php/tests/interop/empty.proto
@@ -0,0 +1,43 @@
+
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package grpc.testing;
+
+// An empty message that you can re-use to avoid defining duplicated empty
+// messages in your project. A typical example is to use it as argument or the
+// return value of a service API. For instance:
+//
+// service Foo {
+// rpc Bar (grpc.testing.EmptyMessage) returns (grpc.testing.EmptyMessage) { };
+// };
+//
+message EmptyMessage {}
diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php
index 82ca438..6f81bfa 100755
--- a/src/php/tests/interop/interop_client.php
+++ b/src/php/tests/interop/interop_client.php
@@ -31,7 +31,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-require_once realpath(dirname(__FILE__) . '/../../lib/autoload.php');
+require_once realpath(dirname(__FILE__) . '/../../vendor/autoload.php');
require 'DrSlump/Protobuf.php';
\DrSlump\Protobuf::autoload();
require 'empty.php';
@@ -132,8 +132,6 @@
}
$call = $stub->StreamingOutputCall($request);
- hardAssert($call->getStatus()->code === Grpc\STATUS_OK,
- 'Call did not complete successfully');
$i = 0;
foreach($call->responses() as $value) {
hardAssert($i < 4, 'Too many responses');
@@ -142,7 +140,10 @@
'Payload ' . $i . ' had the wrong type');
hardAssert(strlen($payload->getBody()) === $sizes[$i],
'Response ' . $i . ' had the wrong length');
+ $i += 1;
}
+ hardAssert($call->getStatus()->code === Grpc\STATUS_OK,
+ 'Call did not complete successfully');
}
/**
@@ -240,4 +241,7 @@
break;
case 'cancel_after_first_response':
cancelAfterFirstResponse($stub);
+ break;
+ default:
+ exit(1);
}
diff --git a/src/php/tests/interop/messages.php b/src/php/tests/interop/messages.php
deleted file mode 100755
index a626a17..0000000
--- a/src/php/tests/interop/messages.php
+++ /dev/null
@@ -1,1074 +0,0 @@
-<?php
-// DO NOT EDIT! Generated by Protobuf-PHP protoc plugin 1.0
-// Source: test/cpp/interop/messages.proto
-// Date: 2015-01-30 23:30:46
-
-namespace grpc\testing {
-
- class PayloadType extends \DrSlump\Protobuf\Enum {
- const COMPRESSABLE = 0;
- const UNCOMPRESSABLE = 1;
- const RANDOM = 2;
- }
-}
-namespace grpc\testing {
-
- class Payload extends \DrSlump\Protobuf\Message {
-
- /** @var int - \grpc\testing\PayloadType */
- public $type = null;
-
- /** @var string */
- public $body = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.Payload');
-
- // OPTIONAL ENUM type = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "type";
- $f->type = \DrSlump\Protobuf::TYPE_ENUM;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $f->reference = '\grpc\testing\PayloadType';
- $descriptor->addField($f);
-
- // OPTIONAL BYTES body = 2
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 2;
- $f->name = "body";
- $f->type = \DrSlump\Protobuf::TYPE_BYTES;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <type> has a value
- *
- * @return boolean
- */
- public function hasType(){
- return $this->_has(1);
- }
-
- /**
- * Clear <type> value
- *
- * @return \grpc\testing\Payload
- */
- public function clearType(){
- return $this->_clear(1);
- }
-
- /**
- * Get <type> value
- *
- * @return int - \grpc\testing\PayloadType
- */
- public function getType(){
- return $this->_get(1);
- }
-
- /**
- * Set <type> value
- *
- * @param int - \grpc\testing\PayloadType $value
- * @return \grpc\testing\Payload
- */
- public function setType( $value){
- return $this->_set(1, $value);
- }
-
- /**
- * Check if <body> has a value
- *
- * @return boolean
- */
- public function hasBody(){
- return $this->_has(2);
- }
-
- /**
- * Clear <body> value
- *
- * @return \grpc\testing\Payload
- */
- public function clearBody(){
- return $this->_clear(2);
- }
-
- /**
- * Get <body> value
- *
- * @return string
- */
- public function getBody(){
- return $this->_get(2);
- }
-
- /**
- * Set <body> value
- *
- * @param string $value
- * @return \grpc\testing\Payload
- */
- public function setBody( $value){
- return $this->_set(2, $value);
- }
- }
-}
-
-namespace grpc\testing {
-
- class SimpleRequest extends \DrSlump\Protobuf\Message {
-
- /** @var int - \grpc\testing\PayloadType */
- public $response_type = null;
-
- /** @var int */
- public $response_size = null;
-
- /** @var \grpc\testing\Payload */
- public $payload = null;
-
- /** @var boolean */
- public $fill_username = null;
-
- /** @var boolean */
- public $fill_oauth_scope = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.SimpleRequest');
-
- // OPTIONAL ENUM response_type = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "response_type";
- $f->type = \DrSlump\Protobuf::TYPE_ENUM;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $f->reference = '\grpc\testing\PayloadType';
- $descriptor->addField($f);
-
- // OPTIONAL INT32 response_size = 2
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 2;
- $f->name = "response_size";
- $f->type = \DrSlump\Protobuf::TYPE_INT32;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- // OPTIONAL MESSAGE payload = 3
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 3;
- $f->name = "payload";
- $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $f->reference = '\grpc\testing\Payload';
- $descriptor->addField($f);
-
- // OPTIONAL BOOL fill_username = 4
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 4;
- $f->name = "fill_username";
- $f->type = \DrSlump\Protobuf::TYPE_BOOL;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- // OPTIONAL BOOL fill_oauth_scope = 5
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 5;
- $f->name = "fill_oauth_scope";
- $f->type = \DrSlump\Protobuf::TYPE_BOOL;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <response_type> has a value
- *
- * @return boolean
- */
- public function hasResponseType(){
- return $this->_has(1);
- }
-
- /**
- * Clear <response_type> value
- *
- * @return \grpc\testing\SimpleRequest
- */
- public function clearResponseType(){
- return $this->_clear(1);
- }
-
- /**
- * Get <response_type> value
- *
- * @return int - \grpc\testing\PayloadType
- */
- public function getResponseType(){
- return $this->_get(1);
- }
-
- /**
- * Set <response_type> value
- *
- * @param int - \grpc\testing\PayloadType $value
- * @return \grpc\testing\SimpleRequest
- */
- public function setResponseType( $value){
- return $this->_set(1, $value);
- }
-
- /**
- * Check if <response_size> has a value
- *
- * @return boolean
- */
- public function hasResponseSize(){
- return $this->_has(2);
- }
-
- /**
- * Clear <response_size> value
- *
- * @return \grpc\testing\SimpleRequest
- */
- public function clearResponseSize(){
- return $this->_clear(2);
- }
-
- /**
- * Get <response_size> value
- *
- * @return int
- */
- public function getResponseSize(){
- return $this->_get(2);
- }
-
- /**
- * Set <response_size> value
- *
- * @param int $value
- * @return \grpc\testing\SimpleRequest
- */
- public function setResponseSize( $value){
- return $this->_set(2, $value);
- }
-
- /**
- * Check if <payload> has a value
- *
- * @return boolean
- */
- public function hasPayload(){
- return $this->_has(3);
- }
-
- /**
- * Clear <payload> value
- *
- * @return \grpc\testing\SimpleRequest
- */
- public function clearPayload(){
- return $this->_clear(3);
- }
-
- /**
- * Get <payload> value
- *
- * @return \grpc\testing\Payload
- */
- public function getPayload(){
- return $this->_get(3);
- }
-
- /**
- * Set <payload> value
- *
- * @param \grpc\testing\Payload $value
- * @return \grpc\testing\SimpleRequest
- */
- public function setPayload(\grpc\testing\Payload $value){
- return $this->_set(3, $value);
- }
-
- /**
- * Check if <fill_username> has a value
- *
- * @return boolean
- */
- public function hasFillUsername(){
- return $this->_has(4);
- }
-
- /**
- * Clear <fill_username> value
- *
- * @return \grpc\testing\SimpleRequest
- */
- public function clearFillUsername(){
- return $this->_clear(4);
- }
-
- /**
- * Get <fill_username> value
- *
- * @return boolean
- */
- public function getFillUsername(){
- return $this->_get(4);
- }
-
- /**
- * Set <fill_username> value
- *
- * @param boolean $value
- * @return \grpc\testing\SimpleRequest
- */
- public function setFillUsername( $value){
- return $this->_set(4, $value);
- }
-
- /**
- * Check if <fill_oauth_scope> has a value
- *
- * @return boolean
- */
- public function hasFillOauthScope(){
- return $this->_has(5);
- }
-
- /**
- * Clear <fill_oauth_scope> value
- *
- * @return \grpc\testing\SimpleRequest
- */
- public function clearFillOauthScope(){
- return $this->_clear(5);
- }
-
- /**
- * Get <fill_oauth_scope> value
- *
- * @return boolean
- */
- public function getFillOauthScope(){
- return $this->_get(5);
- }
-
- /**
- * Set <fill_oauth_scope> value
- *
- * @param boolean $value
- * @return \grpc\testing\SimpleRequest
- */
- public function setFillOauthScope( $value){
- return $this->_set(5, $value);
- }
- }
-}
-
-namespace grpc\testing {
-
- class SimpleResponse extends \DrSlump\Protobuf\Message {
-
- /** @var \grpc\testing\Payload */
- public $payload = null;
-
- /** @var string */
- public $username = null;
-
- /** @var string */
- public $oauth_scope = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.SimpleResponse');
-
- // OPTIONAL MESSAGE payload = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "payload";
- $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $f->reference = '\grpc\testing\Payload';
- $descriptor->addField($f);
-
- // OPTIONAL STRING username = 2
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 2;
- $f->name = "username";
- $f->type = \DrSlump\Protobuf::TYPE_STRING;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- // OPTIONAL STRING oauth_scope = 3
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 3;
- $f->name = "oauth_scope";
- $f->type = \DrSlump\Protobuf::TYPE_STRING;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <payload> has a value
- *
- * @return boolean
- */
- public function hasPayload(){
- return $this->_has(1);
- }
-
- /**
- * Clear <payload> value
- *
- * @return \grpc\testing\SimpleResponse
- */
- public function clearPayload(){
- return $this->_clear(1);
- }
-
- /**
- * Get <payload> value
- *
- * @return \grpc\testing\Payload
- */
- public function getPayload(){
- return $this->_get(1);
- }
-
- /**
- * Set <payload> value
- *
- * @param \grpc\testing\Payload $value
- * @return \grpc\testing\SimpleResponse
- */
- public function setPayload(\grpc\testing\Payload $value){
- return $this->_set(1, $value);
- }
-
- /**
- * Check if <username> has a value
- *
- * @return boolean
- */
- public function hasUsername(){
- return $this->_has(2);
- }
-
- /**
- * Clear <username> value
- *
- * @return \grpc\testing\SimpleResponse
- */
- public function clearUsername(){
- return $this->_clear(2);
- }
-
- /**
- * Get <username> value
- *
- * @return string
- */
- public function getUsername(){
- return $this->_get(2);
- }
-
- /**
- * Set <username> value
- *
- * @param string $value
- * @return \grpc\testing\SimpleResponse
- */
- public function setUsername( $value){
- return $this->_set(2, $value);
- }
-
- /**
- * Check if <oauth_scope> has a value
- *
- * @return boolean
- */
- public function hasOauthScope(){
- return $this->_has(3);
- }
-
- /**
- * Clear <oauth_scope> value
- *
- * @return \grpc\testing\SimpleResponse
- */
- public function clearOauthScope(){
- return $this->_clear(3);
- }
-
- /**
- * Get <oauth_scope> value
- *
- * @return string
- */
- public function getOauthScope(){
- return $this->_get(3);
- }
-
- /**
- * Set <oauth_scope> value
- *
- * @param string $value
- * @return \grpc\testing\SimpleResponse
- */
- public function setOauthScope( $value){
- return $this->_set(3, $value);
- }
- }
-}
-
-namespace grpc\testing {
-
- class StreamingInputCallRequest extends \DrSlump\Protobuf\Message {
-
- /** @var \grpc\testing\Payload */
- public $payload = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.StreamingInputCallRequest');
-
- // OPTIONAL MESSAGE payload = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "payload";
- $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $f->reference = '\grpc\testing\Payload';
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <payload> has a value
- *
- * @return boolean
- */
- public function hasPayload(){
- return $this->_has(1);
- }
-
- /**
- * Clear <payload> value
- *
- * @return \grpc\testing\StreamingInputCallRequest
- */
- public function clearPayload(){
- return $this->_clear(1);
- }
-
- /**
- * Get <payload> value
- *
- * @return \grpc\testing\Payload
- */
- public function getPayload(){
- return $this->_get(1);
- }
-
- /**
- * Set <payload> value
- *
- * @param \grpc\testing\Payload $value
- * @return \grpc\testing\StreamingInputCallRequest
- */
- public function setPayload(\grpc\testing\Payload $value){
- return $this->_set(1, $value);
- }
- }
-}
-
-namespace grpc\testing {
-
- class StreamingInputCallResponse extends \DrSlump\Protobuf\Message {
-
- /** @var int */
- public $aggregated_payload_size = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.StreamingInputCallResponse');
-
- // OPTIONAL INT32 aggregated_payload_size = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "aggregated_payload_size";
- $f->type = \DrSlump\Protobuf::TYPE_INT32;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <aggregated_payload_size> has a value
- *
- * @return boolean
- */
- public function hasAggregatedPayloadSize(){
- return $this->_has(1);
- }
-
- /**
- * Clear <aggregated_payload_size> value
- *
- * @return \grpc\testing\StreamingInputCallResponse
- */
- public function clearAggregatedPayloadSize(){
- return $this->_clear(1);
- }
-
- /**
- * Get <aggregated_payload_size> value
- *
- * @return int
- */
- public function getAggregatedPayloadSize(){
- return $this->_get(1);
- }
-
- /**
- * Set <aggregated_payload_size> value
- *
- * @param int $value
- * @return \grpc\testing\StreamingInputCallResponse
- */
- public function setAggregatedPayloadSize( $value){
- return $this->_set(1, $value);
- }
- }
-}
-
-namespace grpc\testing {
-
- class ResponseParameters extends \DrSlump\Protobuf\Message {
-
- /** @var int */
- public $size = null;
-
- /** @var int */
- public $interval_us = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.ResponseParameters');
-
- // OPTIONAL INT32 size = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "size";
- $f->type = \DrSlump\Protobuf::TYPE_INT32;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- // OPTIONAL INT32 interval_us = 2
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 2;
- $f->name = "interval_us";
- $f->type = \DrSlump\Protobuf::TYPE_INT32;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <size> has a value
- *
- * @return boolean
- */
- public function hasSize(){
- return $this->_has(1);
- }
-
- /**
- * Clear <size> value
- *
- * @return \grpc\testing\ResponseParameters
- */
- public function clearSize(){
- return $this->_clear(1);
- }
-
- /**
- * Get <size> value
- *
- * @return int
- */
- public function getSize(){
- return $this->_get(1);
- }
-
- /**
- * Set <size> value
- *
- * @param int $value
- * @return \grpc\testing\ResponseParameters
- */
- public function setSize( $value){
- return $this->_set(1, $value);
- }
-
- /**
- * Check if <interval_us> has a value
- *
- * @return boolean
- */
- public function hasIntervalUs(){
- return $this->_has(2);
- }
-
- /**
- * Clear <interval_us> value
- *
- * @return \grpc\testing\ResponseParameters
- */
- public function clearIntervalUs(){
- return $this->_clear(2);
- }
-
- /**
- * Get <interval_us> value
- *
- * @return int
- */
- public function getIntervalUs(){
- return $this->_get(2);
- }
-
- /**
- * Set <interval_us> value
- *
- * @param int $value
- * @return \grpc\testing\ResponseParameters
- */
- public function setIntervalUs( $value){
- return $this->_set(2, $value);
- }
- }
-}
-
-namespace grpc\testing {
-
- class StreamingOutputCallRequest extends \DrSlump\Protobuf\Message {
-
- /** @var int - \grpc\testing\PayloadType */
- public $response_type = null;
-
- /** @var \grpc\testing\ResponseParameters[] */
- public $response_parameters = array();
-
- /** @var \grpc\testing\Payload */
- public $payload = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.StreamingOutputCallRequest');
-
- // OPTIONAL ENUM response_type = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "response_type";
- $f->type = \DrSlump\Protobuf::TYPE_ENUM;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $f->reference = '\grpc\testing\PayloadType';
- $descriptor->addField($f);
-
- // REPEATED MESSAGE response_parameters = 2
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 2;
- $f->name = "response_parameters";
- $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
- $f->rule = \DrSlump\Protobuf::RULE_REPEATED;
- $f->reference = '\grpc\testing\ResponseParameters';
- $descriptor->addField($f);
-
- // OPTIONAL MESSAGE payload = 3
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 3;
- $f->name = "payload";
- $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $f->reference = '\grpc\testing\Payload';
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <response_type> has a value
- *
- * @return boolean
- */
- public function hasResponseType(){
- return $this->_has(1);
- }
-
- /**
- * Clear <response_type> value
- *
- * @return \grpc\testing\StreamingOutputCallRequest
- */
- public function clearResponseType(){
- return $this->_clear(1);
- }
-
- /**
- * Get <response_type> value
- *
- * @return int - \grpc\testing\PayloadType
- */
- public function getResponseType(){
- return $this->_get(1);
- }
-
- /**
- * Set <response_type> value
- *
- * @param int - \grpc\testing\PayloadType $value
- * @return \grpc\testing\StreamingOutputCallRequest
- */
- public function setResponseType( $value){
- return $this->_set(1, $value);
- }
-
- /**
- * Check if <response_parameters> has a value
- *
- * @return boolean
- */
- public function hasResponseParameters(){
- return $this->_has(2);
- }
-
- /**
- * Clear <response_parameters> value
- *
- * @return \grpc\testing\StreamingOutputCallRequest
- */
- public function clearResponseParameters(){
- return $this->_clear(2);
- }
-
- /**
- * Get <response_parameters> value
- *
- * @param int $idx
- * @return \grpc\testing\ResponseParameters
- */
- public function getResponseParameters($idx = NULL){
- return $this->_get(2, $idx);
- }
-
- /**
- * Set <response_parameters> value
- *
- * @param \grpc\testing\ResponseParameters $value
- * @return \grpc\testing\StreamingOutputCallRequest
- */
- public function setResponseParameters(\grpc\testing\ResponseParameters $value, $idx = NULL){
- return $this->_set(2, $value, $idx);
- }
-
- /**
- * Get all elements of <response_parameters>
- *
- * @return \grpc\testing\ResponseParameters[]
- */
- public function getResponseParametersList(){
- return $this->_get(2);
- }
-
- /**
- * Add a new element to <response_parameters>
- *
- * @param \grpc\testing\ResponseParameters $value
- * @return \grpc\testing\StreamingOutputCallRequest
- */
- public function addResponseParameters(\grpc\testing\ResponseParameters $value){
- return $this->_add(2, $value);
- }
-
- /**
- * Check if <payload> has a value
- *
- * @return boolean
- */
- public function hasPayload(){
- return $this->_has(3);
- }
-
- /**
- * Clear <payload> value
- *
- * @return \grpc\testing\StreamingOutputCallRequest
- */
- public function clearPayload(){
- return $this->_clear(3);
- }
-
- /**
- * Get <payload> value
- *
- * @return \grpc\testing\Payload
- */
- public function getPayload(){
- return $this->_get(3);
- }
-
- /**
- * Set <payload> value
- *
- * @param \grpc\testing\Payload $value
- * @return \grpc\testing\StreamingOutputCallRequest
- */
- public function setPayload(\grpc\testing\Payload $value){
- return $this->_set(3, $value);
- }
- }
-}
-
-namespace grpc\testing {
-
- class StreamingOutputCallResponse extends \DrSlump\Protobuf\Message {
-
- /** @var \grpc\testing\Payload */
- public $payload = null;
-
-
- /** @var \Closure[] */
- protected static $__extensions = array();
-
- public static function descriptor()
- {
- $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'grpc.testing.StreamingOutputCallResponse');
-
- // OPTIONAL MESSAGE payload = 1
- $f = new \DrSlump\Protobuf\Field();
- $f->number = 1;
- $f->name = "payload";
- $f->type = \DrSlump\Protobuf::TYPE_MESSAGE;
- $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL;
- $f->reference = '\grpc\testing\Payload';
- $descriptor->addField($f);
-
- foreach (self::$__extensions as $cb) {
- $descriptor->addField($cb(), true);
- }
-
- return $descriptor;
- }
-
- /**
- * Check if <payload> has a value
- *
- * @return boolean
- */
- public function hasPayload(){
- return $this->_has(1);
- }
-
- /**
- * Clear <payload> value
- *
- * @return \grpc\testing\StreamingOutputCallResponse
- */
- public function clearPayload(){
- return $this->_clear(1);
- }
-
- /**
- * Get <payload> value
- *
- * @return \grpc\testing\Payload
- */
- public function getPayload(){
- return $this->_get(1);
- }
-
- /**
- * Set <payload> value
- *
- * @param \grpc\testing\Payload $value
- * @return \grpc\testing\StreamingOutputCallResponse
- */
- public function setPayload(\grpc\testing\Payload $value){
- return $this->_set(1, $value);
- }
- }
-}
-
diff --git a/src/php/tests/interop/messages.proto b/src/php/tests/interop/messages.proto
new file mode 100644
index 0000000..de0b1a2
--- /dev/null
+++ b/src/php/tests/interop/messages.proto
@@ -0,0 +1,132 @@
+
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Message definitions to be used by integration test service definitions.
+
+syntax = "proto2";
+
+package grpc.testing;
+
+// The type of payload that should be returned.
+enum PayloadType {
+ // Compressable text format.
+ COMPRESSABLE = 0;
+
+ // Uncompressable binary format.
+ UNCOMPRESSABLE = 1;
+
+ // Randomly chosen from all other formats defined in this enum.
+ RANDOM = 2;
+}
+
+// A block of data, to simply increase gRPC message size.
+message Payload {
+ // The type of data in body.
+ optional PayloadType type = 1 [default = COMPRESSABLE];
+ // Primary contents of payload.
+ optional bytes body = 2;
+}
+
+// Unary request.
+message SimpleRequest {
+ // Desired payload type in the response from the server.
+ // If response_type is RANDOM, server randomly chooses one from other formats.
+ optional PayloadType response_type = 1 [default = COMPRESSABLE];
+
+ // Desired payload size in the response from the server.
+ // If response_type is COMPRESSABLE, this denotes the size before compression.
+ optional int32 response_size = 2;
+
+ // Optional input payload sent along with the request.
+ optional Payload payload = 3;
+
+ // Whether SimpleResponse should include username.
+ optional bool fill_username = 4;
+
+ // Whether SimpleResponse should include OAuth scope.
+ optional bool fill_oauth_scope = 5;
+}
+
+// Unary response, as configured by the request.
+message SimpleResponse {
+ // Payload to increase message size.
+ optional Payload payload = 1;
+ // The user the request came from, for verifying authentication was
+ // successful when the client expected it.
+ optional string username = 2;
+ // OAuth scope.
+ optional string oauth_scope = 3;
+}
+
+// Client-streaming request.
+message StreamingInputCallRequest {
+ // Optional input payload sent along with the request.
+ optional Payload payload = 1;
+
+ // Not expecting any payload from the response.
+}
+
+// Client-streaming response.
+message StreamingInputCallResponse {
+ // Aggregated size of payloads received from the client.
+ optional int32 aggregated_payload_size = 1;
+}
+
+// Configuration for a particular response.
+message ResponseParameters {
+ // Desired payload sizes in responses from the server.
+ // If response_type is COMPRESSABLE, this denotes the size before compression.
+ optional int32 size = 1;
+
+ // Desired interval between consecutive responses in the response stream in
+ // microseconds.
+ optional int32 interval_us = 2;
+}
+
+// Server-streaming request.
+message StreamingOutputCallRequest {
+ // Desired payload type in the response from the server.
+ // If response_type is RANDOM, the payload from each response in the stream
+ // might be of different types. This is to simulate a mixed type of payload
+ // stream.
+ optional PayloadType response_type = 1 [default = COMPRESSABLE];
+
+ // Configuration for each expected response message.
+ repeated ResponseParameters response_parameters = 2;
+
+ // Optional input payload sent along with the request.
+ optional Payload payload = 3;
+}
+
+// Server-streaming response, as configured by the request and parameters.
+message StreamingOutputCallResponse {
+ // Payload to increase response size.
+ optional Payload payload = 1;
+}
diff --git a/src/php/tests/interop/test.php b/src/php/tests/interop/test.php
deleted file mode 100755
index 014bbc9..0000000
--- a/src/php/tests/interop/test.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-// DO NOT EDIT! Generated by Protobuf-PHP protoc plugin 1.0
-// Source: test/cpp/interop/test.proto
-// Date: 2015-01-30 23:30:46
-
-namespace grpc\testing {
-
- class TestServiceClient{
-
- private $rpc_impl;
-
- public function __construct($rpc_impl) {
- $this->rpc_impl = $rpc_impl;
- }
- /**
- * @param grpc\testing\EmptyMessage $input
- */
- public function EmptyCall(\grpc\testing\EmptyMessage $argument, $metadata = array()) {
- return $this->rpc_impl->_simpleRequest('/grpc.testing.TestService/EmptyCall', $argument, '\grpc\testing\EmptyMessage::deserialize', $metadata);
- }
- /**
- * @param grpc\testing\SimpleRequest $input
- */
- public function UnaryCall(\grpc\testing\SimpleRequest $argument, $metadata = array()) {
- return $this->rpc_impl->_simpleRequest('/grpc.testing.TestService/UnaryCall', $argument, '\grpc\testing\SimpleResponse::deserialize', $metadata);
- }
- /**
- * @param grpc\testing\StreamingOutputCallRequest $input
- */
- public function StreamingOutputCall($argument, $metadata = array()) {
- return $this->rpc_impl->_serverStreamRequest('/grpc.testing.TestService/StreamingOutputCall', $argument, '\grpc\testing\StreamingOutputCallResponse::deserialize', $metadata);
- }
- /**
- * @param grpc\testing\StreamingInputCallRequest $input
- */
- public function StreamingInputCall($arguments, $metadata = array()) {
- return $this->rpc_impl->_clientStreamRequest('/grpc.testing.TestService/StreamingInputCall', $arguments, '\grpc\testing\StreamingInputCallResponse::deserialize', $metadata);
- }
- /**
- * @param grpc\testing\StreamingOutputCallRequest $input
- */
- public function FullDuplexCall($metadata = array()) {
- return $this->rpc_impl->_bidiRequest('/grpc.testing.TestService/FullDuplexCall', '\grpc\testing\StreamingOutputCallResponse::deserialize', $metadata);
- }
- /**
- * @param grpc\testing\StreamingOutputCallRequest $input
- */
- public function HalfDuplexCall($metadata = array()) {
- return $this->rpc_impl->_bidiRequest('/grpc.testing.TestService/HalfDuplexCall', '\grpc\testing\StreamingOutputCallResponse::deserialize', $metadata);
- }
- }
-}
diff --git a/src/php/tests/interop/test.proto b/src/php/tests/interop/test.proto
new file mode 100644
index 0000000..39c08f3
--- /dev/null
+++ b/src/php/tests/interop/test.proto
@@ -0,0 +1,72 @@
+
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// An integration test service that covers all the method signature permutations
+// of unary/streaming requests/responses.
+syntax = "proto2";
+
+import "empty.proto";
+import "messages.proto";
+
+package grpc.testing;
+
+// A simple service to test the various types of RPCs and experiment with
+// performance with various types of payload.
+service TestService {
+ // One empty request followed by one empty response.
+ rpc EmptyCall(grpc.testing.EmptyMessage) returns (grpc.testing.EmptyMessage);
+
+ // One request followed by one response.
+ // TODO(Issue 527): Describe required server behavior.
+ rpc UnaryCall(SimpleRequest) returns (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)
+ returns (stream StreamingOutputCallResponse);
+
+ // A sequence of requests followed by one response (streamed upload).
+ // The server returns the aggregated size of client payload as the result.
+ rpc StreamingInputCall(stream StreamingInputCallRequest)
+ returns (StreamingInputCallResponse);
+
+ // A sequence of requests with each request served by the server immediately.
+ // As one request could lead to multiple responses, this interface
+ // demonstrates the idea of full duplexing.
+ rpc FullDuplexCall(stream StreamingOutputCallRequest)
+ returns (stream StreamingOutputCallResponse);
+
+ // A sequence of requests followed by a sequence of responses.
+ // The server buffers all the client requests and then serves them in order. A
+ // stream of responses are returned to the client when the server starts with
+ // first request.
+ rpc HalfDuplexCall(stream StreamingOutputCallRequest)
+ returns (stream StreamingOutputCallResponse);
+}
diff --git a/src/php/tests/unit_tests/CallTest.php b/src/php/tests/unit_tests/CallTest.php
index 8bb0927..d361ce0 100755
--- a/src/php/tests/unit_tests/CallTest.php
+++ b/src/php/tests/unit_tests/CallTest.php
@@ -36,65 +36,47 @@
static $port;
public static function setUpBeforeClass() {
- $cq = new Grpc\CompletionQueue();
- self::$server = new Grpc\Server($cq, []);
+ self::$server = new Grpc\Server([]);
self::$port = self::$server->add_http2_port('0.0.0.0:0');
}
public function setUp() {
- $this->cq = new Grpc\CompletionQueue();
$this->channel = new Grpc\Channel('localhost:' . self::$port, []);
$this->call = new Grpc\Call($this->channel,
'/foo',
Grpc\Timeval::inf_future());
}
- /**
- * @expectedException LogicException
- * @expectedExceptionCode Grpc\CALL_ERROR_INVALID_FLAGS
- * @expectedExceptionMessage invoke
- */
- public function testInvokeRejectsBadFlags() {
- $this->call->invoke($this->cq, 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
- tests */
-
public function testAddEmptyMetadata() {
- $this->call->add_metadata([], 0);
- /* Dummy assert: Checks that the previous call completed without error */
- $this->assertTrue(true);
+ $batch = [
+ Grpc\OP_SEND_INITIAL_METADATA => []
+ ];
+ $result = $this->call->start_batch($batch);
+ $this->assertTrue($result->send_metadata);
}
public function testAddSingleMetadata() {
- $this->call->add_metadata(['key' => ['value']], 0);
- /* Dummy assert: Checks that the previous call completed without error */
- $this->assertTrue(true);
+ $batch = [
+ Grpc\OP_SEND_INITIAL_METADATA => ['key' => ['value']]
+ ];
+ $result = $this->call->start_batch($batch);
+ $this->assertTrue($result->send_metadata);
}
public function testAddMultiValueMetadata() {
- $this->call->add_metadata(['key' => ['value1', 'value2']], 0);
- /* Dummy assert: Checks that the previous call completed without error */
- $this->assertTrue(true);
+ $batch = [
+ Grpc\OP_SEND_INITIAL_METADATA => ['key' => ['value1', 'value2']]
+ ];
+ $result = $this->call->start_batch($batch);
+ $this->assertTrue($result->send_metadata);
}
public function testAddSingleAndMultiValueMetadata() {
- $this->call->add_metadata(
- ['key1' => ['value1'],
- 'key2' => ['value2', 'value3']], 0);
- /* Dummy assert: Checks that the previous call completed without error */
- $this->assertTrue(true);
+ $batch = [
+ Grpc\OP_SEND_INITIAL_METADATA => ['key1' => ['value1'],
+ 'key2' => ['value2', 'value3']]
+ ];
+ $result = $this->call->start_batch($batch);
+ $this->assertTrue($result->send_metadata);
}
}
diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php
index 0cbc506..3e165b7 100755
--- a/src/php/tests/unit_tests/EndToEndTest.php
+++ b/src/php/tests/unit_tests/EndToEndTest.php
@@ -33,18 +33,15 @@
*/
class EndToEndTest extends PHPUnit_Framework_TestCase{
public function setUp() {
- $this->client_queue = new Grpc\CompletionQueue();
- $this->server_queue = new Grpc\CompletionQueue();
- $this->server = new Grpc\Server($this->server_queue, []);
+ $this->server = new Grpc\Server([]);
$port = $this->server->add_http2_port('0.0.0.0:0');
$this->channel = new Grpc\Channel('localhost:' . $port, []);
+ $this->server->start();
}
public function tearDown() {
unset($this->channel);
unset($this->server);
- unset($this->client_queue);
- unset($this->server_queue);
}
public function testSimpleRequestBody() {
@@ -53,55 +50,45 @@
$call = new Grpc\Call($this->channel,
'dummy_method',
$deadline);
- $tag = 1;
- $call->invoke($this->client_queue, $tag, $tag);
- $server_tag = 2;
- $call->writes_done($tag);
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
- $this->assertSame(Grpc\OP_OK, $event->data);
+ $event = $call->start_batch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_CLOSE_FROM_CLIENT => true
+ ]);
- // check that a server rpc new was received
- $this->server->start();
- $this->server->request_call($server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\SERVER_RPC_NEW, $event->type);
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_close);
+
+ $event = $this->server->request_call();
+ $this->assertSame('dummy_method', $event->method);
+ $this->assertSame([], $event->metadata);
$server_call = $event->call;
- $this->assertNotNull($server_call);
- $server_call->server_accept($this->server_queue, $server_tag);
- $server_call->server_end_initial_metadata();
+ $event = $server_call->start_batch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_STATUS_FROM_SERVER => [
+ 'metadata' => [],
+ 'code' => Grpc\STATUS_OK,
+ 'details' => $status_text
+ ],
+ Grpc\OP_RECV_CLOSE_ON_SERVER => true
+ ]);
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_status);
+ $this->assertFalse($event->cancelled);
- // the server sends the status
- $server_call->start_write_status(Grpc\STATUS_OK, $status_text, $server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
- $this->assertSame(Grpc\OP_OK, $event->data);
+ $event = $call->start_batch([
+ Grpc\OP_RECV_INITIAL_METADATA => true,
+ Grpc\OP_RECV_STATUS_ON_CLIENT => true
+ ]);
- // the client gets CLIENT_METADATA_READ
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type);
-
- // the client gets FINISHED
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISHED, $event->type);
- $status = $event->data;
+ $this->assertSame([], $event->metadata);
+ $status = $event->status;
+ $this->assertSame([], $status->metadata);
$this->assertSame(Grpc\STATUS_OK, $status->code);
$this->assertSame($status_text, $status->details);
- // and the server gets FINISHED
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISHED, $event->type);
- $status = $event->data;
-
unset($call);
unset($server_call);
}
@@ -115,79 +102,52 @@
$call = new Grpc\Call($this->channel,
'dummy_method',
$deadline);
- $tag = 1;
- $call->invoke($this->client_queue, $tag, $tag);
- $server_tag = 2;
+ $event = $call->start_batch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
+ Grpc\OP_SEND_MESSAGE => $req_text
+ ]);
- // the client writes
- $call->start_write($req_text, $tag);
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\WRITE_ACCEPTED, $event->type);
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_close);
+ $this->assertTrue($event->send_message);
- // check that a server rpc new was received
- $this->server->start();
- $this->server->request_call($server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\SERVER_RPC_NEW, $event->type);
+ $event = $this->server->request_call();
+ $this->assertSame('dummy_method', $event->method);
$server_call = $event->call;
- $this->assertNotNull($server_call);
- $server_call->server_accept($this->server_queue, $server_tag);
- $server_call->server_end_initial_metadata();
+ $event = $server_call->start_batch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_MESSAGE => $reply_text,
+ Grpc\OP_SEND_STATUS_FROM_SERVER => [
+ 'metadata' => [],
+ 'code' => Grpc\STATUS_OK,
+ 'details' => $status_text
+ ],
+ Grpc\OP_RECV_MESSAGE => true,
+ Grpc\OP_RECV_CLOSE_ON_SERVER => true,
+ ]);
- // start the server read
- $server_call->start_read($server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\READ, $event->type);
- $this->assertSame($req_text, $event->data);
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_status);
+ $this->assertTrue($event->send_message);
+ $this->assertFalse($event->cancelled);
+ $this->assertSame($req_text, $event->message);
- // the server replies
- $server_call->start_write($reply_text, $server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\WRITE_ACCEPTED, $event->type);
+ $event = $call->start_batch([
+ Grpc\OP_RECV_INITIAL_METADATA => true,
+ Grpc\OP_RECV_MESSAGE => true,
+ Grpc\OP_RECV_STATUS_ON_CLIENT => true,
+ ]);
- // the client reads the metadata
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type);
-
- // the client reads the reply
- $call->start_read($tag);
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\READ, $event->type);
- $this->assertSame($reply_text, $event->data);
-
- // the client sends writes done
- $call->writes_done($tag);
- $event = $this->client_queue->next($deadline);
- $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
- $this->assertSame(Grpc\OP_OK, $event->data);
-
- // the server sends the status
- $server_call->start_write_status(GRPC\STATUS_OK, $status_text, $server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
- $this->assertSame(Grpc\OP_OK, $event->data);
-
- // the client gets FINISHED
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISHED, $event->type);
- $status = $event->data;
+ $this->assertSame([], $event->metadata);
+ $this->assertSame($reply_text, $event->message);
+ $status = $event->status;
+ $this->assertSame([], $status->metadata);
$this->assertSame(Grpc\STATUS_OK, $status->code);
$this->assertSame($status_text, $status->details);
- // and the server gets FINISHED
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(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 896afea..2d62fe9 100755
--- a/src/php/tests/unit_tests/SecureEndToEndTest.php
+++ b/src/php/tests/unit_tests/SecureEndToEndTest.php
@@ -33,17 +33,16 @@
*/
class SecureEndToEndTest extends PHPUnit_Framework_TestCase{
public function setUp() {
- $this->client_queue = new Grpc\CompletionQueue();
- $this->server_queue = new Grpc\CompletionQueue();
$credentials = Grpc\Credentials::createSsl(
file_get_contents(dirname(__FILE__) . '/../data/ca.pem'));
$server_credentials = Grpc\ServerCredentials::createSsl(
null,
file_get_contents(dirname(__FILE__) . '/../data/server1.key'),
file_get_contents(dirname(__FILE__) . '/../data/server1.pem'));
- $this->server = new Grpc\Server($this->server_queue);
+ $this->server = new Grpc\Server();
$port = $this->server->add_secure_http2_port('0.0.0.0:0',
$server_credentials);
+ $this->server->start();
$this->channel = new Grpc\Channel(
'localhost:' . $port,
[
@@ -55,70 +54,58 @@
public function tearDown() {
unset($this->channel);
unset($this->server);
- unset($this->client_queue);
- unset($this->server_queue);
}
public function testSimpleRequestBody() {
- $this->server->start();
$deadline = Grpc\Timeval::inf_future();
$status_text = 'xyz';
$call = new Grpc\Call($this->channel,
'dummy_method',
$deadline);
- $tag = 1;
- $call->invoke($this->client_queue, $tag, $tag);
- $server_tag = 2;
- $call->writes_done($tag);
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
- $this->assertSame(Grpc\OP_OK, $event->data);
+ $event = $call->start_batch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_CLOSE_FROM_CLIENT => true
+ ]);
- // check that a server rpc new was received
- $this->server->request_call($server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\SERVER_RPC_NEW, $event->type);
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_close);
+
+ $event = $this->server->request_call();
+ $this->assertSame('dummy_method', $event->method);
+ $this->assertSame([], $event->metadata);
$server_call = $event->call;
- $this->assertNotNull($server_call);
- $server_call->server_accept($this->server_queue, $server_tag);
- $server_call->server_end_initial_metadata();
+ $event = $server_call->start_batch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_STATUS_FROM_SERVER => [
+ 'metadata' => [],
+ 'code' => Grpc\STATUS_OK,
+ 'details' => $status_text
+ ],
+ Grpc\OP_RECV_CLOSE_ON_SERVER => true
+ ]);
- // the server sends the status
- $server_call->start_write_status(Grpc\STATUS_OK, $status_text, $server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
- $this->assertSame(Grpc\OP_OK, $event->data);
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_status);
+ $this->assertFalse($event->cancelled);
- // the client gets CLIENT_METADATA_READ
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type);
+ $event = $call->start_batch([
+ Grpc\OP_RECV_INITIAL_METADATA => true,
+ Grpc\OP_RECV_STATUS_ON_CLIENT => true
+ ]);
- // the client gets FINISHED
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISHED, $event->type);
- $status = $event->data;
+ $this->assertSame([], $event->metadata);
+ $status = $event->status;
+ $this->assertSame([], $status->metadata);
$this->assertSame(Grpc\STATUS_OK, $status->code);
$this->assertSame($status_text, $status->details);
- // and the server gets FINISHED
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISHED, $event->type);
- $status = $event->data;
-
unset($call);
unset($server_call);
}
public function testClientServerFullRequestResponse() {
- $this->server->start();
$deadline = Grpc\Timeval::inf_future();
$req_text = 'client_server_full_request_response';
$reply_text = 'reply:client_server_full_request_response';
@@ -127,78 +114,52 @@
$call = new Grpc\Call($this->channel,
'dummy_method',
$deadline);
- $tag = 1;
- $call->invoke($this->client_queue, $tag, $tag);
- $server_tag = 2;
+ $event = $call->start_batch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
+ Grpc\OP_SEND_MESSAGE => $req_text
+ ]);
- // the client writes
- $call->start_write($req_text, $tag);
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\WRITE_ACCEPTED, $event->type);
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_close);
+ $this->assertTrue($event->send_message);
- // check that a server rpc new was received
- $this->server->request_call($server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\SERVER_RPC_NEW, $event->type);
+ $event = $this->server->request_call();
+ $this->assertSame('dummy_method', $event->method);
$server_call = $event->call;
- $this->assertNotNull($server_call);
- $server_call->server_accept($this->server_queue, $server_tag);
- $server_call->server_end_initial_metadata();
+ $event = $server_call->start_batch([
+ Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_MESSAGE => $reply_text,
+ Grpc\OP_SEND_STATUS_FROM_SERVER => [
+ 'metadata' => [],
+ 'code' => Grpc\STATUS_OK,
+ 'details' => $status_text
+ ],
+ Grpc\OP_RECV_MESSAGE => true,
+ Grpc\OP_RECV_CLOSE_ON_SERVER => true,
+ ]);
- // start the server read
- $server_call->start_read($server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\READ, $event->type);
- $this->assertSame($req_text, $event->data);
+ $this->assertTrue($event->send_metadata);
+ $this->assertTrue($event->send_status);
+ $this->assertTrue($event->send_message);
+ $this->assertFalse($event->cancelled);
+ $this->assertSame($req_text, $event->message);
- // the server replies
- $server_call->start_write($reply_text, $server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\WRITE_ACCEPTED, $event->type);
+ $event = $call->start_batch([
+ Grpc\OP_RECV_INITIAL_METADATA => true,
+ Grpc\OP_RECV_MESSAGE => true,
+ Grpc\OP_RECV_STATUS_ON_CLIENT => true,
+ ]);
- // the client reads the metadata
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type);
-
- // the client reads the reply
- $call->start_read($tag);
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\READ, $event->type);
- $this->assertSame($reply_text, $event->data);
-
- // the client sends writes done
- $call->writes_done($tag);
- $event = $this->client_queue->next($deadline);
- $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
- $this->assertSame(Grpc\OP_OK, $event->data);
-
- // the server sends the status
- $server_call->start_write_status(GRPC\STATUS_OK, $status_text, $server_tag);
- $event = $this->server_queue->next($deadline);
- $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type);
- $this->assertSame(Grpc\OP_OK, $event->data);
-
- // the client gets FINISHED
- $event = $this->client_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISHED, $event->type);
- $status = $event->data;
+ $this->assertSame([], $event->metadata);
+ $this->assertSame($reply_text, $event->message);
+ $status = $event->status;
+ $this->assertSame([], $status->metadata);
$this->assertSame(Grpc\STATUS_OK, $status->code);
$this->assertSame($status_text, $status->details);
- // and the server gets FINISHED
- $event = $this->server_queue->next($deadline);
- $this->assertNotNull($event);
- $this->assertSame(Grpc\FINISHED, $event->type);
-
unset($call);
unset($server_call);
}
diff --git a/src/python/interop/interop/_insecure_interop_test.py b/src/python/interop/interop/_insecure_interop_test.py
index e4ddff1..42e7a4d 100644
--- a/src/python/interop/interop/_insecure_interop_test.py
+++ b/src/python/interop/interop/_insecure_interop_test.py
@@ -42,11 +42,11 @@
unittest.TestCase):
def setUp(self):
- self.server = implementations.insecure_server(
+ self.server = implementations.server(
methods.SERVICE_NAME, methods.SERVER_METHODS, 0)
self.server.start()
port = self.server.port()
- self.stub = implementations.insecure_stub(
+ self.stub = implementations.stub(
methods.SERVICE_NAME, methods.CLIENT_METHODS, 'localhost', port)
def tearDown(self):
diff --git a/src/python/interop/interop/_secure_interop_test.py b/src/python/interop/interop/_secure_interop_test.py
index 214212d..27e7631 100644
--- a/src/python/interop/interop/_secure_interop_test.py
+++ b/src/python/interop/interop/_secure_interop_test.py
@@ -45,14 +45,15 @@
unittest.TestCase):
def setUp(self):
- self.server = implementations.secure_server(
+ self.server = implementations.server(
methods.SERVICE_NAME, methods.SERVER_METHODS, 0,
- resources.private_key(), resources.certificate_chain())
+ private_key=resources.private_key(),
+ certificate_chain=resources.certificate_chain())
self.server.start()
port = self.server.port()
- self.stub = implementations.secure_stub(
+ self.stub = implementations.stub(
methods.SERVICE_NAME, methods.CLIENT_METHODS, 'localhost', port,
- resources.test_root_certificates(), None, None,
+ secure=True, root_certificates=resources.test_root_certificates(),
server_host_override=_SERVER_HOST_OVERRIDE)
def tearDown(self):
diff --git a/src/python/interop/interop/client.py b/src/python/interop/interop/client.py
index fb7dfb5..85a0dcd 100644
--- a/src/python/interop/interop/client.py
+++ b/src/python/interop/interop/client.py
@@ -66,14 +66,14 @@
else:
root_certificates = resources.prod_root_certificates()
- stub = implementations.secure_stub(
+ stub = implementations.stub(
methods.SERVICE_NAME, methods.CLIENT_METHODS, args.server_host,
- args.server_port, root_certificates, None, None,
+ args.server_port, secure=True, root_certificates=root_certificates,
server_host_override=args.server_host_override)
else:
- stub = implementations.insecure_stub(
+ stub = implementations.stub(
methods.SERVICE_NAME, methods.CLIENT_METHODS, args.server_host,
- args.server_port)
+ args.server_port, secure=False)
return stub
diff --git a/src/python/interop/interop/server.py b/src/python/interop/interop/server.py
index 5791203..a67d412 100644
--- a/src/python/interop/interop/server.py
+++ b/src/python/interop/interop/server.py
@@ -53,11 +53,11 @@
if args.use_tls:
private_key = resources.private_key()
certificate_chain = resources.certificate_chain()
- server = implementations.secure_server(
- methods.SERVICE_NAME, methods.SERVER_METHODS, args.port, private_key,
- certificate_chain)
+ server = implementations.server(
+ methods.SERVICE_NAME, methods.SERVER_METHODS, args.port,
+ private_key=private_key, certificate_chain=certificate_chain)
else:
- server = implementations.insecure_server(
+ server = implementations.server(
methods.SERVICE_NAME, methods.SERVER_METHODS, args.port)
server.start()
diff --git a/src/python/src/grpc/_adapter/_call.c b/src/python/src/grpc/_adapter/_call.c
index d8806e5..f837267 100644
--- a/src/python/src/grpc/_adapter/_call.c
+++ b/src/python/src/grpc/_adapter/_call.c
@@ -160,8 +160,22 @@
return result;
}
+static const PyObject *pygrpc_call_add_metadata(Call *self, PyObject *args) {
+ const char* key = NULL;
+ const char* value = NULL;
+ int value_length = 0;
+ if (!PyArg_ParseTuple(args, "ss#", &key, &value, &value_length)) {
+ return NULL;
+ }
+ grpc_metadata metadata;
+ metadata.key = key;
+ metadata.value = value;
+ metadata.value_length = value_length;
+ return pygrpc_translate_call_error(
+ grpc_call_add_metadata_old(self->c_call, &metadata, 0));
+}
+
static const PyObject *pygrpc_call_premetadata(Call *self) {
- /* TODO(nathaniel): Metadata support. */
return pygrpc_translate_call_error(
grpc_call_server_end_initial_metadata_old(self->c_call, 0));
}
@@ -236,6 +250,11 @@
{"complete", (PyCFunction)pygrpc_call_complete, METH_O,
"Complete writes to this call."},
{"accept", (PyCFunction)pygrpc_call_accept, METH_VARARGS, "Accept an RPC."},
+ {"add_metadata", (PyCFunction)pygrpc_call_add_metadata, METH_VARARGS,
+ "Add metadata to the call. May not be called after invoke on the client "
+ "side. On the server side: when called before premetadata it provides "
+ "'leading' metadata, when called after premetadata but before status it "
+ "provides 'trailing metadata'; may not be called after status."},
{"premetadata", (PyCFunction)pygrpc_call_premetadata, METH_VARARGS,
"Indicate the end of leading metadata in the response."},
{"read", (PyCFunction)pygrpc_call_read, METH_O,
diff --git a/src/python/src/grpc/_adapter/_call.h b/src/python/src/grpc/_adapter/_call.h
index a936e23..fabc6f3 100644
--- a/src/python/src/grpc/_adapter/_call.h
+++ b/src/python/src/grpc/_adapter/_call.h
@@ -37,7 +37,10 @@
#include <Python.h>
#include <grpc/grpc.h>
-typedef struct { PyObject_HEAD grpc_call *c_call; } Call;
+typedef struct {
+ PyObject_HEAD;
+ grpc_call *c_call;
+} Call;
PyTypeObject pygrpc_CallType;
diff --git a/src/python/src/grpc/_adapter/_channel.h b/src/python/src/grpc/_adapter/_channel.h
index 6241ccd..303b675 100644
--- a/src/python/src/grpc/_adapter/_channel.h
+++ b/src/python/src/grpc/_adapter/_channel.h
@@ -37,7 +37,10 @@
#include <Python.h>
#include <grpc/grpc.h>
-typedef struct { PyObject_HEAD grpc_channel *c_channel; } Channel;
+typedef struct {
+ PyObject_HEAD;
+ grpc_channel *c_channel;
+} Channel;
PyTypeObject pygrpc_ChannelType;
diff --git a/src/python/src/grpc/_adapter/_client_credentials.h b/src/python/src/grpc/_adapter/_client_credentials.h
index 664dc80..47476ce 100644
--- a/src/python/src/grpc/_adapter/_client_credentials.h
+++ b/src/python/src/grpc/_adapter/_client_credentials.h
@@ -38,7 +38,8 @@
#include <grpc/grpc_security.h>
typedef struct {
- PyObject_HEAD grpc_credentials *c_client_credentials;
+ PyObject_HEAD;
+ grpc_credentials *c_client_credentials;
} ClientCredentials;
PyTypeObject pygrpc_ClientCredentialsType;
diff --git a/src/python/src/grpc/_adapter/_completion_queue.c b/src/python/src/grpc/_adapter/_completion_queue.c
index b56ca19..76d6b6c 100644
--- a/src/python/src/grpc/_adapter/_completion_queue.c
+++ b/src/python/src/grpc/_adapter/_completion_queue.c
@@ -115,35 +115,56 @@
}
}
+static PyObject *pygrpc_metadata_collection_get(
+ grpc_metadata *metadata_elements, size_t count) {
+ PyObject *metadata = PyList_New(count);
+ size_t i;
+ for (i = 0; i < count; ++i) {
+ grpc_metadata elem = metadata_elements[i];
+ PyObject *key = PyString_FromString(elem.key);
+ PyObject *value = PyString_FromStringAndSize(elem.value, elem.value_length);
+ PyObject* kvp = PyTuple_Pack(2, key, value);
+ // n.b. PyList_SetItem *steals* a reference to the set element.
+ PyList_SetItem(metadata, i, kvp);
+ Py_DECREF(key);
+ Py_DECREF(value);
+ }
+ return metadata;
+}
+
static PyObject *pygrpc_stop_event_args(grpc_event *c_event) {
- return PyTuple_Pack(7, stop_event_kind, Py_None, Py_None, Py_None,
- Py_None, Py_None, Py_None);
+ return PyTuple_Pack(8, stop_event_kind, Py_None, Py_None, Py_None,
+ Py_None, Py_None, Py_None, Py_None);
}
static PyObject *pygrpc_write_event_args(grpc_event *c_event) {
PyObject *write_accepted =
c_event->data.write_accepted == GRPC_OP_OK ? Py_True : Py_False;
- return PyTuple_Pack(7, write_event_kind, (PyObject *)c_event->tag,
- write_accepted, Py_None, Py_None, Py_None, Py_None);
+ return PyTuple_Pack(8, write_event_kind, (PyObject *)c_event->tag,
+ write_accepted, Py_None, Py_None, Py_None, Py_None,
+ Py_None);
}
static PyObject *pygrpc_complete_event_args(grpc_event *c_event) {
PyObject *complete_accepted =
c_event->data.finish_accepted == GRPC_OP_OK ? Py_True : Py_False;
- return PyTuple_Pack(7, complete_event_kind, (PyObject *)c_event->tag,
- Py_None, complete_accepted, Py_None, Py_None, Py_None);
+ return PyTuple_Pack(8, complete_event_kind, (PyObject *)c_event->tag,
+ Py_None, complete_accepted, Py_None, Py_None, Py_None,
+ Py_None);
}
static PyObject *pygrpc_service_event_args(grpc_event *c_event) {
if (c_event->data.server_rpc_new.method == NULL) {
- return PyTuple_Pack(7, service_event_kind, c_event->tag,
- Py_None, Py_None, Py_None, Py_None, Py_None);
+ return PyTuple_Pack(
+ 8, service_event_kind, c_event->tag, Py_None, Py_None, Py_None, Py_None,
+ Py_None, Py_None);
} else {
PyObject *method = NULL;
PyObject *host = NULL;
PyObject *service_deadline = NULL;
Call *call = NULL;
PyObject *service_acceptance = NULL;
+ PyObject *metadata = NULL;
PyObject *event_args = NULL;
method = PyBytes_FromString(c_event->data.server_rpc_new.method);
@@ -173,11 +194,16 @@
goto error;
}
- event_args = PyTuple_Pack(7, service_event_kind,
+ metadata = pygrpc_metadata_collection_get(
+ c_event->data.server_rpc_new.metadata_elements,
+ c_event->data.server_rpc_new.metadata_count);
+ event_args = PyTuple_Pack(8, service_event_kind,
(PyObject *)c_event->tag, Py_None, Py_None,
- service_acceptance, Py_None, Py_None);
+ service_acceptance, Py_None, Py_None,
+ metadata);
Py_DECREF(service_acceptance);
+ Py_DECREF(metadata);
error:
Py_XDECREF(call);
Py_XDECREF(method);
@@ -190,8 +216,8 @@
static PyObject *pygrpc_read_event_args(grpc_event *c_event) {
if (c_event->data.read == NULL) {
- return PyTuple_Pack(7, read_event_kind, (PyObject *)c_event->tag,
- Py_None, Py_None, Py_None, Py_None, Py_None);
+ return PyTuple_Pack(8, read_event_kind, (PyObject *)c_event->tag,
+ Py_None, Py_None, Py_None, Py_None, Py_None, Py_None);
} else {
size_t length;
size_t offset;
@@ -216,17 +242,23 @@
if (bytes == NULL) {
return NULL;
}
- event_args = PyTuple_Pack(7, read_event_kind, (PyObject *)c_event->tag,
- Py_None, Py_None, Py_None, bytes, Py_None);
+ event_args = PyTuple_Pack(8, read_event_kind, (PyObject *)c_event->tag,
+ Py_None, Py_None, Py_None, bytes, Py_None,
+ Py_None);
Py_DECREF(bytes);
return event_args;
}
}
static PyObject *pygrpc_metadata_event_args(grpc_event *c_event) {
- /* TODO(nathaniel): Actual transmission of metadata. */
- return PyTuple_Pack(7, metadata_event_kind, (PyObject *)c_event->tag,
- Py_None, Py_None, Py_None, Py_None, Py_None);
+ PyObject *metadata = pygrpc_metadata_collection_get(
+ c_event->data.client_metadata_read.elements,
+ c_event->data.client_metadata_read.count);
+ PyObject* result = PyTuple_Pack(
+ 8, metadata_event_kind, (PyObject *)c_event->tag, Py_None, Py_None,
+ Py_None, Py_None, Py_None, metadata);
+ Py_DECREF(metadata);
+ return result;
}
static PyObject *pygrpc_finished_event_args(grpc_event *c_event) {
@@ -253,9 +285,14 @@
if (status == NULL) {
return NULL;
}
- event_args = PyTuple_Pack(7, finish_event_kind, (PyObject *)c_event->tag,
- Py_None, Py_None, Py_None, Py_None, status);
+ PyObject* metadata = pygrpc_metadata_collection_get(
+ c_event->data.finished.metadata_elements,
+ c_event->data.finished.metadata_count);
+ event_args = PyTuple_Pack(8, finish_event_kind, (PyObject *)c_event->tag,
+ Py_None, Py_None, Py_None, Py_None, status,
+ metadata);
Py_DECREF(status);
+ Py_DECREF(metadata);
return event_args;
}
diff --git a/src/python/src/grpc/_adapter/_completion_queue.h b/src/python/src/grpc/_adapter/_completion_queue.h
index 8e5ee9f..3a39476 100644
--- a/src/python/src/grpc/_adapter/_completion_queue.h
+++ b/src/python/src/grpc/_adapter/_completion_queue.h
@@ -38,7 +38,8 @@
#include <grpc/grpc.h>
typedef struct {
- PyObject_HEAD grpc_completion_queue *c_completion_queue;
+ PyObject_HEAD;
+ grpc_completion_queue *c_completion_queue;
} CompletionQueue;
PyTypeObject pygrpc_CompletionQueueType;
diff --git a/src/python/src/grpc/_adapter/_datatypes.py b/src/python/src/grpc/_adapter/_datatypes.py
index e271ec8..3b22784 100644
--- a/src/python/src/grpc/_adapter/_datatypes.py
+++ b/src/python/src/grpc/_adapter/_datatypes.py
@@ -70,7 +70,7 @@
collections.namedtuple(
'Event',
['kind', 'tag', 'write_accepted', 'complete_accepted',
- 'service_acceptance', 'bytes', 'status'])):
+ 'service_acceptance', 'bytes', 'status', 'metadata'])):
"""Describes an event emitted from a completion queue."""
@enum.unique
diff --git a/src/python/src/grpc/_adapter/_low_test.py b/src/python/src/grpc/_adapter/_low_test.py
index b04ac1c..e88b709 100644
--- a/src/python/src/grpc/_adapter/_low_test.py
+++ b/src/python/src/grpc/_adapter/_low_test.py
@@ -115,6 +115,18 @@
def _perform_echo_test(self, test_data):
method = 'test method'
details = 'test details'
+ server_leading_metadata_key = 'my_server_leading_key'
+ server_leading_metadata_value = 'my_server_leading_value'
+ server_trailing_metadata_key = 'my_server_trailing_key'
+ server_trailing_metadata_value = 'my_server_trailing_value'
+ client_metadata_key = 'my_client_key'
+ client_metadata_value = 'my_client_value'
+ server_leading_binary_metadata_key = 'my_server_leading_key-bin'
+ server_leading_binary_metadata_value = b'\0'*2047
+ server_trailing_binary_metadata_key = 'my_server_trailing_key-bin'
+ server_trailing_binary_metadata_value = b'\0'*2047
+ client_binary_metadata_key = 'my_client_key-bin'
+ client_binary_metadata_value = b'\0'*2047
deadline = _FUTURE
metadata_tag = object()
finish_tag = object()
@@ -128,6 +140,9 @@
client_data = []
client_call = _low.Call(self.channel, method, self.host, deadline)
+ client_call.add_metadata(client_metadata_key, client_metadata_value)
+ client_call.add_metadata(client_binary_metadata_key,
+ client_binary_metadata_value)
client_call.invoke(self.client_completion_queue, metadata_tag, finish_tag)
@@ -139,15 +154,31 @@
self.assertEqual(method, service_accepted.service_acceptance.method)
self.assertEqual(self.host, service_accepted.service_acceptance.host)
self.assertIsNotNone(service_accepted.service_acceptance.call)
+ metadata = dict(service_accepted.metadata)
+ self.assertIn(client_metadata_key, metadata)
+ self.assertEqual(client_metadata_value, metadata[client_metadata_key])
+ self.assertIn(client_binary_metadata_key, metadata)
+ self.assertEqual(client_binary_metadata_value,
+ metadata[client_binary_metadata_key])
server_call = service_accepted.service_acceptance.call
server_call.accept(self.server_completion_queue, finish_tag)
+ server_call.add_metadata(server_leading_metadata_key,
+ server_leading_metadata_value)
+ server_call.add_metadata(server_leading_binary_metadata_key,
+ server_leading_binary_metadata_value)
server_call.premetadata()
metadata_accepted = self.client_completion_queue.get(_FUTURE)
self.assertIsNotNone(metadata_accepted)
self.assertEqual(_low.Event.Kind.METADATA_ACCEPTED, metadata_accepted.kind)
self.assertEqual(metadata_tag, metadata_accepted.tag)
- # TODO(nathaniel): Test transmission and reception of metadata.
+ metadata = dict(metadata_accepted.metadata)
+ self.assertIn(server_leading_metadata_key, metadata)
+ self.assertEqual(server_leading_metadata_value,
+ metadata[server_leading_metadata_key])
+ self.assertIn(server_leading_binary_metadata_key, metadata)
+ self.assertEqual(server_leading_binary_metadata_value,
+ metadata[server_leading_binary_metadata_key])
for datum in test_data:
client_call.write(datum, write_tag)
@@ -194,6 +225,11 @@
self.assertEqual(read_tag, read_accepted.tag)
self.assertIsNone(read_accepted.bytes)
+ server_call.add_metadata(server_trailing_metadata_key,
+ server_trailing_metadata_value)
+ server_call.add_metadata(server_trailing_binary_metadata_key,
+ server_trailing_binary_metadata_value)
+
server_call.status(_low.Status(_low.Code.OK, details), status_tag)
server_terminal_event_one = self.server_completion_queue.get(_FUTURE)
server_terminal_event_two = self.server_completion_queue.get(_FUTURE)
@@ -229,6 +265,13 @@
self.assertEqual(_low.Event.Kind.FINISH, finish_accepted.kind)
self.assertEqual(finish_tag, finish_accepted.tag)
self.assertEqual(_low.Status(_low.Code.OK, details), finish_accepted.status)
+ metadata = dict(finish_accepted.metadata)
+ self.assertIn(server_trailing_metadata_key, metadata)
+ self.assertEqual(server_trailing_metadata_value,
+ metadata[server_trailing_metadata_key])
+ self.assertIn(server_trailing_binary_metadata_key, metadata)
+ self.assertEqual(server_trailing_binary_metadata_value,
+ metadata[server_trailing_binary_metadata_key])
server_timeout_none_event = self.server_completion_queue.get(0)
self.assertIsNone(server_timeout_none_event)
diff --git a/src/python/src/grpc/_adapter/_server.h b/src/python/src/grpc/_adapter/_server.h
index 0c517e3..4248712 100644
--- a/src/python/src/grpc/_adapter/_server.h
+++ b/src/python/src/grpc/_adapter/_server.h
@@ -37,7 +37,10 @@
#include <Python.h>
#include <grpc/grpc.h>
-typedef struct { PyObject_HEAD grpc_server *c_server; } Server;
+typedef struct {
+ PyObject_HEAD;
+ grpc_server *c_server;
+} Server;
int pygrpc_add_server(PyObject *module);
diff --git a/src/python/src/grpc/_adapter/_server_credentials.h b/src/python/src/grpc/_adapter/_server_credentials.h
index 2e56efd..bb6ff2c 100644
--- a/src/python/src/grpc/_adapter/_server_credentials.h
+++ b/src/python/src/grpc/_adapter/_server_credentials.h
@@ -38,7 +38,8 @@
#include <grpc/grpc_security.h>
typedef struct {
- PyObject_HEAD grpc_server_credentials *c_server_credentials;
+ PyObject_HEAD;
+ grpc_server_credentials *c_server_credentials;
} ServerCredentials;
PyTypeObject pygrpc_ServerCredentialsType;
diff --git a/src/python/src/grpc/early_adopter/implementations.py b/src/python/src/grpc/early_adopter/implementations.py
index cc0b8ec..7d3d29f 100644
--- a/src/python/src/grpc/early_adopter/implementations.py
+++ b/src/python/src/grpc/early_adopter/implementations.py
@@ -188,22 +188,10 @@
raise AttributeError(attr)
-def _build_stub(
- service_name, methods, host, port, secure, root_certificates, private_key,
- certificate_chain, server_host_override=None):
- breakdown = _face_utilities.break_down_invocation(service_name, methods)
- return _Stub(
- breakdown, host, port, secure, root_certificates, private_key,
- certificate_chain, server_host_override=server_host_override)
-
-
-def _build_server(service_name, methods, port, private_key, certificate_chain):
- breakdown = _face_utilities.break_down_service(service_name, methods)
- return _Server(breakdown, port, private_key, certificate_chain)
-
-
-def insecure_stub(service_name, methods, host, port):
- """Constructs an insecure interfaces.Stub.
+def stub(
+ service_name, methods, host, port, secure=False, root_certificates=None,
+ private_key=None, certificate_chain=None, server_host_override=None):
+ """Constructs an interfaces.Stub.
Args:
service_name: The package-qualified full name of the service.
@@ -213,27 +201,7 @@
not qualified by the service name or decorated in any other way.
host: The host to which to connect for RPC service.
port: The port to which to connect for RPC service.
-
- Returns:
- An interfaces.Stub affording RPC invocation.
- """
- return _build_stub(
- service_name, methods, host, port, False, None, None, None)
-
-
-def secure_stub(
- service_name, methods, host, port, root_certificates, private_key,
- certificate_chain, server_host_override=None):
- """Constructs an insecure interfaces.Stub.
-
- Args:
- service_name: The package-qualified full name of the service.
- methods: A dictionary from RPC method name to
- interfaces.RpcMethodInvocationDescription describing the RPCs to be
- supported by the created stub. The RPC method names in the dictionary are
- not qualified by the service name or decorated in any other way.
- host: The host to which to connect for RPC service.
- port: The port to which to connect for RPC service.
+ secure: Whether or not to construct the stub with a secure connection.
root_certificates: The PEM-encoded root certificates or None to ask for
them to be retrieved from a default location.
private_key: The PEM-encoded private key to use or None if no private key
@@ -246,32 +214,15 @@
Returns:
An interfaces.Stub affording RPC invocation.
"""
- return _build_stub(
- service_name, methods, host, port, True, root_certificates, private_key,
+ breakdown = _face_utilities.break_down_invocation(service_name, methods)
+ return _Stub(
+ breakdown, host, port, secure, root_certificates, private_key,
certificate_chain, server_host_override=server_host_override)
-def insecure_server(service_name, methods, port):
- """Constructs an insecure interfaces.Server.
-
- Args:
- service_name: The package-qualified full name of the service.
- methods: A dictionary from RPC method name to
- interfaces.RpcMethodServiceDescription describing the RPCs to
- be serviced by the created server. The RPC method names in the dictionary
- are not qualified by the service name or decorated in any other way.
- port: The desired port on which to serve or zero to ask for a port to
- be automatically selected.
-
- Returns:
- An interfaces.Server that will run with no security and
- service unsecured raw requests.
- """
- return _build_server(service_name, methods, port, None, None)
-
-
-def secure_server(service_name, methods, port, private_key, certificate_chain):
- """Constructs a secure interfaces.Server.
+def server(
+ service_name, methods, port, private_key=None, certificate_chain=None):
+ """Constructs an interfaces.Server.
Args:
service_name: The package-qualified full name of the service.
@@ -281,11 +232,12 @@
are not qualified by the service name or decorated in any other way.
port: The port on which to serve or zero to ask for a port to be
automatically selected.
- private_key: A pem-encoded private key.
- certificate_chain: A pem-encoded certificate chain.
+ private_key: A pem-encoded private key, or None for an insecure server.
+ certificate_chain: A pem-encoded certificate chain, or None for an insecure
+ server.
Returns:
An interfaces.Server that will serve secure traffic.
"""
- return _build_server(
- service_name, methods, port, private_key, certificate_chain)
+ breakdown = _face_utilities.break_down_service(service_name, methods)
+ return _Server(breakdown, port, private_key, certificate_chain)
diff --git a/src/python/src/grpc/early_adopter/implementations_test.py b/src/python/src/grpc/early_adopter/implementations_test.py
index ae4adad..32b9747 100644
--- a/src/python/src/grpc/early_adopter/implementations_test.py
+++ b/src/python/src/grpc/early_adopter/implementations_test.py
@@ -106,11 +106,11 @@
class EarlyAdopterImplementationsTest(unittest.TestCase):
def setUp(self):
- self.server = implementations.insecure_server(
+ self.server = implementations.server(
SERVICE_NAME, _SERVICE_DESCRIPTIONS, 0)
self.server.start()
port = self.server.port()
- self.stub = implementations.insecure_stub(
+ self.stub = implementations.stub(
SERVICE_NAME, _INVOCATION_DESCRIPTIONS, 'localhost', port)
def tearDown(self):
diff --git a/src/ruby/Rakefile b/src/ruby/Rakefile
index b27305d..afb354e 100755
--- a/src/ruby/Rakefile
+++ b/src/ruby/Rakefile
@@ -2,14 +2,17 @@
require 'rake/extensiontask'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
+require 'bundler/gem_tasks'
-desc 'Run Rubocop to check for style violations'
+# Add rubocop style checking tasks
RuboCop::RakeTask.new
+# Add the extension compiler task
Rake::ExtensionTask.new 'grpc' do |ext|
ext.lib_dir = File.join('lib', 'grpc')
end
+# Define the test suites
SPEC_SUITES = [
{ id: :wrapper, title: 'wrapper layer', files: %w(spec/*.rb) },
{ id: :idiomatic, title: 'idiomatic layer', dir: %w(spec/generic),
@@ -19,36 +22,34 @@
{ id: :server, title: 'rpc server thread tests', dir: %w(spec/generic),
tag: 'server' }
]
+namespace :suite do
+ SPEC_SUITES.each do |suite|
+ desc "Run all specs in the #{suite[:title]} spec suite"
+ RSpec::Core::RakeTask.new(suite[:id]) do |t|
+ spec_files = []
+ suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
-desc 'Run all RSpec tests'
-namespace :spec do
- namespace :suite do
- SPEC_SUITES.each do |suite|
- desc "Run all specs in #{suite[:title]} spec suite"
- RSpec::Core::RakeTask.new(suite[:id]) do |t|
- spec_files = []
- suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
+ if suite[:dir]
+ suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
+ end
+ helper = 'spec/spec_helper.rb'
+ spec_files << helper unless spec_files.include?(helper)
- if suite[:dirs]
- suite[:dirs].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
- end
-
- t.pattern = spec_files
- t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
- if suite[:tags]
- t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
- end
+ t.pattern = spec_files
+ t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
+ if suite[:tags]
+ t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
end
end
end
end
-desc 'Compiles the extension then runs all the tests'
-task :all
+# Define dependencies between the suites.
+task 'suite:wrapper' => [:compile, :rubocop]
+task 'suite:idiomatic' => 'suite:wrapper'
+task 'suite:bidi' => 'suite:wrapper'
+task 'suite:server' => 'suite:wrapper'
+desc 'Compiles the gRPC extension then runs all the tests'
+task all: ['suite:idiomatic', 'suite:bidi', 'suite:server']
task default: :all
-task 'spec:suite:wrapper' => [:compile, :rubocop]
-task 'spec:suite:idiomatic' => 'spec:suite:wrapper'
-task 'spec:suite:bidi' => 'spec:suite:wrapper'
-task 'spec:suite:server' => 'spec:suite:wrapper'
-task all: ['spec:suite:idiomatic', 'spec:suite:bidi', 'spec:suite:server']
diff --git a/src/ruby/spec/generic/client_stub_spec.rb b/src/ruby/spec/generic/client_stub_spec.rb
index 73f2d37..0c98fc4 100644
--- a/src/ruby/spec/generic/client_stub_spec.rb
+++ b/src/ruby/spec/generic/client_stub_spec.rb
@@ -384,13 +384,7 @@
th.join
end
- # disabled because an unresolved wire-protocol implementation feature
- #
- # - servers should be able initiate messaging, however, as it stand
- # servers don't know if all the client metadata has been sent until
- # they receive a message from the client. Without receiving all the
- # metadata, the server does not accept the call, so this test hangs.
- xit 'supports a server-initiated ping pong', bidi: true do
+ it 'supports a server-initiated ping pong', bidi: true do
server_port = create_test_server
host = "localhost:#{server_port}"
th = run_bidi_streamer_echo_ping_pong(@sent_msgs, @pass, false)
diff --git a/templates/BUILD.template b/templates/BUILD.template
new file mode 100644
index 0000000..997c55b
--- /dev/null
+++ b/templates/BUILD.template
@@ -0,0 +1,69 @@
+# GRPC Bazel BUILD file.
+# This currently builds C and C++ code.
+
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+licenses(["notice"]) # 3-clause BSD
+
+% for lib in libs:
+% if lib.build == "all" and lib.language == 'c':
+${makelib(lib)}
+% endif
+% endfor
+
+<%def name="makelib(lib)">
+
+cc_library(
+ name = "${lib.name}",
+ srcs = [
+% for hdr in lib.get("headers", []):
+ "${hdr}",
+% endfor
+% for src in lib.src:
+ "${src}",
+% endfor
+ ],
+ hdrs = [
+% for hdr in lib.get("public_headers", []):
+ "${hdr}",
+% endfor
+ ],
+ includes = [
+ "include",
+ ".",
+ ],
+ deps = [
+% for dep in lib.get("deps", []):
+ ":${dep}",
+% endfor
+ ],
+)
+
+</%def>
diff --git a/test/compiler/python_plugin_test.py b/test/compiler/python_plugin_test.py
index 3d2f117..ad3beba 100644
--- a/test/compiler/python_plugin_test.py
+++ b/test/compiler/python_plugin_test.py
@@ -177,7 +177,7 @@
servicer = Servicer()
server = getattr(
- test_pb2, SERVER_FACTORY_IDENTIFIER)(servicer, 0, None, None)
+ test_pb2, SERVER_FACTORY_IDENTIFIER)(servicer, 0)
with server:
port = server.port()
stub = getattr(test_pb2, STUB_FACTORY_IDENTIFIER)('localhost', port)
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c
index 36f13e1..7467c2f 100644
--- a/test/core/util/port_posix.c
+++ b/test/core/util/port_posix.c
@@ -32,7 +32,8 @@
*/
#include <grpc/support/port_platform.h>
-#ifdef GPR_POSIX_SOCKET
+#include "test/core/util/test_config.h"
+#if defined(GPR_POSIX_SOCKET) && defined(GRPC_TEST_PICK_PORT)
#include "test/core/util/port.h"
@@ -125,7 +126,7 @@
} else {
port = 0;
}
-
+
if (!is_port_available(&port, is_tcp)) {
continue;
}
@@ -155,4 +156,4 @@
return port;
}
-#endif /* GPR_POSIX_SOCKET */
+#endif /* GPR_POSIX_SOCKET && GRPC_TEST_PICK_PORT */
diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h
index 668a069..0b3c543 100644
--- a/test/core/util/test_config.h
+++ b/test/core/util/test_config.h
@@ -59,6 +59,10 @@
gpr_time_add(gpr_now(), \
gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)))
+#ifndef GRPC_TEST_CUSTOM_PICK_PORT
+#define GRPC_TEST_PICK_PORT
+#endif
+
void grpc_test_init(int argc, char **argv);
#ifdef __cplusplus
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 4c71831..9938fcf 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -532,15 +532,19 @@
send_request.set_message("Hello");
std::pair<grpc::string, grpc::string> meta1("key1", "val1");
std::pair<grpc::string, grpc::string> meta2(
- "key2-bin", {"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13});
+ "key2-bin",
+ grpc::string("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc",
+ 13));
std::pair<grpc::string, grpc::string> meta3("key3", "val3");
std::pair<grpc::string, grpc::string> meta6(
"key4-bin",
- {"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", 14});
+ grpc::string("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
+ 14));
std::pair<grpc::string, grpc::string> meta5("key5", "val5");
std::pair<grpc::string, grpc::string> meta4(
"key6-bin",
- {"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15});
+ grpc::string("\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee",
+ 15));
cli_ctx.AddMetadata(meta1.first, meta1.second);
cli_ctx.AddMetadata(meta2.first, meta2.second);
@@ -595,6 +599,5 @@
::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
grpc_shutdown();
- google::protobuf::ShutdownProtobufLibrary();
return result;
}
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 41c2669..0d5db04 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -83,10 +83,30 @@
class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
public:
+ TestServiceImpl() : signal_client_(false) {}
+
Status Echo(ServerContext* context, const EchoRequest* request,
EchoResponse* response) GRPC_OVERRIDE {
response->set_message(request->message());
MaybeEchoDeadline(context, request, response);
+ if (request->has_param() && request->param().client_cancel_after_us()) {
+ {
+ std::unique_lock<std::mutex> lock(mu_);
+ signal_client_ = true;
+ }
+ while (!context->IsCancelled()) {
+ std::this_thread::sleep_for(std::chrono::microseconds(
+ request->param().client_cancel_after_us()));
+ }
+ return Status::Cancelled;
+ } else if (request->has_param() &&
+ request->param().server_cancel_after_us()) {
+ std::this_thread::sleep_for(
+ std::chrono::microseconds(request->param().server_cancel_after_us()));
+ return Status::Cancelled;
+ } else {
+ EXPECT_FALSE(context->IsCancelled());
+ }
return Status::OK;
}
@@ -130,6 +150,15 @@
}
return Status::OK;
}
+
+ bool signal_client() {
+ std::unique_lock<std::mutex> lock(mu_);
+ return signal_client_;
+ }
+
+ private:
+ bool signal_client_;
+ std::mutex mu_;
};
class TestServiceImplDupPkg
@@ -151,7 +180,8 @@
server_address_ << "localhost:" << port;
// Setup server
ServerBuilder builder;
- builder.AddListeningPort(server_address_.str(), InsecureServerCredentials());
+ builder.AddListeningPort(server_address_.str(),
+ InsecureServerCredentials());
builder.RegisterService(&service_);
builder.RegisterService(&dup_pkg_service_);
builder.SetThreadPool(&thread_pool_);
@@ -423,6 +453,44 @@
EXPECT_EQ("Rpc sent on a lame channel.", s.details());
}
+void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) {
+ std::this_thread::sleep_for(std::chrono::microseconds(delay_us));
+ while (!service->signal_client()) {
+ }
+ context->TryCancel();
+}
+
+// Client cancels rpc after 10ms
+TEST_F(End2endTest, ClientCancelsRpc) {
+ ResetStub();
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("Hello");
+ const int kCancelDelayUs = 10 * 1000;
+ request.mutable_param()->set_client_cancel_after_us(kCancelDelayUs);
+
+ ClientContext context;
+ std::thread cancel_thread(CancelRpc, &context, kCancelDelayUs, &service_);
+ Status s = stub_->Echo(&context, request, &response);
+ cancel_thread.join();
+ EXPECT_EQ(StatusCode::CANCELLED, s.code());
+ EXPECT_TRUE(s.details().empty());
+}
+
+// Server cancels rpc after 1ms
+TEST_F(End2endTest, ServerCancelsRpc) {
+ ResetStub();
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("Hello");
+ request.mutable_param()->set_server_cancel_after_us(1000);
+
+ ClientContext context;
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(StatusCode::CANCELLED, s.code());
+ EXPECT_TRUE(s.details().empty());
+}
+
} // namespace testing
} // namespace grpc
@@ -432,6 +500,5 @@
::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
grpc_shutdown();
- google::protobuf::ShutdownProtobufLibrary();
return result;
}
diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc
index 711f1b9..9cdd8c9 100644
--- a/test/cpp/end2end/generic_end2end_test.cc
+++ b/test/cpp/end2end/generic_end2end_test.cc
@@ -47,6 +47,7 @@
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
+#include <grpc++/generic_stub.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
@@ -83,12 +84,21 @@
buffer->Dump(&slices);
grpc::string buf;
buf.reserve(buffer->Length());
- for (const Slice& s : slices) {
- buf.append(reinterpret_cast<const char*>(s.begin()), s.size());
+ for (auto s = slices.begin(); s != slices.end(); s++) {
+ buf.append(reinterpret_cast<const char*>(s->begin()), s->size());
}
return message->ParseFromString(buf);
}
+std::unique_ptr<ByteBuffer> SerializeToByteBuffer(
+ grpc::protobuf::Message* message) {
+ grpc::string buf;
+ message->SerializeToString(&buf);
+ gpr_slice s = gpr_slice_from_copied_string(buf.c_str());
+ Slice slice(s, Slice::STEAL_REF);
+ return std::unique_ptr<ByteBuffer>(new ByteBuffer(&slice, 1));
+}
+
class GenericEnd2endTest : public ::testing::Test {
protected:
GenericEnd2endTest() : generic_service_("*") {}
@@ -118,7 +128,7 @@
void ResetStub() {
std::shared_ptr<ChannelInterface> channel = CreateChannel(
server_address_.str(), InsecureCredentials(), ChannelArguments());
- stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
+ generic_stub_.reset(new GenericStub(channel));
}
void server_ok(int i) { verify_ok(&srv_cq_, i, true); }
@@ -127,6 +137,7 @@
void client_fail(int i) { verify_ok(&cli_cq_, i, false); }
void SendRpc(int num_rpcs) {
+ const grpc::string kMethodName("/grpc.cpp.test.util.TestService/Echo");
for (int i = 0; i < num_rpcs; i++) {
EchoRequest send_request;
EchoRequest recv_request;
@@ -139,35 +150,42 @@
GenericServerAsyncReaderWriter stream(&srv_ctx);
send_request.set_message("Hello");
- std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader(
- stub_->AsyncEcho(&cli_ctx, send_request, &cli_cq_, tag(1)));
+ std::unique_ptr<GenericClientAsyncReaderWriter> call =
+ generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1));
client_ok(1);
+ std::unique_ptr<ByteBuffer> send_buffer =
+ SerializeToByteBuffer(&send_request);
+ call->Write(*send_buffer, tag(2));
+ client_ok(2);
+ call->WritesDone(tag(3));
+ client_ok(3);
- generic_service_.RequestCall(&srv_ctx, &stream, &srv_cq_, tag(2));
+ generic_service_.RequestCall(&srv_ctx, &stream, &srv_cq_, tag(4));
- verify_ok(generic_service_.completion_queue(), 2, true);
+ verify_ok(generic_service_.completion_queue(), 4, true);
EXPECT_EQ(server_address_.str(), srv_ctx.host());
- EXPECT_EQ("/grpc.cpp.test.util.TestService/Echo", srv_ctx.method());
+ EXPECT_EQ(kMethodName, srv_ctx.method());
ByteBuffer recv_buffer;
- stream.Read(&recv_buffer, tag(3));
- server_ok(3);
+ stream.Read(&recv_buffer, tag(5));
+ server_ok(5);
EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_request));
EXPECT_EQ(send_request.message(), recv_request.message());
send_response.set_message(recv_request.message());
- grpc::string buf;
- send_response.SerializeToString(&buf);
- gpr_slice s = gpr_slice_from_copied_string(buf.c_str());
- Slice slice(s, Slice::STEAL_REF);
- ByteBuffer send_buffer(&slice, 1);
- stream.Write(send_buffer, tag(4));
- server_ok(4);
+ send_buffer = SerializeToByteBuffer(&send_response);
+ stream.Write(*send_buffer, tag(6));
+ server_ok(6);
- stream.Finish(Status::OK, tag(5));
- server_ok(5);
+ stream.Finish(Status::OK, tag(7));
+ server_ok(7);
- response_reader->Finish(&recv_response, &recv_status, tag(4));
- client_ok(4);
+ recv_buffer.Clear();
+ call->Read(&recv_buffer, tag(8));
+ client_ok(8);
+ EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_response));
+
+ call->Finish(&recv_status, tag(9));
+ client_ok(9);
EXPECT_EQ(send_response.message(), recv_response.message());
EXPECT_TRUE(recv_status.IsOk());
@@ -177,6 +195,7 @@
CompletionQueue cli_cq_;
CompletionQueue srv_cq_;
std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_;
+ std::unique_ptr<grpc::GenericStub> generic_stub_;
std::unique_ptr<Server> server_;
AsyncGenericService generic_service_;
std::ostringstream server_address_;
@@ -196,6 +215,7 @@
TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
ResetStub();
+ const grpc::string kMethodName("/grpc.cpp.test.util.TestService/BidiStream");
EchoRequest send_request;
EchoRequest recv_request;
EchoResponse send_response;
@@ -206,17 +226,19 @@
GenericServerAsyncReaderWriter srv_stream(&srv_ctx);
send_request.set_message("Hello");
- std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse> >
- cli_stream(stub_->AsyncBidiStream(&cli_ctx, &cli_cq_, tag(1)));
+ std::unique_ptr<GenericClientAsyncReaderWriter> cli_stream =
+ generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1));
client_ok(1);
generic_service_.RequestCall(&srv_ctx, &srv_stream, &srv_cq_, tag(2));
verify_ok(generic_service_.completion_queue(), 2, true);
EXPECT_EQ(server_address_.str(), srv_ctx.host());
- EXPECT_EQ("/grpc.cpp.test.util.TestService/BidiStream", srv_ctx.method());
+ EXPECT_EQ(kMethodName, srv_ctx.method());
- cli_stream->Write(send_request, tag(3));
+ std::unique_ptr<ByteBuffer> send_buffer =
+ SerializeToByteBuffer(&send_request);
+ cli_stream->Write(*send_buffer, tag(3));
client_ok(3);
ByteBuffer recv_buffer;
@@ -226,22 +248,18 @@
EXPECT_EQ(send_request.message(), recv_request.message());
send_response.set_message(recv_request.message());
- grpc::string buf;
- send_response.SerializeToString(&buf);
- gpr_slice s = gpr_slice_from_copied_string(buf.c_str());
- Slice slice(s, Slice::STEAL_REF);
- ByteBuffer send_buffer(&slice, 1);
- srv_stream.Write(send_buffer, tag(5));
+ send_buffer = SerializeToByteBuffer(&send_response);
+ srv_stream.Write(*send_buffer, tag(5));
server_ok(5);
- cli_stream->Read(&recv_response, tag(6));
+ cli_stream->Read(&recv_buffer, tag(6));
client_ok(6);
+ EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_response));
EXPECT_EQ(send_response.message(), recv_response.message());
cli_stream->WritesDone(tag(7));
client_ok(7);
- recv_buffer.Clear();
srv_stream.Read(&recv_buffer, tag(8));
server_fail(8);
@@ -265,6 +283,5 @@
::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
grpc_shutdown();
- google::protobuf::ShutdownProtobufLibrary();
return result;
}
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index eceb600..780a737 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -213,8 +213,11 @@
builder.RegisterService(&service);
std::shared_ptr<ServerCredentials> creds = grpc::InsecureServerCredentials();
if (FLAGS_enable_ssl) {
- SslServerCredentialsOptions ssl_opts = {
- "", {{test_server1_key, test_server1_cert}}};
+ SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key,
+ test_server1_cert};
+ SslServerCredentialsOptions ssl_opts;
+ ssl_opts.pem_root_certs = "";
+ ssl_opts.pem_key_cert_pairs.push_back(pkcp);
creds = grpc::SslServerCredentials(ssl_opts);
}
builder.AddListeningPort(server_address.str(), creds);
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index 221fb30..cae7f44 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -115,12 +115,12 @@
impl_([this, idx, client]() {
for (;;) {
// run the loop body
- client->ThreadFunc(&histogram_, idx);
+ client->ThreadFunc(&histogram_, idx);
// lock, see if we're done
std::lock_guard<std::mutex> g(mu_);
- if (done_) return;
- // also check if we're marking, and swap out the histogram if so
- if (new_) {
+ if (done_) {return;}
+ // check if we're marking, swap out the histogram if so
+ if (new_) {
new_->Swap(&histogram_);
new_ = nullptr;
cv_.notify_one();
@@ -164,8 +164,12 @@
std::unique_ptr<Timer> timer_;
};
-std::unique_ptr<Client> CreateSynchronousClient(const ClientConfig& args);
-std::unique_ptr<Client> CreateAsyncClient(const ClientConfig& args);
+std::unique_ptr<Client>
+ CreateSynchronousUnaryClient(const ClientConfig& args);
+std::unique_ptr<Client>
+ CreateSynchronousStreamingClient(const ClientConfig& args);
+std::unique_ptr<Client> CreateAsyncUnaryClient(const ClientConfig& args);
+std::unique_ptr<Client> CreateAsyncStreamingClient(const ClientConfig& args);
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc
index 526f37a..1ed3c71 100644
--- a/test/cpp/qps/client_async.cc
+++ b/test/cpp/qps/client_async.cc
@@ -46,7 +46,7 @@
#include <grpc++/async_unary_call.h>
#include <grpc++/client_context.h>
#include <grpc++/status.h>
-#include "test/core/util/grpc_profiler.h"
+#include <grpc++/stream.h>
#include "test/cpp/util/create_test_channel.h"
#include "test/cpp/qps/qpstest.pb.h"
#include "test/cpp/qps/timer.h"
@@ -59,13 +59,13 @@
public:
ClientRpcContext() {}
virtual ~ClientRpcContext() {}
- virtual bool RunNextState() = 0; // do next state, return false if steps done
+ // next state, return false if done. Collect stats when appropriate
+ virtual bool RunNextState(bool, Histogram* hist) = 0;
virtual void StartNewClone() = 0;
static void* tag(ClientRpcContext* c) { return reinterpret_cast<void*>(c); }
static ClientRpcContext* detag(void* t) {
return reinterpret_cast<ClientRpcContext*>(t);
}
- virtual void report_stats(Histogram* hist) = 0;
};
template <class RequestType, class ResponseType>
@@ -89,9 +89,12 @@
response_reader_(
start_req(stub_, &context_, req_, ClientRpcContext::tag(this))) {}
~ClientRpcContextUnaryImpl() GRPC_OVERRIDE {}
- bool RunNextState() GRPC_OVERRIDE { return (this->*next_state_)(); }
- void report_stats(Histogram* hist) GRPC_OVERRIDE {
- hist->Add((Timer::Now() - start_) * 1e9);
+ bool RunNextState(bool ok, Histogram* hist) GRPC_OVERRIDE {
+ bool ret = (this->*next_state_)(ok);
+ if (!ret) {
+ hist->Add((Timer::Now() - start_) * 1e9);
+ }
+ return ret;
}
void StartNewClone() GRPC_OVERRIDE {
@@ -99,16 +102,16 @@
}
private:
- bool ReqSent() {
+ bool ReqSent(bool) {
next_state_ = &ClientRpcContextUnaryImpl::RespDone;
response_reader_->Finish(&response_, &status_, ClientRpcContext::tag(this));
return true;
}
- bool RespDone() {
+ bool RespDone(bool) {
next_state_ = &ClientRpcContextUnaryImpl::DoCallBack;
return false;
}
- bool DoCallBack() {
+ bool DoCallBack(bool) {
callback_(status_, &response_);
return false;
}
@@ -116,7 +119,7 @@
TestService::Stub* stub_;
RequestType req_;
ResponseType response_;
- bool (ClientRpcContextUnaryImpl::*next_state_)();
+ bool (ClientRpcContextUnaryImpl::*next_state_)(bool);
std::function<void(grpc::Status, ResponseType*)> callback_;
std::function<std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>(
TestService::Stub*, grpc::ClientContext*, const RequestType&, void*)>
@@ -127,9 +130,9 @@
response_reader_;
};
-class AsyncClient GRPC_FINAL : public Client {
+class AsyncUnaryClient GRPC_FINAL : public Client {
public:
- explicit AsyncClient(const ClientConfig& config) : Client(config) {
+ explicit AsyncUnaryClient(const ClientConfig& config) : Client(config) {
for (int i = 0; i < config.async_client_threads(); i++) {
cli_cqs_.emplace_back(new CompletionQueue);
}
@@ -144,7 +147,8 @@
int t = 0;
for (int i = 0; i < config.outstanding_rpcs_per_channel(); i++) {
- for (auto& channel : channels_) {
+ for (auto channel = channels_.begin(); channel != channels_.end();
+ channel++) {
auto* cq = cli_cqs_[t].get();
t = (t + 1) % cli_cqs_.size();
auto start_req = [cq](TestService::Stub* stub, grpc::ClientContext* ctx,
@@ -152,7 +156,7 @@
return stub->AsyncUnaryCall(ctx, request, cq, tag);
};
- TestService::Stub* stub = channel.get_stub();
+ TestService::Stub* stub = channel->get_stub();
const SimpleRequest& request = request_;
new ClientRpcContextUnaryImpl<SimpleRequest, SimpleResponse>(
stub, request, start_req, check_done);
@@ -162,14 +166,14 @@
StartThreads(config.async_client_threads());
}
- ~AsyncClient() GRPC_OVERRIDE {
+ ~AsyncUnaryClient() GRPC_OVERRIDE {
EndThreads();
- for (auto& cq : cli_cqs_) {
- cq->Shutdown();
+ for (auto cq = cli_cqs_.begin(); cq != cli_cqs_.end(); cq++) {
+ (*cq)->Shutdown();
void* got_tag;
bool ok;
- while (cq->Next(&got_tag, &ok)) {
+ while ((*cq)->Next(&got_tag, &ok)) {
delete ClientRpcContext::detag(got_tag);
}
}
@@ -181,10 +185,9 @@
cli_cqs_[thread_idx]->Next(&got_tag, &ok);
ClientRpcContext* ctx = ClientRpcContext::detag(got_tag);
- if (ctx->RunNextState() == false) {
+ if (ctx->RunNextState(ok, histogram) == false) {
// call the callback and then delete it
- ctx->report_stats(histogram);
- ctx->RunNextState();
+ ctx->RunNextState(ok, histogram);
ctx->StartNewClone();
delete ctx;
}
@@ -193,8 +196,145 @@
std::vector<std::unique_ptr<CompletionQueue>> cli_cqs_;
};
-std::unique_ptr<Client> CreateAsyncClient(const ClientConfig& args) {
- return std::unique_ptr<Client>(new AsyncClient(args));
+template <class RequestType, class ResponseType>
+class ClientRpcContextStreamingImpl : public ClientRpcContext {
+ public:
+ ClientRpcContextStreamingImpl(
+ TestService::Stub *stub, const RequestType &req,
+ std::function<
+ std::unique_ptr<grpc::ClientAsyncReaderWriter<
+ RequestType,ResponseType>>(
+ TestService::Stub *, grpc::ClientContext *, void *)> start_req,
+ std::function<void(grpc::Status, ResponseType *)> on_done)
+ : context_(),
+ stub_(stub),
+ req_(req),
+ response_(),
+ next_state_(&ClientRpcContextStreamingImpl::ReqSent),
+ callback_(on_done),
+ start_req_(start_req),
+ start_(Timer::Now()),
+ stream_(start_req_(stub_, &context_, ClientRpcContext::tag(this))) {}
+ ~ClientRpcContextStreamingImpl() GRPC_OVERRIDE {}
+ bool RunNextState(bool ok, Histogram *hist) GRPC_OVERRIDE {
+ return (this->*next_state_)(ok, hist);
+ }
+ void StartNewClone() GRPC_OVERRIDE {
+ new ClientRpcContextStreamingImpl(stub_, req_, start_req_, callback_);
+ }
+
+ private:
+ bool ReqSent(bool ok, Histogram *) {
+ return StartWrite(ok);
+ }
+ bool StartWrite(bool ok) {
+ if (!ok) {
+ return(false);
+ }
+ start_ = Timer::Now();
+ next_state_ = &ClientRpcContextStreamingImpl::WriteDone;
+ stream_->Write(req_, ClientRpcContext::tag(this));
+ return true;
+ }
+ bool WriteDone(bool ok, Histogram *) {
+ if (!ok) {
+ return(false);
+ }
+ next_state_ = &ClientRpcContextStreamingImpl::ReadDone;
+ stream_->Read(&response_, ClientRpcContext::tag(this));
+ return true;
+ }
+ bool ReadDone(bool ok, Histogram *hist) {
+ hist->Add((Timer::Now() - start_) * 1e9);
+ return StartWrite(ok);
+ }
+ grpc::ClientContext context_;
+ TestService::Stub *stub_;
+ RequestType req_;
+ ResponseType response_;
+ bool (ClientRpcContextStreamingImpl::*next_state_)(bool, Histogram *);
+ std::function<void(grpc::Status, ResponseType *)> callback_;
+ std::function<std::unique_ptr<grpc::ClientAsyncReaderWriter<
+ RequestType,ResponseType>>(
+ TestService::Stub *, grpc::ClientContext *, void *)> start_req_;
+ grpc::Status status_;
+ double start_;
+ std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType,ResponseType>>
+ stream_;
+};
+
+class AsyncStreamingClient GRPC_FINAL : public Client {
+ public:
+ explicit AsyncStreamingClient(const ClientConfig &config) : Client(config) {
+ for (int i = 0; i < config.async_client_threads(); i++) {
+ cli_cqs_.emplace_back(new CompletionQueue);
+ }
+
+ auto payload_size = config.payload_size();
+ auto check_done = [payload_size](grpc::Status s, SimpleResponse *response) {
+ GPR_ASSERT(s.IsOk() && (response->payload().type() ==
+ grpc::testing::PayloadType::COMPRESSABLE) &&
+ (response->payload().body().length() ==
+ static_cast<size_t>(payload_size)));
+ };
+
+ int t = 0;
+ for (int i = 0; i < config.outstanding_rpcs_per_channel(); i++) {
+ for (auto channel = channels_.begin(); channel != channels_.end();
+ channel++) {
+ auto* cq = cli_cqs_[t].get();
+ t = (t + 1) % cli_cqs_.size();
+ auto start_req = [cq](TestService::Stub *stub, grpc::ClientContext *ctx,
+ void *tag) {
+ auto stream = stub->AsyncStreamingCall(ctx, cq, tag);
+ return stream;
+ };
+
+ TestService::Stub *stub = channel->get_stub();
+ const SimpleRequest &request = request_;
+ new ClientRpcContextStreamingImpl<SimpleRequest, SimpleResponse>(
+ stub, request, start_req, check_done);
+ }
+ }
+
+ StartThreads(config.async_client_threads());
+ }
+
+ ~AsyncStreamingClient() GRPC_OVERRIDE {
+ EndThreads();
+
+ for (auto cq = cli_cqs_.begin(); cq != cli_cqs_.end(); cq++) {
+ (*cq)->Shutdown();
+ void *got_tag;
+ bool ok;
+ while ((*cq)->Next(&got_tag, &ok)) {
+ delete ClientRpcContext::detag(got_tag);
+ }
+ }
+ }
+
+ void ThreadFunc(Histogram *histogram, size_t thread_idx) GRPC_OVERRIDE {
+ void *got_tag;
+ bool ok;
+ cli_cqs_[thread_idx]->Next(&got_tag, &ok);
+
+ ClientRpcContext *ctx = ClientRpcContext::detag(got_tag);
+ if (ctx->RunNextState(ok, histogram) == false) {
+ // call the callback and then delete it
+ ctx->RunNextState(ok, histogram);
+ ctx->StartNewClone();
+ delete ctx;
+ }
+ }
+
+ std::vector<std::unique_ptr<CompletionQueue>> cli_cqs_;
+};
+
+std::unique_ptr<Client> CreateAsyncUnaryClient(const ClientConfig& args) {
+ return std::unique_ptr<Client>(new AsyncUnaryClient(args));
+}
+std::unique_ptr<Client> CreateAsyncStreamingClient(const ClientConfig& args) {
+ return std::unique_ptr<Client>(new AsyncStreamingClient(args));
}
} // namespace testing
diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc
index 7bb7231..77da172 100644
--- a/test/cpp/qps/client_sync.cc
+++ b/test/cpp/qps/client_sync.cc
@@ -48,10 +48,11 @@
#include <grpc/support/host_port.h>
#include <gflags/gflags.h>
#include <grpc++/client_context.h>
-#include <grpc++/status.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
-#include "test/core/util/grpc_profiler.h"
+#include <grpc++/status.h>
+#include <grpc++/stream.h>
+#include <gtest/gtest.h>
#include "test/cpp/util/create_test_channel.h"
#include "test/cpp/qps/client.h"
#include "test/cpp/qps/qpstest.pb.h"
@@ -61,18 +62,28 @@
namespace grpc {
namespace testing {
-class SynchronousClient GRPC_FINAL : public Client {
+class SynchronousClient : public Client {
public:
SynchronousClient(const ClientConfig& config) : Client(config) {
- size_t num_threads =
- config.outstanding_rpcs_per_channel() * config.client_channels();
- responses_.resize(num_threads);
- StartThreads(num_threads);
+ num_threads_ =
+ config.outstanding_rpcs_per_channel() * config.client_channels();
+ responses_.resize(num_threads_);
}
- ~SynchronousClient() { EndThreads(); }
+ virtual ~SynchronousClient() { EndThreads(); }
- void ThreadFunc(Histogram* histogram, size_t thread_idx) {
+ protected:
+ size_t num_threads_;
+ std::vector<SimpleResponse> responses_;
+};
+
+class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient {
+ public:
+ SynchronousUnaryClient(const ClientConfig& config):
+ SynchronousClient(config) {StartThreads(num_threads_);}
+ ~SynchronousUnaryClient() {}
+
+ void ThreadFunc(Histogram* histogram, size_t thread_idx) GRPC_OVERRIDE {
auto* stub = channels_[thread_idx % channels_.size()].get_stub();
double start = Timer::Now();
grpc::ClientContext context;
@@ -80,13 +91,45 @@
stub->UnaryCall(&context, request_, &responses_[thread_idx]);
histogram->Add((Timer::Now() - start) * 1e9);
}
-
- private:
- std::vector<SimpleResponse> responses_;
};
-std::unique_ptr<Client> CreateSynchronousClient(const ClientConfig& config) {
- return std::unique_ptr<Client>(new SynchronousClient(config));
+class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
+ public:
+ SynchronousStreamingClient(const ClientConfig& config):
+ SynchronousClient(config) {
+ for (size_t thread_idx=0;thread_idx<num_threads_;thread_idx++){
+ auto* stub = channels_[thread_idx % channels_.size()].get_stub();
+ stream_ = stub->StreamingCall(&context_);
+ }
+ StartThreads(num_threads_);
+ }
+ ~SynchronousStreamingClient() {
+ if (stream_) {
+ SimpleResponse response;
+ stream_->WritesDone();
+ EXPECT_TRUE(stream_->Finish().IsOk());
+ }
+ }
+
+ void ThreadFunc(Histogram* histogram, size_t thread_idx) GRPC_OVERRIDE {
+ double start = Timer::Now();
+ EXPECT_TRUE(stream_->Write(request_));
+ EXPECT_TRUE(stream_->Read(&responses_[thread_idx]));
+ histogram->Add((Timer::Now() - start) * 1e9);
+ }
+ private:
+ grpc::ClientContext context_;
+ std::unique_ptr<grpc::ClientReaderWriter<SimpleRequest,
+ SimpleResponse>> stream_;
+};
+
+std::unique_ptr<Client>
+CreateSynchronousUnaryClient(const ClientConfig& config) {
+ return std::unique_ptr<Client>(new SynchronousUnaryClient(config));
+}
+std::unique_ptr<Client>
+CreateSynchronousStreamingClient(const ClientConfig& config) {
+ return std::unique_ptr<Client>(new SynchronousStreamingClient(config));
}
} // namespace testing
diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc
index d29ca1d..64a5349 100644
--- a/test/cpp/qps/driver.cc
+++ b/test/cpp/qps/driver.cc
@@ -154,19 +154,19 @@
server_mark.mutable_mark();
ClientArgs client_mark;
client_mark.mutable_mark();
- for (auto& server : servers) {
- GPR_ASSERT(server.stream->Write(server_mark));
+ for (auto server = servers.begin(); server != servers.end(); server++) {
+ GPR_ASSERT(server->stream->Write(server_mark));
}
- for (auto& client : clients) {
- GPR_ASSERT(client.stream->Write(client_mark));
+ for (auto client = clients.begin(); client != clients.end(); client++) {
+ GPR_ASSERT(client->stream->Write(client_mark));
}
ServerStatus server_status;
ClientStatus client_status;
- for (auto& server : servers) {
- GPR_ASSERT(server.stream->Read(&server_status));
+ for (auto server = servers.begin(); server != servers.end(); server++) {
+ GPR_ASSERT(server->stream->Read(&server_status));
}
- for (auto& client : clients) {
- GPR_ASSERT(client.stream->Read(&client_status));
+ for (auto client = clients.begin(); client != clients.end(); client++) {
+ GPR_ASSERT(client->stream->Read(&client_status));
}
// Wait some time
@@ -176,33 +176,33 @@
// Finish a run
ScenarioResult result;
gpr_log(GPR_INFO, "Finishing");
- for (auto& server : servers) {
- GPR_ASSERT(server.stream->Write(server_mark));
+ for (auto server = servers.begin(); server != servers.end(); server++) {
+ GPR_ASSERT(server->stream->Write(server_mark));
}
- for (auto& client : clients) {
- GPR_ASSERT(client.stream->Write(client_mark));
+ for (auto client = clients.begin(); client != clients.end(); client++) {
+ GPR_ASSERT(client->stream->Write(client_mark));
}
- for (auto& server : servers) {
- GPR_ASSERT(server.stream->Read(&server_status));
+ for (auto server = servers.begin(); server != servers.end(); server++) {
+ GPR_ASSERT(server->stream->Read(&server_status));
const auto& stats = server_status.stats();
result.server_resources.push_back(ResourceUsage{
stats.time_elapsed(), stats.time_user(), stats.time_system()});
}
- for (auto& client : clients) {
- GPR_ASSERT(client.stream->Read(&client_status));
+ for (auto client = clients.begin(); client != clients.end(); client++) {
+ GPR_ASSERT(client->stream->Read(&client_status));
const auto& stats = client_status.stats();
result.latencies.MergeProto(stats.latencies());
result.client_resources.push_back(ResourceUsage{
stats.time_elapsed(), stats.time_user(), stats.time_system()});
}
- for (auto& client : clients) {
- GPR_ASSERT(client.stream->WritesDone());
- GPR_ASSERT(client.stream->Finish().IsOk());
+ for (auto client = clients.begin(); client != clients.end(); client++) {
+ GPR_ASSERT(client->stream->WritesDone());
+ GPR_ASSERT(client->stream->Finish().IsOk());
}
- for (auto& server : servers) {
- GPR_ASSERT(server.stream->WritesDone());
- GPR_ASSERT(server.stream->Finish().IsOk());
+ for (auto server = servers.begin(); server != servers.end(); server++) {
+ GPR_ASSERT(server->stream->WritesDone());
+ GPR_ASSERT(server->stream->Finish().IsOk());
}
return result;
}
diff --git a/test/cpp/qps/qps-sweep.sh b/test/cpp/qps/qps-sweep.sh
new file mode 100755
index 0000000..7bc6ead
--- /dev/null
+++ b/test/cpp/qps/qps-sweep.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+if [ x"$QPS_WORKERS" == x ]; then
+ echo Error: Must set QPS_WORKERS variable in form \
+ "host:port,host:port,..." 1>&2
+ exit 1
+fi
+
+bins=`find . .. ../.. ../../.. -name bins | head -1`
+
+for channels in 1 2 4 8
+do
+ for client in SYNCHRONOUS_CLIENT ASYNC_CLIENT
+ do
+ for server in SYNCHRONOUS_SERVER ASYNC_SERVER
+ do
+ for rpc in UNARY STREAMING
+ do
+ echo "Test $rpc $client $server , $channels channels"
+ "$bins"/opt/qps_driver --rpc_type=$rpc \
+ --client_type=$client --server_type=$server
+ done
+ done
+ done
+done
diff --git a/test/cpp/qps/qps_driver.cc b/test/cpp/qps/qps_driver.cc
index 5e9a577..f7aa8e2 100644
--- a/test/cpp/qps/qps_driver.cc
+++ b/test/cpp/qps/qps_driver.cc
@@ -42,6 +42,7 @@
// Common config
DEFINE_bool(enable_ssl, false, "Use SSL");
+DEFINE_string(rpc_type, "UNARY", "Type of RPC: UNARY or STREAMING");
// Server config
DEFINE_int32(server_threads, 1, "Number of server threads");
@@ -59,6 +60,7 @@
using grpc::testing::ServerConfig;
using grpc::testing::ClientType;
using grpc::testing::ServerType;
+using grpc::testing::RpcType;
using grpc::testing::ResourceUsage;
using grpc::testing::sum;
@@ -73,6 +75,9 @@
grpc_init();
ParseCommandLineFlags(&argc, &argv, true);
+ RpcType rpc_type;
+ GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type));
+
ClientType client_type;
ServerType server_type;
GPR_ASSERT(ClientType_Parse(FLAGS_client_type, &client_type));
@@ -86,6 +91,7 @@
client_config.set_client_channels(FLAGS_client_channels);
client_config.set_payload_size(FLAGS_payload_size);
client_config.set_async_client_threads(FLAGS_async_client_threads);
+ client_config.set_rpc_type(rpc_type);
ServerConfig server_config;
server_config.set_server_type(server_type);
diff --git a/test/cpp/qps/qpstest.proto b/test/cpp/qps/qpstest.proto
index 6a7170b..1553ef5 100644
--- a/test/cpp/qps/qpstest.proto
+++ b/test/cpp/qps/qpstest.proto
@@ -87,15 +87,21 @@
ASYNC_SERVER = 2;
}
+enum RpcType {
+ UNARY = 1;
+ STREAMING = 2;
+}
+
message ClientConfig {
repeated string server_targets = 1;
required ClientType client_type = 2;
- required bool enable_ssl = 3;
+ optional bool enable_ssl = 3 [default=false];
required int32 outstanding_rpcs_per_channel = 4;
required int32 client_channels = 5;
required int32 payload_size = 6;
// only for async client:
optional int32 async_client_threads = 7;
+ optional RpcType rpc_type = 8 [default=UNARY];
}
// Request current stats
@@ -121,8 +127,8 @@
message ServerConfig {
required ServerType server_type = 1;
- required int32 threads = 2;
- required bool enable_ssl = 3;
+ optional int32 threads = 2 [default=1];
+ optional bool enable_ssl = 3 [default=false];
}
message ServerArgs {
@@ -144,7 +150,7 @@
// Desired payload size in the response from the server.
// If response_type is COMPRESSABLE, this denotes the size before compression.
- optional int32 response_size = 2;
+ optional int32 response_size = 2 [default=0];
// Optional input payload sent along with the request.
optional Payload payload = 3;
@@ -154,72 +160,14 @@
optional Payload payload = 1;
}
-message StreamingInputCallRequest {
- // Optional input payload sent along with the request.
- optional Payload payload = 1;
-
- // Not expecting any payload from the response.
-}
-
-message StreamingInputCallResponse {
- // Aggregated size of payloads received from the client.
- optional int32 aggregated_payload_size = 1;
-}
-
-message ResponseParameters {
- // Desired payload sizes in responses from the server.
- // If response_type is COMPRESSABLE, this denotes the size before compression.
- required int32 size = 1;
-
- // Desired interval between consecutive responses in the response stream in
- // microseconds.
- required int32 interval_us = 2;
-}
-
-message StreamingOutputCallRequest {
- // Desired payload type in the response from the server.
- // If response_type is RANDOM, the payload from each response in the stream
- // might be of different types. This is to simulate a mixed type of payload
- // stream.
- optional PayloadType response_type = 1 [default=COMPRESSABLE];
-
- repeated ResponseParameters response_parameters = 2;
-
- // Optional input payload sent along with the request.
- optional Payload payload = 3;
-}
-
-message StreamingOutputCallResponse {
- optional Payload payload = 1;
-}
-
service TestService {
// One request followed by one response.
// The server returns the client payload as-is.
rpc UnaryCall(SimpleRequest) returns (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)
- returns (stream StreamingOutputCallResponse);
-
- // A sequence of requests followed by one response (streamed upload).
- // The server returns the aggregated size of client payload as the result.
- rpc StreamingInputCall(stream StreamingInputCallRequest)
- returns (StreamingInputCallResponse);
-
- // A sequence of requests with each request served by the server immediately.
- // As one request could lead to multiple responses, this interface
- // demonstrates the idea of full duplexing.
- rpc FullDuplexCall(stream StreamingOutputCallRequest)
- returns (stream StreamingOutputCallResponse);
-
- // A sequence of requests followed by a sequence of responses.
- // The server buffers all the client requests and then serves them in order. A
- // stream of responses are returned to the client when the server starts with
- // first request.
- rpc HalfDuplexCall(stream StreamingOutputCallRequest)
- returns (stream StreamingOutputCallResponse);
+ // One request followed by one response.
+ // The server returns the client payload as-is.
+ rpc StreamingCall(stream SimpleRequest) returns (stream SimpleResponse);
}
service Worker {
diff --git a/test/cpp/qps/server.cc b/test/cpp/qps/server.cc
deleted file mode 100644
index e1907b0..0000000
--- a/test/cpp/qps/server.cc
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/signal.h>
-#include <thread>
-
-#include <unistd.h>
-
-#include <gflags/gflags.h>
-#include <grpc/support/alloc.h>
-#include <grpc/support/host_port.h>
-#include <grpc++/config.h>
-#include <grpc++/server.h>
-#include <grpc++/server_builder.h>
-#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
-#include <grpc++/status.h>
-#include "src/cpp/server/thread_pool.h"
-#include "test/core/util/grpc_profiler.h"
-#include "test/cpp/qps/qpstest.pb.h"
-
-#include <grpc/grpc.h>
-#include <grpc/support/log.h>
-
-DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls.");
-DEFINE_int32(port, 0, "Server port.");
-DEFINE_int32(server_threads, 4, "Number of server threads.");
-
-using grpc::Server;
-using grpc::ServerBuilder;
-using grpc::ServerContext;
-using grpc::ThreadPool;
-using grpc::testing::Payload;
-using grpc::testing::PayloadType;
-using grpc::testing::ServerStats;
-using grpc::testing::SimpleRequest;
-using grpc::testing::SimpleResponse;
-using grpc::testing::StatsRequest;
-using grpc::testing::TestService;
-using grpc::Status;
-
-// In some distros, gflags is in the namespace google, and in some others,
-// in gflags. This hack is enabling us to find both.
-namespace google {}
-namespace gflags {}
-using namespace google;
-using namespace gflags;
-
-static bool got_sigint = false;
-
-static void sigint_handler(int x) { got_sigint = 1; }
-
-static double time_double(struct timeval* tv) {
- return tv->tv_sec + 1e-6 * tv->tv_usec;
-}
-
-static bool SetPayload(PayloadType type, int size, Payload* payload) {
- PayloadType response_type = type;
- // TODO(yangg): Support UNCOMPRESSABLE payload.
- if (type != PayloadType::COMPRESSABLE) {
- return false;
- }
- payload->set_type(response_type);
- std::unique_ptr<char[]> body(new char[size]());
- payload->set_body(body.get(), size);
- return true;
-}
-
-namespace {
-
-class TestServiceImpl GRPC_FINAL : public TestService::Service {
- public:
- Status CollectServerStats(ServerContext* context, const StatsRequest*,
- ServerStats* response) {
- struct rusage usage;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- getrusage(RUSAGE_SELF, &usage);
- response->set_time_now(time_double(&tv));
- response->set_time_user(time_double(&usage.ru_utime));
- response->set_time_system(time_double(&usage.ru_stime));
- return Status::OK;
- }
- Status UnaryCall(ServerContext* context, const SimpleRequest* request,
- SimpleResponse* response) {
- if (request->has_response_size() && request->response_size() > 0) {
- if (!SetPayload(request->response_type(), request->response_size(),
- response->mutable_payload())) {
- return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
- }
- }
- return Status::OK;
- }
-};
-
-} // namespace
-
-static void RunServer() {
- char* server_address = NULL;
- gpr_join_host_port(&server_address, "::", FLAGS_port);
-
- TestServiceImpl service;
-
- SimpleRequest request;
- SimpleResponse response;
-
- ServerBuilder builder;
- builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
- builder.RegisterService(&service);
-
- std::unique_ptr<ThreadPool> pool(new ThreadPool(FLAGS_server_threads));
- builder.SetThreadPool(pool.get());
-
- std::unique_ptr<Server> server(builder.BuildAndStart());
- gpr_log(GPR_INFO, "Server listening on %s\n", server_address);
-
- grpc_profiler_start("qps_server.prof");
-
- while (!got_sigint) {
- sleep(5);
- }
-
- grpc_profiler_stop();
-
- gpr_free(server_address);
-}
-
-int main(int argc, char** argv) {
- grpc_init();
- ParseCommandLineFlags(&argc, &argv, true);
-
- signal(SIGINT, sigint_handler);
-
- GPR_ASSERT(FLAGS_port != 0);
- GPR_ASSERT(!FLAGS_enable_ssl);
- RunServer();
-
- grpc_shutdown();
- return 0;
-}
diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc
index 586b6e7..65c170a 100644
--- a/test/cpp/qps/server_async.cc
+++ b/test/cpp/qps/server_async.cc
@@ -33,6 +33,7 @@
#include <forward_list>
#include <functional>
+#include <mutex>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/signal.h>
@@ -48,9 +49,9 @@
#include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
+#include <grpc++/stream.h>
#include <gtest/gtest.h>
#include "src/cpp/server/thread_pool.h"
-#include "test/core/util/grpc_profiler.h"
#include "test/cpp/qps/qpstest.pb.h"
#include "test/cpp/qps/server.h"
@@ -63,7 +64,8 @@
class AsyncQpsServerTest : public Server {
public:
AsyncQpsServerTest(const ServerConfig& config, int port)
- : srv_cq_(), async_service_(&srv_cq_), server_(nullptr) {
+ : srv_cq_(), async_service_(&srv_cq_), server_(nullptr),
+ shutdown_(false) {
char* server_address = NULL;
gpr_join_host_port(&server_address, "::", port);
@@ -78,10 +80,16 @@
using namespace std::placeholders;
request_unary_ = std::bind(&TestService::AsyncService::RequestUnaryCall,
&async_service_, _1, _2, _3, &srv_cq_, _4);
+ request_streaming_ =
+ std::bind(&TestService::AsyncService::RequestStreamingCall,
+ &async_service_, _1, _2, &srv_cq_, _3);
for (int i = 0; i < 100; i++) {
contexts_.push_front(
new ServerRpcContextUnaryImpl<SimpleRequest, SimpleResponse>(
- request_unary_, UnaryCall));
+ request_unary_, ProcessRPC));
+ contexts_.push_front(
+ new ServerRpcContextStreamingImpl<SimpleRequest, SimpleResponse>(
+ request_streaming_, ProcessRPC));
}
for (int i = 0; i < config.threads(); i++) {
threads_.push_back(std::thread([=]() {
@@ -89,14 +97,15 @@
bool ok;
void* got_tag;
while (srv_cq_.Next(&got_tag, &ok)) {
- if (ok) {
- ServerRpcContext* ctx = detag(got_tag);
- // The tag is a pointer to an RPC context to invoke
- if (ctx->RunNextState() == false) {
- // this RPC context is done, so refresh it
+ ServerRpcContext* ctx = detag(got_tag);
+ // The tag is a pointer to an RPC context to invoke
+ if (ctx->RunNextState(ok) == false) {
+ // this RPC context is done, so refresh it
+ std::lock_guard<std::mutex> g(shutdown_mutex_);
+ if (!shutdown_) {
ctx->Reset();
}
- }
+ }
}
return;
}));
@@ -104,9 +113,13 @@
}
~AsyncQpsServerTest() {
server_->Shutdown();
- srv_cq_.Shutdown();
- for (auto& thr : threads_) {
- thr.join();
+ {
+ std::lock_guard<std::mutex> g(shutdown_mutex_);
+ shutdown_ = true;
+ srv_cq_.Shutdown();
+ }
+ for (auto thr = threads_.begin(); thr != threads_.end(); thr++) {
+ thr->join();
}
while (!contexts_.empty()) {
delete contexts_.front();
@@ -119,7 +132,7 @@
public:
ServerRpcContext() {}
virtual ~ServerRpcContext(){};
- virtual bool RunNextState() = 0; // do next state, return false if all done
+ virtual bool RunNextState(bool) = 0; // next state, return false if done
virtual void Reset() = 0; // start this back at a clean state
};
static void* tag(ServerRpcContext* func) {
@@ -130,7 +143,7 @@
}
template <class RequestType, class ResponseType>
- class ServerRpcContextUnaryImpl : public ServerRpcContext {
+ class ServerRpcContextUnaryImpl GRPC_FINAL : public ServerRpcContext {
public:
ServerRpcContextUnaryImpl(
std::function<void(ServerContext*, RequestType*,
@@ -146,7 +159,7 @@
AsyncQpsServerTest::tag(this));
}
~ServerRpcContextUnaryImpl() GRPC_OVERRIDE {}
- bool RunNextState() GRPC_OVERRIDE { return (this->*next_state_)(); }
+ bool RunNextState(bool ok) GRPC_OVERRIDE {return (this->*next_state_)(ok);}
void Reset() GRPC_OVERRIDE {
srv_ctx_ = ServerContext();
req_ = RequestType();
@@ -160,8 +173,11 @@
}
private:
- bool finisher() { return false; }
- bool invoker() {
+ bool finisher(bool) { return false; }
+ bool invoker(bool ok) {
+ if (!ok)
+ return false;
+
ResponseType response;
// Call the RPC processing function
@@ -174,7 +190,7 @@
}
ServerContext srv_ctx_;
RequestType req_;
- bool (ServerRpcContextUnaryImpl::*next_state_)();
+ bool (ServerRpcContextUnaryImpl::*next_state_)(bool);
std::function<void(ServerContext*, RequestType*,
grpc::ServerAsyncResponseWriter<ResponseType>*, void*)>
request_method_;
@@ -183,9 +199,88 @@
grpc::ServerAsyncResponseWriter<ResponseType> response_writer_;
};
- static Status UnaryCall(const SimpleRequest* request,
- SimpleResponse* response) {
- if (request->has_response_size() && request->response_size() > 0) {
+ template <class RequestType, class ResponseType>
+ class ServerRpcContextStreamingImpl GRPC_FINAL : public ServerRpcContext {
+ public:
+ ServerRpcContextStreamingImpl(
+ std::function<void(ServerContext *,
+ grpc::ServerAsyncReaderWriter<ResponseType,
+ RequestType> *, void *)> request_method,
+ std::function<grpc::Status(const RequestType *, ResponseType *)>
+ invoke_method)
+ : next_state_(&ServerRpcContextStreamingImpl::request_done),
+ request_method_(request_method),
+ invoke_method_(invoke_method),
+ stream_(&srv_ctx_) {
+ request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this));
+ }
+ ~ServerRpcContextStreamingImpl() GRPC_OVERRIDE {
+ }
+ bool RunNextState(bool ok) GRPC_OVERRIDE {return (this->*next_state_)(ok);}
+ void Reset() GRPC_OVERRIDE {
+ srv_ctx_ = ServerContext();
+ req_ = RequestType();
+ stream_ = grpc::ServerAsyncReaderWriter<ResponseType,
+ RequestType>(&srv_ctx_);
+
+ // Then request the method
+ next_state_ = &ServerRpcContextStreamingImpl::request_done;
+ request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this));
+ }
+
+ private:
+ bool request_done(bool ok) {
+ if (!ok)
+ return false;
+ stream_.Read(&req_, AsyncQpsServerTest::tag(this));
+ next_state_ = &ServerRpcContextStreamingImpl::read_done;
+ return true;
+ }
+
+ bool read_done(bool ok) {
+ if (ok) {
+ // invoke the method
+ ResponseType response;
+ // Call the RPC processing function
+ grpc::Status status = invoke_method_(&req_, &response);
+ // initiate the write
+ stream_.Write(response, AsyncQpsServerTest::tag(this));
+ next_state_ = &ServerRpcContextStreamingImpl::write_done;
+ } else { // client has sent writes done
+ // finish the stream
+ stream_.Finish(Status::OK, AsyncQpsServerTest::tag(this));
+ next_state_ = &ServerRpcContextStreamingImpl::finish_done;
+ }
+ return true;
+ }
+ bool write_done(bool ok) {
+ // now go back and get another streaming read!
+ if (ok) {
+ stream_.Read(&req_, AsyncQpsServerTest::tag(this));
+ next_state_ = &ServerRpcContextStreamingImpl::read_done;
+ }
+ else {
+ stream_.Finish(Status::OK, AsyncQpsServerTest::tag(this));
+ next_state_ = &ServerRpcContextStreamingImpl::finish_done;
+ }
+ return true;
+ }
+ bool finish_done(bool ok) {return false; /* reset the context */ }
+
+ ServerContext srv_ctx_;
+ RequestType req_;
+ bool (ServerRpcContextStreamingImpl::*next_state_)(bool);
+ std::function<void(ServerContext *,
+ grpc::ServerAsyncReaderWriter<ResponseType,
+ RequestType> *, void *)> request_method_;
+ std::function<grpc::Status(const RequestType *, ResponseType *)>
+ invoke_method_;
+ grpc::ServerAsyncReaderWriter<ResponseType,RequestType> stream_;
+ };
+
+ static Status ProcessRPC(const SimpleRequest* request,
+ SimpleResponse* response) {
+ if (request->response_size() > 0) {
if (!SetPayload(request->response_type(), request->response_size(),
response->mutable_payload())) {
return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
@@ -200,7 +295,13 @@
std::function<void(ServerContext*, SimpleRequest*,
grpc::ServerAsyncResponseWriter<SimpleResponse>*, void*)>
request_unary_;
+ std::function<void(ServerContext*, grpc::ServerAsyncReaderWriter<
+ SimpleResponse,SimpleRequest>*, void*)>
+ request_streaming_;
std::forward_list<ServerRpcContext*> contexts_;
+
+ std::mutex shutdown_mutex_;
+ bool shutdown_;
};
std::unique_ptr<Server> CreateAsyncServer(const ServerConfig& config,
diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc
index 3e15fb6..9964429 100644
--- a/test/cpp/qps/server_sync.cc
+++ b/test/cpp/qps/server_sync.cc
@@ -47,7 +47,6 @@
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "src/cpp/server/thread_pool.h"
-#include "test/core/util/grpc_profiler.h"
#include "test/cpp/qps/qpstest.pb.h"
#include "test/cpp/qps/server.h"
#include "test/cpp/qps/timer.h"
@@ -62,7 +61,7 @@
public:
Status UnaryCall(ServerContext* context, const SimpleRequest* request,
SimpleResponse* response) GRPC_OVERRIDE {
- if (request->has_response_size() && request->response_size() > 0) {
+ if (request->response_size() > 0) {
if (!Server::SetPayload(request->response_type(),
request->response_size(),
response->mutable_payload())) {
@@ -71,6 +70,23 @@
}
return Status::OK;
}
+ Status StreamingCall(ServerContext *context,
+ ServerReaderWriter<SimpleResponse, SimpleRequest>*
+ stream) GRPC_OVERRIDE {
+ SimpleRequest request;
+ while (stream->Read(&request)) {
+ SimpleResponse response;
+ if (request.response_size() > 0) {
+ if (!Server::SetPayload(request.response_type(),
+ request.response_size(),
+ response.mutable_payload())) {
+ return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
+ }
+ }
+ stream->Write(response);
+ }
+ return Status::OK;
+ }
};
class SynchronousServer GRPC_FINAL : public grpc::testing::Server {
diff --git a/test/cpp/qps/stats.h b/test/cpp/qps/stats.h
index ca59390..82dc03e 100644
--- a/test/cpp/qps/stats.h
+++ b/test/cpp/qps/stats.h
@@ -43,8 +43,8 @@
template <class T, class F>
double sum(const T& container, F functor) {
double r = 0;
- for (auto v : container) {
- r += functor(v);
+ for (auto v = container.begin(); v != container.end(); v++) {
+ r += functor(*v);
}
return r;
}
diff --git a/test/cpp/qps/timer.cc b/test/cpp/qps/timer.cc
index 3c13420..d1b6bc1 100644
--- a/test/cpp/qps/timer.cc
+++ b/test/cpp/qps/timer.cc
@@ -36,6 +36,7 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <grpc/support/time.h>
+#include <grpc++/config.h>
Timer::Timer() : start_(Sample()) {}
diff --git a/test/cpp/qps/worker.cc b/test/cpp/qps/worker.cc
index fdcd9d5..378151c 100644
--- a/test/cpp/qps/worker.cc
+++ b/test/cpp/qps/worker.cc
@@ -77,9 +77,12 @@
std::unique_ptr<Client> CreateClient(const ClientConfig& config) {
switch (config.client_type()) {
case ClientType::SYNCHRONOUS_CLIENT:
- return CreateSynchronousClient(config);
+ return (config.rpc_type() == RpcType::UNARY) ?
+ CreateSynchronousUnaryClient(config) :
+ CreateSynchronousStreamingClient(config);
case ClientType::ASYNC_CLIENT:
- return CreateAsyncClient(config);
+ return (config.rpc_type() == RpcType::UNARY) ?
+ CreateAsyncUnaryClient(config) : CreateAsyncStreamingClient(config);
}
abort();
}
@@ -106,30 +109,10 @@
return Status(RESOURCE_EXHAUSTED);
}
- ClientArgs args;
- if (!stream->Read(&args)) {
- return Status(INVALID_ARGUMENT);
- }
- if (!args.has_setup()) {
- return Status(INVALID_ARGUMENT);
- }
- auto client = CreateClient(args.setup());
- if (!client) {
- return Status(INVALID_ARGUMENT);
- }
- ClientStatus status;
- if (!stream->Write(status)) {
- return Status(UNKNOWN);
- }
- while (stream->Read(&args)) {
- if (!args.has_mark()) {
- return Status(INVALID_ARGUMENT);
- }
- *status.mutable_stats() = client->Mark();
- stream->Write(status);
- }
-
- return Status::OK;
+ grpc_profiler_start("qps_client.prof");
+ Status ret = RunTestBody(ctx,stream);
+ grpc_profiler_stop();
+ return ret;
}
Status RunServer(ServerContext* ctx,
@@ -140,31 +123,10 @@
return Status(RESOURCE_EXHAUSTED);
}
- ServerArgs args;
- if (!stream->Read(&args)) {
- return Status(INVALID_ARGUMENT);
- }
- if (!args.has_setup()) {
- return Status(INVALID_ARGUMENT);
- }
- auto server = CreateServer(args.setup());
- if (!server) {
- return Status(INVALID_ARGUMENT);
- }
- ServerStatus status;
- status.set_port(FLAGS_server_port);
- if (!stream->Write(status)) {
- return Status(UNKNOWN);
- }
- while (stream->Read(&args)) {
- if (!args.has_mark()) {
- return Status(INVALID_ARGUMENT);
- }
- *status.mutable_stats() = server->Mark();
- stream->Write(status);
- }
-
- return Status::OK;
+ grpc_profiler_start("qps_server.prof");
+ Status ret = RunServerBody(ctx,stream);
+ grpc_profiler_stop();
+ return ret;
}
private:
@@ -199,6 +161,63 @@
acquired_ = false;
}
+ Status RunTestBody(ServerContext* ctx,
+ ServerReaderWriter<ClientStatus, ClientArgs>* stream) {
+ ClientArgs args;
+ if (!stream->Read(&args)) {
+ return Status(INVALID_ARGUMENT);
+ }
+ if (!args.has_setup()) {
+ return Status(INVALID_ARGUMENT);
+ }
+ auto client = CreateClient(args.setup());
+ if (!client) {
+ return Status(INVALID_ARGUMENT);
+ }
+ ClientStatus status;
+ if (!stream->Write(status)) {
+ return Status(UNKNOWN);
+ }
+ while (stream->Read(&args)) {
+ if (!args.has_mark()) {
+ return Status(INVALID_ARGUMENT);
+ }
+ *status.mutable_stats() = client->Mark();
+ stream->Write(status);
+ }
+
+ return Status::OK;
+ }
+
+ Status RunServerBody(ServerContext* ctx,
+ ServerReaderWriter<ServerStatus, ServerArgs>* stream) {
+ ServerArgs args;
+ if (!stream->Read(&args)) {
+ return Status(INVALID_ARGUMENT);
+ }
+ if (!args.has_setup()) {
+ return Status(INVALID_ARGUMENT);
+ }
+ auto server = CreateServer(args.setup());
+ if (!server) {
+ return Status(INVALID_ARGUMENT);
+ }
+ ServerStatus status;
+ status.set_port(FLAGS_server_port);
+ if (!stream->Write(status)) {
+ return Status(UNKNOWN);
+ }
+ while (stream->Read(&args)) {
+ if (!args.has_mark()) {
+ return Status(INVALID_ARGUMENT);
+ }
+ *status.mutable_stats() = server->Mark();
+ stream->Write(status);
+ }
+
+ return Status::OK;
+ }
+
std::mutex mu_;
bool acquired_;
};
diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc
new file mode 100644
index 0000000..eb67b8d
--- /dev/null
+++ b/test/cpp/util/cli_call.cc
@@ -0,0 +1,106 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/cpp/util/cli_call.h"
+
+#include <iostream>
+
+#include <grpc++/byte_buffer.h>
+#include <grpc++/channel_interface.h>
+#include <grpc++/client_context.h>
+#include <grpc++/generic_stub.h>
+#include <grpc++/status.h>
+#include <grpc++/stream.h>
+
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/slice.h>
+
+namespace grpc {
+namespace testing {
+namespace {
+void* tag(int i) { return (void*)(gpr_intptr) i; }
+} // namespace
+
+void CliCall::Call(std::shared_ptr<grpc::ChannelInterface> channel,
+ const grpc::string& method, const grpc::string& request,
+ grpc::string* response) {
+ std::unique_ptr<grpc::GenericStub> stub(new grpc::GenericStub(channel));
+ grpc::ClientContext ctx;
+ grpc::CompletionQueue cq;
+ std::unique_ptr<grpc::GenericClientAsyncReaderWriter> call(
+ stub->Call(&ctx, method, &cq, tag(1)));
+ void* got_tag;
+ bool ok;
+ cq.Next(&got_tag, &ok);
+ GPR_ASSERT(ok);
+
+ gpr_slice s = gpr_slice_from_copied_string(request.c_str());
+ grpc::Slice req_slice(s, grpc::Slice::STEAL_REF);
+ grpc::ByteBuffer send_buffer(&req_slice, 1);
+ call->Write(send_buffer, tag(2));
+ cq.Next(&got_tag, &ok);
+ GPR_ASSERT(ok);
+ call->WritesDone(tag(3));
+ cq.Next(&got_tag, &ok);
+ GPR_ASSERT(ok);
+ grpc::ByteBuffer recv_buffer;
+ call->Read(&recv_buffer, tag(4));
+ cq.Next(&got_tag, &ok);
+ if (!ok) {
+ std::cout << "Failed to read response." << std::endl;
+ return;
+ }
+ grpc::Status status;
+ call->Finish(&status, tag(5));
+ cq.Next(&got_tag, &ok);
+ GPR_ASSERT(ok);
+
+ if (status.IsOk()) {
+ std::cout << "RPC finished with OK status." << std::endl;
+ std::vector<grpc::Slice> slices;
+ recv_buffer.Dump(&slices);
+
+ response->clear();
+ for (size_t i = 0; i < slices.size(); i++) {
+ response->append(reinterpret_cast<const char*>(slices[i].begin()),
+ slices[i].size());
+ }
+ } else {
+ std::cout << "RPC finished with status code " << status.code()
+ << " details: " << status.details() << std::endl;
+ }
+}
+
+} // namespace testing
+} // namespace grpc
diff --git a/src/php/tests/unit_tests/CompletionQueueTest.php b/test/cpp/util/cli_call.h
old mode 100755
new mode 100644
similarity index 75%
rename from src/php/tests/unit_tests/CompletionQueueTest.php
rename to test/cpp/util/cli_call.h
index 76ee61d..7be8bb6
--- a/src/php/tests/unit_tests/CompletionQueueTest.php
+++ b/test/cpp/util/cli_call.h
@@ -1,4 +1,3 @@
-<?php
/*
*
* Copyright 2015, Google Inc.
@@ -31,16 +30,24 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-class CompletionQueueTest extends PHPUnit_Framework_TestCase{
- public function testNextReturnsNullWithNoCall() {
- $cq = new Grpc\CompletionQueue();
- $event = $cq->next(Grpc\Timeval::zero());
- $this->assertNull($event);
- }
- public function testPluckReturnsNullWithNoCall() {
- $cq = new Grpc\CompletionQueue();
- $event = $cq->pluck(0, Grpc\Timeval::zero());
- $this->assertNull($event);
- }
-}
+#ifndef GRPC_TEST_CPP_UTIL_CLI_CALL_H
+#define GRPC_TEST_CPP_UTIL_CLI_CALL_H
+
+#include <grpc++/channel_interface.h>
+#include <grpc++/config.h>
+
+namespace grpc {
+namespace testing {
+
+class CliCall GRPC_FINAL {
+ public:
+ static void Call(std::shared_ptr<grpc::ChannelInterface> channel,
+ const grpc::string& method, const grpc::string& request,
+ grpc::string* response);
+};
+
+} // namespace testing
+} // namespace grpc
+
+#endif // GRPC_TEST_CPP_UTIL_CLI_CALL_H
diff --git a/test/cpp/util/cli_call_test.cc b/test/cpp/util/cli_call_test.cc
new file mode 100644
index 0000000..91fc40c
--- /dev/null
+++ b/test/cpp/util/cli_call_test.cc
@@ -0,0 +1,131 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/util/test_config.h"
+#include "test/cpp/util/cli_call.h"
+#include "test/cpp/util/echo.pb.h"
+#include "src/cpp/server/thread_pool.h"
+#include <grpc++/channel_arguments.h>
+#include <grpc++/channel_interface.h>
+#include <grpc++/client_context.h>
+#include <grpc++/create_channel.h>
+#include <grpc++/credentials.h>
+#include <grpc++/server.h>
+#include <grpc++/server_builder.h>
+#include <grpc++/server_context.h>
+#include <grpc++/server_credentials.h>
+#include <grpc++/status.h>
+#include "test/core/util/port.h"
+#include <gtest/gtest.h>
+
+#include <grpc/grpc.h>
+
+using grpc::cpp::test::util::EchoRequest;
+using grpc::cpp::test::util::EchoResponse;
+
+namespace grpc {
+namespace testing {
+
+class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
+ public:
+ Status Echo(ServerContext* context, const EchoRequest* request,
+ EchoResponse* response) GRPC_OVERRIDE {
+ response->set_message(request->message());
+ return Status::OK;
+ }
+};
+
+class CliCallTest : public ::testing::Test {
+ protected:
+ CliCallTest() : thread_pool_(2) {}
+
+ void SetUp() GRPC_OVERRIDE {
+ int port = grpc_pick_unused_port_or_die();
+ server_address_ << "localhost:" << port;
+ // Setup server
+ ServerBuilder builder;
+ builder.AddListeningPort(server_address_.str(),
+ InsecureServerCredentials());
+ builder.RegisterService(&service_);
+ builder.SetThreadPool(&thread_pool_);
+ server_ = builder.BuildAndStart();
+ }
+
+ void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
+
+ void ResetStub() {
+ channel_ = CreateChannel(server_address_.str(), InsecureCredentials(),
+ ChannelArguments());
+ stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
+ }
+
+ std::shared_ptr<ChannelInterface> channel_;
+ std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_;
+ std::unique_ptr<Server> server_;
+ std::ostringstream server_address_;
+ TestServiceImpl service_;
+ ThreadPool thread_pool_;
+};
+
+// Send a rpc with a normal stub and then a CliCall. Verify they match.
+TEST_F(CliCallTest, SimpleRpc) {
+ ResetStub();
+ // Normal stub.
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("Hello");
+
+ ClientContext context;
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(response.message(), request.message());
+ EXPECT_TRUE(s.IsOk());
+
+ const grpc::string kMethod("/grpc.cpp.test.util.TestService/Echo");
+ grpc::string request_bin, response_bin, expected_response_bin;
+ EXPECT_TRUE(request.SerializeToString(&request_bin));
+ EXPECT_TRUE(response.SerializeToString(&expected_response_bin));
+ CliCall::Call(channel_, kMethod, request_bin, &response_bin);
+ EXPECT_EQ(expected_response_bin, response_bin);
+}
+
+} // namespace testing
+} // namespace grpc
+
+int main(int argc, char** argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+ ::testing::InitGoogleTest(&argc, argv);
+ int result = RUN_ALL_TESTS();
+ grpc_shutdown();
+ return result;
+}
diff --git a/test/cpp/util/grpc_cli.cc b/test/cpp/util/grpc_cli.cc
new file mode 100644
index 0000000..f2271d9
--- /dev/null
+++ b/test/cpp/util/grpc_cli.cc
@@ -0,0 +1,139 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ A command line tool to talk to any grpc server.
+ Example of talking to grpc interop server:
+ 1. Prepare request binary file:
+ a. create a text file input.txt, containing the following:
+ response_size: 10
+ payload: {
+ body: "hello world"
+ }
+ b. under grpc/ run
+ protoc --proto_path=test/cpp/interop/ \
+ --encode=grpc.testing.SimpleRequest test/cpp/interop/messages.proto \
+ < input.txt > input.bin
+ 2. Start a server
+ make interop_server && bins/opt/interop_server --port=50051
+ 3. Run the tool
+ make grpc_cli && bins/opt/grpc_cli call localhost:50051 \
+ /grpc.testing.TestService/UnaryCall --enable_ssl=false \
+ --input_binary_file=input.bin --output_binary_file=output.bin
+ 4. Decode response
+ protoc --proto_path=test/cpp/interop/ \
+ --decode=grpc.testing.SimpleResponse test/cpp/interop/messages.proto \
+ < output.bin > output.txt
+ 5. Now the text form of response should be in output.txt
+*/
+
+#include <fstream>
+#include <iostream>
+#include <sstream>
+
+#include <gflags/gflags.h>
+#include "test/cpp/util/cli_call.h"
+#include <grpc++/channel_arguments.h>
+#include <grpc++/channel_interface.h>
+#include <grpc++/create_channel.h>
+#include <grpc++/credentials.h>
+
+#include <grpc/grpc.h>
+
+// In some distros, gflags is in the namespace google, and in some others,
+// in gflags. This hack is enabling us to find both.
+namespace google {}
+namespace gflags {}
+using namespace google;
+using namespace gflags;
+
+DEFINE_bool(enable_ssl, true, "Whether to use ssl/tls.");
+DEFINE_bool(use_auth, false, "Whether to create default google credentials.");
+DEFINE_string(input_binary_file, "",
+ "Path to input file containing serialized request.");
+DEFINE_string(output_binary_file, "output.bin",
+ "Path to output file to write serialized response.");
+
+int main(int argc, char** argv) {
+ grpc_init();
+
+ ParseCommandLineFlags(&argc, &argv, true);
+
+ if (argc < 4 || grpc::string(argv[1]) != "call") {
+ std::cout << "Usage: grpc_cli call server_host:port full_method_string\n"
+ << "Example: grpc_cli call service.googleapis.com "
+ << "/grpc.testing.TestService/UnaryCall "
+ << "--input_binary_file=input.bin --output_binary_file=output.bin"
+ << std::endl;
+ }
+ grpc::string server_address(argv[2]);
+ // TODO(yangg) basic check of method string
+ grpc::string method(argv[3]);
+
+ if (FLAGS_input_binary_file.empty()) {
+ std::cout << "Missing --input_binary_file for serialized request."
+ << std::endl;
+ return 1;
+ }
+ std::cout << "connecting to " << server_address << std::endl;
+
+ std::ifstream input_file(FLAGS_input_binary_file,
+ std::ios::in | std::ios::binary);
+ std::stringstream input_stream;
+ input_stream << input_file.rdbuf();
+
+ std::unique_ptr<grpc::Credentials> creds;
+ if (!FLAGS_enable_ssl) {
+ creds = grpc::InsecureCredentials();
+ } else {
+ if (FLAGS_use_auth) {
+ creds = grpc::GoogleDefaultCredentials();
+ } else {
+ creds = grpc::SslCredentials(grpc::SslCredentialsOptions());
+ }
+ }
+ std::shared_ptr<grpc::ChannelInterface> channel =
+ grpc::CreateChannel(server_address, creds, grpc::ChannelArguments());
+
+ grpc::string response;
+ grpc::testing::CliCall::Call(channel, method, input_stream.str(), &response);
+ if (!response.empty()) {
+ std::ofstream output_file(FLAGS_output_binary_file,
+ std::ios::trunc | std::ios::binary);
+ output_file << response;
+ }
+
+ channel.reset();
+ grpc_shutdown();
+ return 0;
+}
diff --git a/test/cpp/util/messages.proto b/test/cpp/util/messages.proto
index 9c27f68..a79bce1 100644
--- a/test/cpp/util/messages.proto
+++ b/test/cpp/util/messages.proto
@@ -34,6 +34,8 @@
message RequestParams {
optional bool echo_deadline = 1;
+ optional int32 client_cancel_after_us = 2;
+ optional int32 server_cancel_after_us = 3;
}
message EchoRequest {
diff --git a/tools/dockerfile/grpc_php/Dockerfile b/tools/dockerfile/grpc_php/Dockerfile
index 100d7b3..770d0d2 100644
--- a/tools/dockerfile/grpc_php/Dockerfile
+++ b/tools/dockerfile/grpc_php/Dockerfile
@@ -45,3 +45,9 @@
RUN cd /var/local/git/grpc/src/php/ext/grpc \
&& ./configure \
&& make
+
+RUN cd /var/local/git/grpc/src/php && composer install
+
+RUN cd /var/local/git/grpc/src/php && protoc-gen-php -i tests/interop/ -o tests/interop/ tests/interop/test.proto
+
+RUN cd /var/local/git/grpc/src/php && ./bin/run_tests.sh
\ No newline at end of file
diff --git a/tools/dockerfile/grpc_php_base/Dockerfile b/tools/dockerfile/grpc_php_base/Dockerfile
index cc874fd..c49d3fe 100644
--- a/tools/dockerfile/grpc_php_base/Dockerfile
+++ b/tools/dockerfile/grpc_php_base/Dockerfile
@@ -32,6 +32,10 @@
# Includes PHP installation dependencies, things that are unlikely to vary.
FROM grpc/base
+RUN echo "deb http://packages.dotdeb.org wheezy-php55 all" >> /etc/apt/sources.list.d/dotdeb.list
+RUN echo "deb-src http://packages.dotdeb.org wheezy-php55 all" >> /etc/apt/sources.list.d/dotdeb.list
+RUN wget http://www.dotdeb.org/dotdeb.gpg -O- |apt-key add -
+
# Install RVM dependencies and other packages
RUN apt-get update && apt-get install -y \
autoconf \
@@ -50,29 +54,25 @@
libsqlite3-dev \
libssl-dev \
libtool \
+ libxml2 \
libyaml-dev \
make \
patch \
procps \
-# TODO(mlumish): Uncomment these lines when building against them works
-# php5-common \
-# php5-cli \
-# php5-dev \
-# php-pear \
+ php5-common \
+ php5-cli \
+ php5-dev \
+ php-pear \
pkg-config \
procps \
sqlite3 \
zlib1g-dev
-# Install the version of PHP gRPC is tested against
ENV DEBIAN_FRONTEND noniteractive
-RUN apt-get update && apt-get install -y libxml2 libxml2-dev # used by PHP
-RUN cd /var/local \
- && curl -o php-5.5.17.tar.gz http://php.net/distributions/php-5.5.17.tar.gz \
- && tar -xf php-5.5.17.tar.gz \
- && cd php-5.5.17 \
- && ./configure --with-zlib=/usr --with-libxml-dir=ext/libxml \
- && make -j12 && make install
+
+# Install composer
+RUN curl -sS https://getcomposer.org/installer | php
+RUN mv composer.phar /usr/local/bin/composer
# Download the patched PHP protobuf so that PHP gRPC clients can be generated
# from proto3 schemas.
diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py
index a132ef4..3cf6ddf 100755
--- a/tools/run_tests/run_tests.py
+++ b/tools/run_tests/run_tests.py
@@ -224,6 +224,24 @@
def __str__(self):
return 'csharp'
+class Build(object):
+
+ def test_specs(self, config, travis):
+ return []
+
+ def make_targets(self):
+ return ['all']
+
+ def build_steps(self):
+ return []
+
+ def supports_multi_config(self):
+ return True
+
+ def __str__(self):
+ return self.make_target
+
+
# different configurations we can run under
_CONFIGS = {
'dbg': SimpleConfig('dbg'),
@@ -248,7 +266,8 @@
'php': PhpLanguage(),
'python': PythonLanguage(),
'ruby': RubyLanguage(),
- 'csharp': CSharpLanguage()
+ 'csharp': CSharpLanguage(),
+ 'build': Build(),
}
# parse command line
diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json
index 0150fd4..eab0704 100644
--- a/tools/run_tests/tests.json
+++ b/tools/run_tests/tests.json
@@ -349,6 +349,11 @@
{
"flaky": false,
"language": "c++",
+ "name": "cli_call_test"
+ },
+ {
+ "flaky": false,
+ "language": "c++",
"name": "credentials_test"
},
{
diff --git a/vsprojects/vs2013/gpr_test_util.vcxproj b/vsprojects/vs2013/gpr_test_util.vcxproj
index 04caa7e..e0608b3 100644
--- a/vsprojects/vs2013/gpr_test_util.vcxproj
+++ b/vsprojects/vs2013/gpr_test_util.vcxproj
@@ -78,6 +78,9 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClInclude Include="..\..\test\core\util\test_config.h" />
+ </ItemGroup>
+ <ItemGroup>
<ClCompile Include="..\..\test\core\util\test_config.c">
</ClCompile>
</ItemGroup>
diff --git a/vsprojects/vs2013/grpc++.vcxproj b/vsprojects/vs2013/grpc++.vcxproj
index 6d921e7..d545a94 100644
--- a/vsprojects/vs2013/grpc++.vcxproj
+++ b/vsprojects/vs2013/grpc++.vcxproj
@@ -128,6 +128,8 @@
</ClCompile>
<ClCompile Include="..\..\src\cpp\client\credentials.cc">
</ClCompile>
+ <ClCompile Include="..\..\src\cpp\client\generic_stub.cc">
+ </ClCompile>
<ClCompile Include="..\..\src\cpp\client\insecure_credentials.cc">
</ClCompile>
<ClCompile Include="..\..\src\cpp\client\internal_stub.cc">
diff --git a/vsprojects/vs2013/grpc++.vcxproj.filters b/vsprojects/vs2013/grpc++.vcxproj.filters
index 61b3bc5..ed93dae 100644
--- a/vsprojects/vs2013/grpc++.vcxproj.filters
+++ b/vsprojects/vs2013/grpc++.vcxproj.filters
@@ -25,6 +25,9 @@
<ClCompile Include="..\..\src\cpp\client\credentials.cc">
<Filter>src\cpp\client</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\cpp\client\generic_stub.cc">
+ <Filter>src\cpp\client</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\cpp\client\insecure_credentials.cc">
<Filter>src\cpp\client</Filter>
</ClCompile>
diff --git a/vsprojects/vs2013/grpc.sln b/vsprojects/vs2013/grpc.sln
index a3915b3..4e56edd 100644
--- a/vsprojects/vs2013/grpc.sln
+++ b/vsprojects/vs2013/grpc.sln
@@ -18,6 +18,7 @@
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grpc_test_util", "grpc_test_util.vcxproj", "{17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}"
ProjectSection(ProjectDependencies) = postProject
{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}
+ {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037}
{29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9}
EndProjectSection
EndProject
diff --git a/vsprojects/vs2013/grpc.vcxproj b/vsprojects/vs2013/grpc.vcxproj
index 754c899..a88eb34 100644
--- a/vsprojects/vs2013/grpc.vcxproj
+++ b/vsprojects/vs2013/grpc.vcxproj
@@ -358,6 +358,8 @@
</ClCompile>
<ClCompile Include="..\..\src\core\surface\call_details.c">
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\call_log_batch.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\channel.c">
</ClCompile>
<ClCompile Include="..\..\src\core\surface\channel_create.c">
diff --git a/vsprojects/vs2013/grpc.vcxproj.filters b/vsprojects/vs2013/grpc.vcxproj.filters
index 463a770..20dbe8c 100644
--- a/vsprojects/vs2013/grpc.vcxproj.filters
+++ b/vsprojects/vs2013/grpc.vcxproj.filters
@@ -253,6 +253,9 @@
<ClCompile Include="..\..\src\core\surface\call_details.c">
<Filter>src\core\surface</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\call_log_batch.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\channel.c">
<Filter>src\core\surface</Filter>
</ClCompile>
diff --git a/vsprojects/vs2013/grpc_shared.vcxproj b/vsprojects/vs2013/grpc_shared.vcxproj
index 927d205..b673cc7 100644
--- a/vsprojects/vs2013/grpc_shared.vcxproj
+++ b/vsprojects/vs2013/grpc_shared.vcxproj
@@ -362,6 +362,8 @@
</ClCompile>
<ClCompile Include="..\..\src\core\surface\call_details.c">
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\call_log_batch.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\channel.c">
</ClCompile>
<ClCompile Include="..\..\src\core\surface\channel_create.c">
diff --git a/vsprojects/vs2013/grpc_shared.vcxproj.filters b/vsprojects/vs2013/grpc_shared.vcxproj.filters
index 463a770..20dbe8c 100644
--- a/vsprojects/vs2013/grpc_shared.vcxproj.filters
+++ b/vsprojects/vs2013/grpc_shared.vcxproj.filters
@@ -253,6 +253,9 @@
<ClCompile Include="..\..\src\core\surface\call_details.c">
<Filter>src\core\surface</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\call_log_batch.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\channel.c">
<Filter>src\core\surface</Filter>
</ClCompile>
diff --git a/vsprojects/vs2013/grpc_test_util.vcxproj b/vsprojects/vs2013/grpc_test_util.vcxproj
index 7269671..4756f53 100644
--- a/vsprojects/vs2013/grpc_test_util.vcxproj
+++ b/vsprojects/vs2013/grpc_test_util.vcxproj
@@ -105,6 +105,9 @@
<ProjectReference Include="gpr.vcxproj">
<Project>{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}</Project>
</ProjectReference>
+ <ProjectReference Include="gpr_test_util.vcxproj">
+ <Project>{EAB0A629-17A9-44DB-B5FF-E91A721FE037}</Project>
+ </ProjectReference>
<ProjectReference Include="grpc.vcxproj">
<Project>{29D16885-7228-4C31-81ED-5F9187C7F2A9}</Project>
</ProjectReference>
diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj b/vsprojects/vs2013/grpc_unsecure.vcxproj
index e1c1bc8..98c14c2 100644
--- a/vsprojects/vs2013/grpc_unsecure.vcxproj
+++ b/vsprojects/vs2013/grpc_unsecure.vcxproj
@@ -302,6 +302,8 @@
</ClCompile>
<ClCompile Include="..\..\src\core\surface\call_details.c">
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\call_log_batch.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\channel.c">
</ClCompile>
<ClCompile Include="..\..\src\core\surface\channel_create.c">
diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
index fe96623..4b758d6 100644
--- a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
+++ b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
@@ -193,6 +193,9 @@
<ClCompile Include="..\..\src\core\surface\call_details.c">
<Filter>src\core\surface</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\call_log_batch.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\channel.c">
<Filter>src\core\surface</Filter>
</ClCompile>