Merge branch 'master' of https://github.com/grpc/grpc into interop_server_split

pull/7447/head
Nicolas "Pixel" Noble 9 years ago
commit 64f8d09ca0
  1. 2
      Makefile
  2. 1
      build.yaml
  3. 2
      examples/php/composer.json
  4. 1
      package.xml
  5. 65
      setup.py
  6. 5
      src/core/ext/transport/chttp2/client/insecure/channel_create.c
  7. 23
      src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
  8. 35
      src/core/ext/transport/chttp2/server/insecure/server_chttp2.c
  9. 28
      src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c
  10. 20
      src/core/lib/channel/handshaker.c
  11. 12
      src/core/lib/channel/handshaker.h
  12. 5
      src/core/lib/security/transport/handshake.c
  13. 2
      src/core/lib/transport/transport.h
  14. 3
      src/csharp/Grpc.Core/GrpcEnvironment.cs
  15. 24
      src/objective-c/tests/InteropTestsRemoteWithCronet/Info.plist
  16. 50
      src/objective-c/tests/InteropTestsRemoteWithCronet/InteropTestsRemoteWithCronet.m
  17. 16
      src/objective-c/tests/Podfile
  18. 184
      src/objective-c/tests/Tests.xcodeproj/project.pbxproj
  19. 104
      src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/InteropTestsRemoteWithCronet.xcscheme
  20. 43
      src/php/README.md
  21. 6
      src/php/bin/determine_extension_dir.sh
  22. 4
      src/php/composer.json
  23. 307
      src/php/ext/grpc/call.c
  24. 31
      src/php/ext/grpc/call.h
  25. 86
      src/php/ext/grpc/call_credentials.c
  26. 21
      src/php/ext/grpc/call_credentials.h
  27. 124
      src/php/ext/grpc/channel.c
  28. 20
      src/php/ext/grpc/channel.h
  29. 77
      src/php/ext/grpc/channel_credentials.c
  30. 21
      src/php/ext/grpc/channel_credentials.h
  31. 84
      src/php/ext/grpc/php7_wrapper.h
  32. 2
      src/php/ext/grpc/php_grpc.h
  33. 74
      src/php/ext/grpc/server.c
  34. 20
      src/php/ext/grpc/server.h
  35. 40
      src/php/ext/grpc/server_credentials.c
  36. 22
      src/php/ext/grpc/server_credentials.h
  37. 131
      src/php/ext/grpc/timeval.c
  38. 21
      src/php/ext/grpc/timeval.h
  39. 1
      src/python/grpcio/.gitignore
  40. 67
      src/python/grpcio/commands.py
  41. 2
      templates/Makefile.template
  42. 30
      templates/tools/dockerfile/interoptest/grpc_interop_php/Dockerfile.template
  43. 37
      templates/tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile.template
  44. 45
      templates/tools/dockerfile/php7_deps.include
  45. 21
      templates/tools/dockerfile/php_common_deps.include
  46. 6
      templates/tools/dockerfile/php_deps.include
  47. 5
      templates/tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile.template
  48. 38
      templates/tools/dockerfile/test/php7_jessie_x64/Dockerfile.template
  49. 12
      test/core/iomgr/udp_server_test.c
  50. 29
      tools/dockerfile/interoptest/grpc_interop_php/Dockerfile
  51. 125
      tools/dockerfile/interoptest/grpc_interop_php7/Dockerfile
  52. 52
      tools/dockerfile/interoptest/grpc_interop_php7/build_interop.sh
  53. 11
      tools/dockerfile/stress_test/grpc_interop_stress_php/Dockerfile
  54. 6
      tools/dockerfile/test/multilang_jessie_x64/Dockerfile
  55. 105
      tools/dockerfile/test/php7_jessie_x64/Dockerfile
  56. 6
      tools/dockerfile/test/php_jessie_x64/Dockerfile
  57. 28
      tools/run_tests/run_interop_tests.py
  58. 37
      tools/run_tests/run_tests.py

@ -748,8 +748,8 @@ endif
endif
else
PC_LIBS_GRPCXX = -lprotobuf
PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
endif
PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
else
ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a

@ -3378,6 +3378,7 @@ php_config_m4:
- src/php/ext/grpc/channel.h
- src/php/ext/grpc/channel_credentials.h
- src/php/ext/grpc/completion_queue.h
- src/php/ext/grpc/php7_wrapper.h
- src/php/ext/grpc/php_grpc.h
- src/php/ext/grpc/server.h
- src/php/ext/grpc/server_credentials.h

@ -3,6 +3,6 @@
"description": "gRPC example for PHP",
"minimum-stability": "dev",
"require": {
"grpc/grpc": "v0.15.0"
"grpc/grpc": "v0.15.2"
}
}

@ -46,6 +46,7 @@
<file baseinstalldir="/" name="src/php/ext/grpc/channel.h" role="src" />
<file baseinstalldir="/" name="src/php/ext/grpc/channel_credentials.h" role="src" />
<file baseinstalldir="/" name="src/php/ext/grpc/completion_queue.h" role="src" />
<file baseinstalldir="/" name="src/php/ext/grpc/php7_wrapper.h" role="src" />
<file baseinstalldir="/" name="src/php/ext/grpc/php_grpc.h" role="src" />
<file baseinstalldir="/" name="src/php/ext/grpc/server.h" role="src" />
<file baseinstalldir="/" name="src/php/ext/grpc/server_credentials.h" role="src" />

@ -168,55 +168,27 @@ if 'darwin' in sys.platform and PY3:
r'macosx-10.7-\1',
util.get_platform())
def cython_extensions():
module_names = list(CYTHON_EXTENSION_MODULE_NAMES)
extra_sources = list(CYTHON_HELPER_C_FILES) + list(CORE_C_FILES)
include_dirs = list(EXTENSION_INCLUDE_DIRECTORIES)
libraries = list(EXTENSION_LIBRARIES)
define_macros = list(DEFINE_MACROS)
build_with_cython = bool(BUILD_WITH_CYTHON)
# Set compiler directives linetrace argument only if we care about tracing;
# this is due to Cython having different behavior between linetrace being
# False and linetrace being unset. See issue #5689.
cython_compiler_directives = {}
if ENABLE_CYTHON_TRACING:
define_macros = define_macros + [('CYTHON_TRACE_NOGIL', 1)]
cython_compiler_directives['linetrace'] = True
pyx_module_files = [os.path.join(PYTHON_STEM,
name.replace('.', '/') + '.pyx')
for name in module_names]
c_module_files = [os.path.join(PYTHON_STEM,
name.replace('.', '/') + '.c')
for name in module_names]
if not build_with_cython:
for module_file in c_module_files:
if not os.path.isfile(module_file):
sys.stderr.write('Cython-generated files are missing; '
'forcing Cython build...\n')
build_with_cython = True
break
module_files = pyx_module_files if build_with_cython else c_module_files
def cython_extensions_and_necessity():
cython_module_files = [os.path.join(PYTHON_STEM,
name.replace('.', '/') + '.pyx')
for name in CYTHON_EXTENSION_MODULE_NAMES]
extensions = [
_extension.Extension(
name=module_name,
sources=[module_file] + extra_sources,
include_dirs=include_dirs, libraries=libraries,
define_macros=define_macros,
sources=[module_file] + list(CYTHON_HELPER_C_FILES) + list(CORE_C_FILES),
include_dirs=list(EXTENSION_INCLUDE_DIRECTORIES),
libraries=list(EXTENSION_LIBRARIES),
define_macros=list(DEFINE_MACROS),
extra_compile_args=list(CFLAGS),
extra_link_args=list(LDFLAGS),
) for (module_name, module_file) in zip(module_names, module_files)
) for (module_name, module_file) in zip(list(CYTHON_EXTENSION_MODULE_NAMES), cython_module_files)
]
if build_with_cython:
import Cython.Build
return Cython.Build.cythonize(
extensions,
include_path=include_dirs,
compiler_directives=cython_compiler_directives)
else:
return extensions
need_cython = BUILD_WITH_CYTHON
if not BUILD_WITH_CYTHON:
need_cython = need_cython or not commands.check_and_update_cythonization(extensions)
return commands.try_cythonize(extensions, linetracing=ENABLE_CYTHON_TRACING, mandatory=BUILD_WITH_CYTHON), need_cython
CYTHON_EXTENSION_MODULES = cython_extensions()
CYTHON_EXTENSION_MODULES, need_cython = cython_extensions_and_necessity()
PACKAGE_DIRECTORIES = {
'': PYTHON_STEM,
@ -236,6 +208,15 @@ SETUP_REQUIRES = INSTALL_REQUIRES + (
'sphinx_rtd_theme>=0.1.8',
'six>=1.10',
)
if BUILD_WITH_CYTHON:
sys.stderr.write(
"You requested a Cython build via GRPC_PYTHON_BUILD_WITH_CYTHON, "
"but do not have Cython installed. We won't stop you from using "
"other commands, but the extension files will fail to build.\n")
elif need_cython:
sys.stderr.write(
'We could not find Cython. Setup may take 10-20 minutes.\n')
SETUP_REQUIRES += ('cython>=0.23',)
COMMAND_CLASS = {
'doc': commands.SphinxDocumentation,

@ -88,7 +88,8 @@ static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg,
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_channel_args *args, void *user_data) {
grpc_channel_args *args, void *user_data,
grpc_error *error) {
connector *c = user_data;
c->result->transport =
grpc_create_chttp2_transport(exec_ctx, args, endpoint, 1);
@ -97,7 +98,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
c->result->channel_args = args;
grpc_closure *notify = c->notify;
c->notify = NULL;
grpc_exec_ctx_sched(exec_ctx, notify, GRPC_ERROR_NONE, NULL);
grpc_exec_ctx_sched(exec_ctx, notify, error, NULL);
}
static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {

@ -126,15 +126,22 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_channel_args *args, void *user_data) {
grpc_channel_args *args, void *user_data,
grpc_error *error) {
connector *c = user_data;
// TODO(roth, jboeuf): Convert security connector handshaking to use new
// handshake API, and then move the code from on_secure_handshake_done()
// into this function.
c->tmp_args = args;
grpc_channel_security_connector_do_handshake(exec_ctx, c->security_connector,
endpoint, c->args.deadline,
on_secure_handshake_done, c);
if (error != GRPC_ERROR_NONE) {
grpc_closure *notify = c->notify;
c->notify = NULL;
grpc_exec_ctx_sched(exec_ctx, notify, error, NULL);
} else {
// TODO(roth, jboeuf): Convert security connector handshaking to use new
// handshake API, and then move the code from on_secure_handshake_done()
// into this function.
c->tmp_args = args;
grpc_channel_security_connector_do_handshake(
exec_ctx, c->security_connector, endpoint, c->args.deadline,
on_secure_handshake_done, c);
}
}
static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg,

@ -55,21 +55,28 @@ typedef struct server_connect_state {
} server_connect_state;
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_channel_args *args, void *user_data) {
grpc_channel_args *args, void *user_data,
grpc_error *error) {
server_connect_state *state = user_data;
/*
* Beware that the call to grpc_create_chttp2_transport() has to happen before
* grpc_tcp_server_destroy(). This is fine here, but similar code
* asynchronously doing a handshake instead of calling grpc_tcp_server_start()
* (as in server_secure_chttp2.c) needs to add synchronization to avoid this
* case.
*/
grpc_transport *transport =
grpc_create_chttp2_transport(exec_ctx, args, endpoint, 0);
grpc_server_setup_transport(exec_ctx, state->server, transport,
state->accepting_pollset,
grpc_server_get_channel_args(state->server));
grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL, 0);
if (error != GRPC_ERROR_NONE) {
const char *error_str = grpc_error_string(error);
gpr_log(GPR_ERROR, "Handshaking failed: %s", error_str);
grpc_error_free_string(error_str);
GRPC_ERROR_UNREF(error);
grpc_handshake_manager_shutdown(exec_ctx, state->handshake_mgr);
} else {
// Beware that the call to grpc_create_chttp2_transport() has to happen
// before grpc_tcp_server_destroy(). This is fine here, but similar code
// asynchronously doing a handshake instead of calling
// grpc_tcp_server_start() (as in server_secure_chttp2.c) needs to add
// synchronization to avoid this case.
grpc_transport *transport =
grpc_create_chttp2_transport(exec_ctx, args, endpoint, 0);
grpc_server_setup_transport(exec_ctx, state->server, transport,
state->accepting_pollset,
grpc_server_get_channel_args(state->server));
grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL, 0);
}
// Clean up.
grpc_channel_args_destroy(args);
grpc_handshake_manager_destroy(exec_ctx, state->handshake_mgr);

@ -59,7 +59,7 @@ typedef struct server_secure_state {
grpc_tcp_server *tcp;
grpc_server_security_connector *sc;
grpc_server_credentials *creds;
int is_shutdown;
bool is_shutdown;
gpr_mu mu;
gpr_refcount refcount;
grpc_closure destroy_closure;
@ -96,12 +96,11 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *statep,
grpc_endpoint *secure_endpoint,
grpc_auth_context *auth_context) {
server_secure_connect *state = statep;
grpc_transport *transport;
if (status == GRPC_SECURITY_OK) {
if (secure_endpoint) {
gpr_mu_lock(&state->state->mu);
if (!state->state->is_shutdown) {
transport = grpc_create_chttp2_transport(
grpc_transport *transport = grpc_create_chttp2_transport(
exec_ctx, grpc_server_get_channel_args(state->state->server),
secure_endpoint, 0);
grpc_arg args_to_add[2];
@ -129,13 +128,26 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *statep,
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_channel_args *args, void *user_data) {
grpc_channel_args *args, void *user_data,
grpc_error *error) {
server_secure_connect *state = user_data;
if (error != GRPC_ERROR_NONE) {
const char *error_str = grpc_error_string(error);
gpr_log(GPR_ERROR, "Handshaking failed: %s", error_str);
grpc_error_free_string(error_str);
GRPC_ERROR_UNREF(error);
grpc_handshake_manager_shutdown(exec_ctx, state->handshake_mgr);
grpc_handshake_manager_destroy(exec_ctx, state->handshake_mgr);
grpc_channel_args_destroy(args);
state_unref(state->state);
gpr_free(state);
return;
}
grpc_handshake_manager_destroy(exec_ctx, state->handshake_mgr);
state->handshake_mgr = NULL;
// TODO(roth, jboeuf): Convert security connector handshaking to use new
// handshake API, and then move the code from on_secure_handshake_done()
// into this function.
grpc_handshake_manager_destroy(exec_ctx, state->handshake_mgr);
state->handshake_mgr = NULL;
state->args = args;
grpc_server_security_connector_do_handshake(
exec_ctx, state->state->sc, state->acceptor, endpoint, state->deadline,
@ -187,7 +199,7 @@ static void destroy(grpc_exec_ctx *exec_ctx, grpc_server *server, void *statep,
server_secure_state *state = statep;
grpc_tcp_server *tcp;
gpr_mu_lock(&state->mu);
state->is_shutdown = 1;
state->is_shutdown = true;
state->destroy_callback = callback;
tcp = state->tcp;
gpr_mu_unlock(&state->mu);
@ -252,7 +264,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
state->tcp = tcp;
state->sc = sc;
state->creds = grpc_server_credentials_ref(creds);
state->is_shutdown = 0;
state->is_shutdown = false;
gpr_mu_init(&state->mu);
gpr_ref_init(&state->refcount, 1);

@ -102,8 +102,8 @@ grpc_handshake_manager* grpc_handshake_manager_create() {
static bool is_power_of_2(size_t n) { return (n & (n - 1)) == 0; }
void grpc_handshake_manager_add(grpc_handshaker* handshaker,
grpc_handshake_manager* mgr) {
void grpc_handshake_manager_add(grpc_handshake_manager* mgr,
grpc_handshaker* handshaker) {
// To avoid allocating memory for each handshaker we add, we double
// the number of elements every time we need more.
size_t realloc_count = 0;
@ -130,8 +130,6 @@ void grpc_handshake_manager_destroy(grpc_exec_ctx* exec_ctx,
void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx,
grpc_handshake_manager* mgr) {
// FIXME: maybe check which handshaker is currently in progress, and
// only shut down that one?
for (size_t i = 0; i < mgr->count; ++i) {
grpc_handshaker_shutdown(exec_ctx, mgr->handshakers[i]);
}
@ -145,10 +143,18 @@ void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx,
// handshakers together.
static void call_next_handshaker(grpc_exec_ctx* exec_ctx,
grpc_endpoint* endpoint,
grpc_channel_args* args, void* user_data) {
grpc_channel_args* args, void* user_data,
grpc_error* error) {
grpc_handshake_manager* mgr = user_data;
GPR_ASSERT(mgr->state != NULL);
GPR_ASSERT(mgr->state->index < mgr->count);
// If we got an error, skip all remaining handshakers and invoke the
// caller-supplied callback immediately.
if (error != GRPC_ERROR_NONE) {
mgr->state->final_cb(exec_ctx, endpoint, args, mgr->state->final_user_data,
error);
return;
}
grpc_handshaker_done_cb cb = call_next_handshaker;
// If this is the last handshaker, use the caller-supplied callback
// and user_data instead of chaining back to this function again.
@ -177,7 +183,7 @@ void grpc_handshake_manager_do_handshake(
if (mgr->count == 0) {
// No handshakers registered, so we just immediately call the done
// callback with the passed-in endpoint.
cb(exec_ctx, endpoint, args_copy, user_data);
cb(exec_ctx, endpoint, args_copy, user_data, GRPC_ERROR_NONE);
} else {
GPR_ASSERT(mgr->state == NULL);
mgr->state = gpr_malloc(sizeof(struct grpc_handshaker_state));
@ -186,6 +192,6 @@ void grpc_handshake_manager_do_handshake(
mgr->state->acceptor = acceptor;
mgr->state->final_cb = cb;
mgr->state->final_user_data = user_data;
call_next_handshaker(exec_ctx, endpoint, args_copy, mgr);
call_next_handshaker(exec_ctx, endpoint, args_copy, mgr, GRPC_ERROR_NONE);
}
}

@ -60,7 +60,7 @@ typedef struct grpc_handshaker grpc_handshaker;
typedef void (*grpc_handshaker_done_cb)(grpc_exec_ctx* exec_ctx,
grpc_endpoint* endpoint,
grpc_channel_args* args,
void* user_data);
void* user_data, grpc_error* error);
struct grpc_handshaker_vtable {
/// Destroys the handshaker.
@ -115,9 +115,9 @@ typedef struct grpc_handshake_manager grpc_handshake_manager;
grpc_handshake_manager* grpc_handshake_manager_create();
/// Adds a handshaker to the handshake manager.
/// Takes ownership of \a mgr.
void grpc_handshake_manager_add(grpc_handshaker* handshaker,
grpc_handshake_manager* mgr);
/// Takes ownership of \a handshaker.
void grpc_handshake_manager_add(grpc_handshake_manager* mgr,
grpc_handshaker* handshaker);
/// Destroys the handshake manager.
void grpc_handshake_manager_destroy(grpc_exec_ctx* exec_ctx,
@ -134,8 +134,8 @@ void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx,
/// Does NOT take ownership of \a args. Instead, makes a copy before
/// invoking the first handshaker.
/// \a acceptor will be NULL for client-side handshakers.
/// If successful, invokes \a cb with \a user_data after all handshakers
/// have completed.
/// Invokes \a cb with \a user_data after either a handshaker fails or
/// all handshakers have completed successfully.
void grpc_handshake_manager_do_handshake(
grpc_exec_ctx* exec_ctx, grpc_handshake_manager* mgr,
grpc_endpoint* endpoint, const grpc_channel_args* args,

@ -357,8 +357,9 @@ void grpc_do_security_handshake(
gpr_mu_unlock(&server_connector->mu);
}
send_handshake_bytes_to_peer(exec_ctx, h);
grpc_timer_init(exec_ctx, &h->timer, deadline, on_timeout, h,
gpr_now(deadline.clock_type));
grpc_timer_init(exec_ctx, &h->timer,
gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC),
on_timeout, h, gpr_now(GPR_CLOCK_MONOTONIC));
}
void grpc_security_handshake_shutdown(grpc_exec_ctx *exec_ctx,

@ -138,7 +138,7 @@ typedef struct grpc_transport_stream_op {
/** If != GRPC_ERROR_NONE, cancel this stream */
grpc_error *cancel_error;
/** If != GRPC_ERROR, send grpc-status, grpc-message, and close this
/** If != GRPC_ERROR_NONE, send grpc-status, grpc-message, and close this
stream for both reading and writing */
grpc_error *close_error;

@ -47,7 +47,6 @@ namespace Grpc.Core
/// </summary>
public class GrpcEnvironment
{
const LogLevel DefaultLogLevel = LogLevel.Info;
const int MinDefaultThreadPoolSize = 4;
static object staticLock = new object();
@ -58,7 +57,7 @@ namespace Grpc.Core
static readonly HashSet<Channel> registeredChannels = new HashSet<Channel>();
static readonly HashSet<Server> registeredServers = new HashSet<Server>();
static ILogger logger = new LogLevelFilterLogger(new ConsoleLogger(), DefaultLogLevel);
static ILogger logger = new NullLogger();
readonly object myLock = new object();
readonly GrpcThreadPool threadPool;

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

@ -0,0 +1,50 @@
/*
*
* 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.
*
*/
#import <GRPCClient/GRPCCall+Tests.h>
#import "InteropTests.h"
static NSString * const kRemoteSSLHost = @"grpc-test.sandbox.googleapis.com";
/** Tests in InteropTests.m, sending the RPCs to a remote SSL server. */
@interface InteropTestsRemoteWithCronet : InteropTests
@end
@implementation InteropTestsRemoteWithCronet
+ (NSString *)host {
return kRemoteSSLHost;
}
@end

@ -39,6 +39,22 @@ target 'CoreCronetEnd2EndTests' do
pod 'gRPC-Core/Cronet-Tests', :path => GRPC_LOCAL_SRC
end
target 'InteropTestsRemoteWithCronet' do
pod 'Protobuf', :path => "#{GRPC_LOCAL_SRC}/third_party/protobuf", :inhibit_warnings => true
pod '!ProtoCompiler', :path => "#{GRPC_LOCAL_SRC}/src/objective-c"
pod '!ProtoCompiler-gRPCPlugin', :path => "#{GRPC_LOCAL_SRC}/src/objective-c"
pod 'BoringSSL', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c", :inhibit_warnings => true
pod 'CronetFramework', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c"
pod 'gRPC', :path => GRPC_LOCAL_SRC
pod 'gRPC-Core', :path => GRPC_LOCAL_SRC
pod 'gRPC-RxLibrary', :path => GRPC_LOCAL_SRC
pod 'gRPC-ProtoRPC', :path => GRPC_LOCAL_SRC
pod 'RemoteTest', :path => "RemoteTestClient"
end
# gRPC-Core.podspec needs to be modified to be successfully used for local development. A Podfile's
# pre_install hook lets us do that. The block passed to it runs after the podspecs are downloaded
# and before they are installed in the user project.

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
09B76D9585ACE7403804D9DC /* libPods-InteropTestsRemoteWithCronet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E9444C764F0FFF64A7EB58E /* libPods-InteropTestsRemoteWithCronet.a */; };
0F9232F984C08643FD40C34F /* libPods-InteropTestsRemote.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DBE059B4AC7A51919467EEC0 /* libPods-InteropTestsRemote.a */; };
16A9E77B6E336B3C0B9BA6E0 /* libPods-InteropTestsLocalSSL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DBEDE45BDA60DF1E1C8950C0 /* libPods-InteropTestsLocalSSL.a */; };
20DFDF829DD993A4A00D5662 /* libPods-RxLibraryUnitTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A58BE6DF1C62D1739EBB2C78 /* libPods-RxLibraryUnitTests.a */; };
@ -14,6 +15,9 @@
3D7C85F6AA68C4A205E3BA16 /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 20DFF2F3C97EF098FE5A3171 /* libPods-Tests.a */; };
5E8A5DA71D3840B4000F8BC4 /* CoreCronetEnd2EndTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E8A5DA61D3840B4000F8BC4 /* CoreCronetEnd2EndTests.m */; };
5E8A5DA91D3840B4000F8BC4 /* libTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 635697C71B14FC11007A7283 /* libTests.a */; };
5EE84BF41D4717E40050C6CC /* InteropTestsRemoteWithCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE84BF31D4717E40050C6CC /* InteropTestsRemoteWithCronet.m */; };
5EE84BF61D4717E40050C6CC /* libTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 635697C71B14FC11007A7283 /* libTests.a */; };
5EE84BFE1D471D400050C6CC /* InteropTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 635ED2EB1B1A3BC400FDE5C3 /* InteropTests.m */; };
60D2A57ED559F34428C2EEC5 /* libPods-CoreCronetEnd2EndTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FBD98AC417B9882D32B19F28 /* libPods-CoreCronetEnd2EndTests.a */; };
6312AE4E1B1BF49B00341DEE /* GRPCClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6312AE4D1B1BF49B00341DEE /* GRPCClientTests.m */; };
63423F4A1B150A5F006CF63C /* libTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 635697C71B14FC11007A7283 /* libTests.a */; };
@ -48,6 +52,13 @@
remoteGlobalIDString = 635697C61B14FC11007A7283;
remoteInfo = Tests;
};
5EE84BF71D4717E40050C6CC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 635697BF1B14FC11007A7283 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 635697C61B14FC11007A7283;
remoteInfo = Tests;
};
63423F4B1B150A5F006CF63C /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 635697BF1B14FC11007A7283 /* Project object */;
@ -102,6 +113,7 @@
07D10A965323BEA7FE59A74B /* Pods-RxLibraryUnitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxLibraryUnitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RxLibraryUnitTests/Pods-RxLibraryUnitTests.debug.xcconfig"; sourceTree = "<group>"; };
0A4F89D9C90E9C30990218F0 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
0D2284C3DF7E57F0ED504E39 /* Pods-CoreCronetEnd2EndTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CoreCronetEnd2EndTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CoreCronetEnd2EndTests/Pods-CoreCronetEnd2EndTests.debug.xcconfig"; sourceTree = "<group>"; };
17F60BF2871F6AF85FB3FA12 /* Pods-InteropTestsRemoteWithCronet.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InteropTestsRemoteWithCronet.debug.xcconfig"; path = "Pods/Target Support Files/Pods-InteropTestsRemoteWithCronet/Pods-InteropTestsRemoteWithCronet.debug.xcconfig"; sourceTree = "<group>"; };
20DFF2F3C97EF098FE5A3171 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
35F2B6BF3BAE8F0DC4AFD76E /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
3B0861FC805389C52DB260D4 /* Pods-RxLibraryUnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxLibraryUnitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-RxLibraryUnitTests/Pods-RxLibraryUnitTests.release.xcconfig"; sourceTree = "<group>"; };
@ -111,6 +123,9 @@
5761E98978DDDF136A58CB7E /* Pods-AllTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AllTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-AllTests/Pods-AllTests.release.xcconfig"; sourceTree = "<group>"; };
5E8A5DA41D3840B4000F8BC4 /* CoreCronetEnd2EndTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoreCronetEnd2EndTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5E8A5DA61D3840B4000F8BC4 /* CoreCronetEnd2EndTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CoreCronetEnd2EndTests.m; sourceTree = "<group>"; };
5EE84BF11D4717E40050C6CC /* InteropTestsRemoteWithCronet.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = InteropTestsRemoteWithCronet.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5EE84BF31D4717E40050C6CC /* InteropTestsRemoteWithCronet.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InteropTestsRemoteWithCronet.m; sourceTree = "<group>"; };
5EE84BF51D4717E40050C6CC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6312AE4D1B1BF49B00341DEE /* GRPCClientTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GRPCClientTests.m; sourceTree = "<group>"; };
63423F441B150A5F006CF63C /* AllTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AllTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
63423F501B151B77006CF63C /* RxLibraryUnitTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RxLibraryUnitTests.m; sourceTree = "<group>"; };
@ -128,7 +143,9 @@
63E240CD1B6C4E2B005F3B0E /* InteropTestsLocalSSL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InteropTestsLocalSSL.m; sourceTree = "<group>"; };
63E240CF1B6C63DC005F3B0E /* TestCertificates.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TestCertificates.bundle; sourceTree = "<group>"; };
7A2E97E3F469CC2A758D77DE /* Pods-InteropTestsLocalSSL.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InteropTestsLocalSSL.release.xcconfig"; path = "Pods/Target Support Files/Pods-InteropTestsLocalSSL/Pods-InteropTestsLocalSSL.release.xcconfig"; sourceTree = "<group>"; };
9E9444C764F0FFF64A7EB58E /* libPods-InteropTestsRemoteWithCronet.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-InteropTestsRemoteWithCronet.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A58BE6DF1C62D1739EBB2C78 /* libPods-RxLibraryUnitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RxLibraryUnitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
AC414EF7A6BF76ED02B6E480 /* Pods-InteropTestsRemoteWithCronet.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InteropTestsRemoteWithCronet.release.xcconfig"; path = "Pods/Target Support Files/Pods-InteropTestsRemoteWithCronet/Pods-InteropTestsRemoteWithCronet.release.xcconfig"; sourceTree = "<group>"; };
B94C27C06733CF98CE1B2757 /* Pods-AllTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AllTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AllTests/Pods-AllTests.debug.xcconfig"; sourceTree = "<group>"; };
CAE086D5B470DA367D415AB0 /* libPods-AllTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AllTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
DBE059B4AC7A51919467EEC0 /* libPods-InteropTestsRemote.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-InteropTestsRemote.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@ -152,6 +169,15 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
5EE84BEE1D4717E40050C6CC /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5EE84BF61D4717E40050C6CC /* libTests.a in Frameworks */,
09B76D9585ACE7403804D9DC /* libPods-InteropTestsRemoteWithCronet.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
63423F411B150A5F006CF63C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@ -219,6 +245,7 @@
A58BE6DF1C62D1739EBB2C78 /* libPods-RxLibraryUnitTests.a */,
20DFF2F3C97EF098FE5A3171 /* libPods-Tests.a */,
FBD98AC417B9882D32B19F28 /* libPods-CoreCronetEnd2EndTests.a */,
9E9444C764F0FFF64A7EB58E /* libPods-InteropTestsRemoteWithCronet.a */,
);
name = Frameworks;
sourceTree = "<group>";
@ -242,6 +269,8 @@
E6733B838B28453434B556E2 /* Pods-Tests.release.xcconfig */,
0D2284C3DF7E57F0ED504E39 /* Pods-CoreCronetEnd2EndTests.debug.xcconfig */,
4AD97096D13D7416DC91A72A /* Pods-CoreCronetEnd2EndTests.release.xcconfig */,
17F60BF2871F6AF85FB3FA12 /* Pods-InteropTestsRemoteWithCronet.debug.xcconfig */,
AC414EF7A6BF76ED02B6E480 /* Pods-InteropTestsRemoteWithCronet.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
@ -254,12 +283,22 @@
path = CoreCronetEnd2EndTests;
sourceTree = "<group>";
};
5EE84BF21D4717E40050C6CC /* InteropTestsRemoteWithCronet */ = {
isa = PBXGroup;
children = (
5EE84BF31D4717E40050C6CC /* InteropTestsRemoteWithCronet.m */,
5EE84BF51D4717E40050C6CC /* Info.plist */,
);
path = InteropTestsRemoteWithCronet;
sourceTree = "<group>";
};
635697BE1B14FC11007A7283 = {
isa = PBXGroup;
children = (
635697C91B14FC11007A7283 /* Tests */,
63E240CF1B6C63DC005F3B0E /* TestCertificates.bundle */,
5E8A5DA51D3840B4000F8BC4 /* CoreCronetEnd2EndTests */,
5EE84BF21D4717E40050C6CC /* InteropTestsRemoteWithCronet */,
635697C81B14FC11007A7283 /* Products */,
51E4650F34F854F41FF053B3 /* Pods */,
136D535E19727099B941D7B1 /* Frameworks */,
@ -276,6 +315,7 @@
63DC84341BE15294000708E8 /* InteropTestsLocalSSL.xctest */,
63DC84431BE152B5000708E8 /* InteropTestsLocalCleartext.xctest */,
5E8A5DA41D3840B4000F8BC4 /* CoreCronetEnd2EndTests.xctest */,
5EE84BF11D4717E40050C6CC /* InteropTestsRemoteWithCronet.xctest */,
);
name = Products;
sourceTree = "<group>";
@ -328,6 +368,27 @@
productReference = 5E8A5DA41D3840B4000F8BC4 /* CoreCronetEnd2EndTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
5EE84BF01D4717E40050C6CC /* InteropTestsRemoteWithCronet */ = {
isa = PBXNativeTarget;
buildConfigurationList = 5EE84BFB1D4717E40050C6CC /* Build configuration list for PBXNativeTarget "InteropTestsRemoteWithCronet" */;
buildPhases = (
C0F7B1FF6F88CC5FBF362F4C /* [CP] Check Pods Manifest.lock */,
5EE84BED1D4717E40050C6CC /* Sources */,
5EE84BEE1D4717E40050C6CC /* Frameworks */,
5EE84BEF1D4717E40050C6CC /* Resources */,
31F8D1C407195CBF0C02929B /* [CP] Embed Pods Frameworks */,
DB4D0E73C229F2FF3B364AB3 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
dependencies = (
5EE84BF81D4717E40050C6CC /* PBXTargetDependency */,
);
name = InteropTestsRemoteWithCronet;
productName = InteropTestsRemoteWithCronet;
productReference = 5EE84BF11D4717E40050C6CC /* InteropTestsRemoteWithCronet.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
63423F431B150A5F006CF63C /* AllTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 63423F4D1B150A5F006CF63C /* Build configuration list for PBXNativeTarget "AllTests" */;
@ -464,6 +525,9 @@
5E8A5DA31D3840B4000F8BC4 = {
CreatedOnToolsVersion = 7.3.1;
};
5EE84BF01D4717E40050C6CC = {
CreatedOnToolsVersion = 7.3.1;
};
63423F431B150A5F006CF63C = {
CreatedOnToolsVersion = 6.3.1;
};
@ -503,6 +567,7 @@
63DC84331BE15294000708E8 /* InteropTestsLocalSSL */,
63DC84421BE152B5000708E8 /* InteropTestsLocalCleartext */,
5E8A5DA31D3840B4000F8BC4 /* CoreCronetEnd2EndTests */,
5EE84BF01D4717E40050C6CC /* InteropTestsRemoteWithCronet */,
);
};
/* End PBXProject section */
@ -515,6 +580,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
5EE84BEF1D4717E40050C6CC /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
63423F421B150A5F006CF63C /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
@ -555,6 +627,21 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
31F8D1C407195CBF0C02929B /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-InteropTestsRemoteWithCronet/Pods-InteropTestsRemoteWithCronet-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
4C406327D3907A5E5FBA8AC9 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@ -780,6 +867,21 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
C0F7B1FF6F88CC5FBF362F4C /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
C2E09DC4BD239F71160F0CC1 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@ -825,6 +927,21 @@
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-RxLibraryUnitTests/Pods-RxLibraryUnitTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
DB4D0E73C229F2FF3B364AB3 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-InteropTestsRemoteWithCronet/Pods-InteropTestsRemoteWithCronet-resources.sh\"\n";
showEnvVarsInLog = 0;
};
E63468C760D0724F18861822 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@ -866,6 +983,15 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
5EE84BED1D4717E40050C6CC /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5EE84BFE1D471D400050C6CC /* InteropTests.m in Sources */,
5EE84BF41D4717E40050C6CC /* InteropTestsRemoteWithCronet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
63423F401B150A5F006CF63C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@ -931,6 +1057,11 @@
target = 635697C61B14FC11007A7283 /* Tests */;
targetProxy = 5E8A5DAA1D3840B4000F8BC4 /* PBXContainerItemProxy */;
};
5EE84BF81D4717E40050C6CC /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 635697C61B14FC11007A7283 /* Tests */;
targetProxy = 5EE84BF71D4717E40050C6CC /* PBXContainerItemProxy */;
};
63423F4C1B150A5F006CF63C /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 635697C61B14FC11007A7283 /* Tests */;
@ -991,6 +1122,50 @@
};
name = Release;
};
5EE84BF91D4717E40050C6CC /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 17F60BF2871F6AF85FB3FA12 /* Pods-InteropTestsRemoteWithCronet.debug.xcconfig */;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_TESTABILITY = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"COCOAPODS=1",
"$(inherited)",
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1",
"GRPC_COMPILE_WITH_CRONET=1",
);
INFOPLIST_FILE = InteropTestsRemoteWithCronet/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.grpc.InteropTestsRemoteWithCronet;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
5EE84BFA1D4717E40050C6CC /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AC414EF7A6BF76ED02B6E480 /* Pods-InteropTestsRemoteWithCronet.release.xcconfig */;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"COCOAPODS=1",
"$(inherited)",
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1",
"GRPC_COMPILE_WITH_CRONET=1",
);
INFOPLIST_FILE = InteropTestsRemoteWithCronet/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.grpc.InteropTestsRemoteWithCronet;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
63423F4E1B150A5F006CF63C /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = B94C27C06733CF98CE1B2757 /* Pods-AllTests.debug.xcconfig */;
@ -1239,6 +1414,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
5EE84BFB1D4717E40050C6CC /* Build configuration list for PBXNativeTarget "InteropTestsRemoteWithCronet" */ = {
isa = XCConfigurationList;
buildConfigurations = (
5EE84BF91D4717E40050C6CC /* Debug */,
5EE84BFA1D4717E40050C6CC /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
63423F4D1B150A5F006CF63C /* Build configuration list for PBXNativeTarget "AllTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EE84BF01D4717E40050C6CC"
BuildableName = "InteropTestsRemoteWithCronet.xctest"
BlueprintName = "InteropTestsRemoteWithCronet"
ReferencedContainer = "container:Tests.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EE84BF01D4717E40050C6CC"
BuildableName = "InteropTestsRemoteWithCronet.xctest"
BlueprintName = "InteropTestsRemoteWithCronet"
ReferencedContainer = "container:Tests.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "InteropTests">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EE84BF01D4717E40050C6CC"
BuildableName = "InteropTestsRemoteWithCronet.xctest"
BlueprintName = "InteropTestsRemoteWithCronet"
ReferencedContainer = "container:Tests.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EE84BF01D4717E40050C6CC"
BuildableName = "InteropTestsRemoteWithCronet.xctest"
BlueprintName = "InteropTestsRemoteWithCronet"
ReferencedContainer = "container:Tests.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5EE84BF01D4717E40050C6CC"
BuildableName = "InteropTestsRemoteWithCronet.xctest"
BlueprintName = "InteropTestsRemoteWithCronet"
ReferencedContainer = "container:Tests.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

@ -9,23 +9,12 @@ GA
## Environment
Prerequisite: `php` >=5.5, `phpize`, `pecl`, `phpunit`
**Linux (Debian):**
```sh
$ sudo apt-get install php5 php5-dev php-pear
```
**Linux (CentOS):**
```sh
$ yum install php55w
$ yum --enablerepo=remi,remi-php55 install php-devel php-pear
```
**Mac OS X:**
Prerequisite:
* `php` 5.5 or above, 7.0 or above
* `pear` and `pecl`
* `phpunit`
**PEAR:**
```sh
$ curl -O http://pear.php.net/go-pear.phar
$ sudo php -d detect_unicode=0 go-pear.phar
@ -72,13 +61,7 @@ $ sudo make install
### gRPC PHP extension
Install the gRPC PHP extension from PECL
```sh
$ sudo pecl install grpc
```
Or, compile from source
Compile the gRPC PHP extension
```sh
$ cd grpc/src/php/ext/grpc
@ -148,12 +131,8 @@ Alternatively, you can download `protoc` binaries from [the protocol buffers Git
You need to install `protoc-gen-php` to generate stub class `.php` files from service definition `.proto` files.
```sh
$ cd grpc/src/php/vendor/stanley-cheung/protobuf-php # if you had run `composer install` in the previous step
OR
$ git clone https://github.com/stanley-cheung/Protobuf-PHP # clone from github repo
$ git clone https://github.com/stanley-cheung/Protobuf-PHP
$ cd Protobuf-PHP
$ gem install rake ronn
$ rake pear:package version=1.0
$ sudo pear install Protobuf-1.0.tgz
@ -175,7 +154,7 @@ Run a local server serving the math services. Please see [Node][] for how to run
```sh
$ cd grpc
$ npm install
$ nodejs src/node/test/math/math_server.js
$ node src/node/test/math/math_server.js
```
### Run test client
@ -212,7 +191,7 @@ Make sure the Node math server is still running, as above.
```sh
$ cd grpc
$ npm install
$ nodejs src/node/test/math/math_server.js
$ node src/node/test/math/math_server.js
```
Make sure you have run `composer install` to generate the `vendor/autoload.php` file
@ -282,7 +261,7 @@ Make sure the Node math server is still running, as above.
```sh
$ cd grpc
$ npm install
$ nodejs src/node/test/math/math_server.js
$ node src/node/test/math/math_server.js
```
Make sure you have run `composer install` to generate the `vendor/autoload.php` file

@ -29,11 +29,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
default_extension_dir=$(php-config --extension-dir)
if command -v brew > /dev/null && \
brew ls --versions | grep php5[56]-grpc > /dev/null; then
# the grpc php extension was installed by homebrew
:
elif [ ! -e $default_extension_dir/grpc.so ]; then
if [ ! -e $default_extension_dir/grpc.so ]; then
# the grpc extension is not found in the default PHP extension dir
# try the source modules directory
module_dir=../ext/grpc/modules

@ -8,7 +8,9 @@
"version": "1.0.0",
"require": {
"php": ">=5.5.0",
"stanley-cheung/protobuf-php": "v0.6",
"stanley-cheung/protobuf-php": "v0.6"
},
"require-dev": {
"google/auth": "v0.9"
},
"autoload": {

@ -90,34 +90,54 @@ zend_object_value create_wrapped_grpc_call(zend_class_entry *class_type
return retval;
}
/* 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 TSRMLS_DC) {
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->owned = owned;
return call_object;
#else
static zend_object_handlers call_ce_handlers;
/* Frees and destroys an instance of wrapped_grpc_call */
static void free_wrapped_grpc_call(zend_object *object) {
wrapped_grpc_call *call = wrapped_grpc_call_from_obj(object);
if (call->owned && call->wrapped != NULL) {
grpc_call_destroy(call->wrapped);
}
zend_object_std_dtor(&call->std);
}
/* Initializes an instance of wrapped_grpc_call to be associated with an
* object of a class specified by class_type */
zend_object *create_wrapped_grpc_call(zend_class_entry *class_type) {
wrapped_grpc_call *intern;
intern = ecalloc(1, sizeof(wrapped_grpc_call) +
zend_object_properties_size(class_type));
zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);
intern->std.handlers = &call_ce_handlers;
return &intern->std;
}
#endif
/* 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 TSRMLS_DC) {
zval *grpc_parse_metadata_array(grpc_metadata_array
*metadata_array TSRMLS_DC) {
int count = metadata_array->count;
grpc_metadata *elements = metadata_array->metadata;
int i;
zval *array;
zval **data = NULL;
PHP_GRPC_MAKE_STD_ZVAL(array);
array_init(array);
int i;
HashTable *array_hash;
zval *inner_array;
char *str_key;
char *str_val;
size_t key_len;
MAKE_STD_ZVAL(array);
array_init(array);
#if PHP_MAJOR_VERSION < 7
zval **data = NULL;
#else
zval *data;
#endif
array_hash = Z_ARRVAL_P(array);
grpc_metadata *elem;
for (i = 0; i < count; i++) {
@ -127,9 +147,14 @@ zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC) {
memcpy(str_key, elem->key, key_len);
str_val = ecalloc(elem->value_length + 1, sizeof(char));
memcpy(str_val, elem->value, elem->value_length);
#if PHP_MAJOR_VERSION < 7
if (zend_hash_find(array_hash, str_key, key_len, (void **)data) ==
SUCCESS) {
if (Z_TYPE_P(*data) != IS_ARRAY) {
#else
if ((data = zend_hash_str_find(array_hash, str_key, key_len)) != NULL) {
if (Z_TYPE_P(data) != IS_ARRAY) {
#endif
zend_throw_exception(zend_exception_get_default(TSRMLS_C),
"Metadata hash somehow contains wrong types.",
1 TSRMLS_CC);
@ -137,11 +162,18 @@ zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC) {
efree(str_val);
return NULL;
}
add_next_index_stringl(*data, str_val, elem->value_length, false);
#if PHP_MAJOR_VERSION < 7
php_grpc_add_next_index_stringl(*data, str_val, elem->value_length,
false);
#else
php_grpc_add_next_index_stringl(data, str_val, elem->value_length,
false);
#endif
} else {
MAKE_STD_ZVAL(inner_array);
PHP_GRPC_MAKE_STD_ZVAL(inner_array);
array_init(inner_array);
add_next_index_stringl(inner_array, str_val, elem->value_length, false);
php_grpc_add_next_index_stringl(inner_array, str_val,
elem->value_length, false);
add_assoc_zval(array, str_key, inner_array);
}
}
@ -151,20 +183,27 @@ zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC) {
/* 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) {
HashTable *array_hash;
HashTable *inner_array_hash;
#if PHP_MAJOR_VERSION < 7
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;
#else
zval *inner_array;
zval *value;
zend_string *key;
#endif
if (Z_TYPE_P(array) != IS_ARRAY) {
return false;
}
grpc_metadata_array_init(metadata);
array_hash = Z_ARRVAL_P(array);
#if PHP_MAJOR_VERSION < 7
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;
@ -179,7 +218,22 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
inner_array_hash = Z_ARRVAL_P(*inner_array);
metadata->capacity += zend_hash_num_elements(inner_array_hash);
}
#else
ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, inner_array) {
if (key == NULL) {
return false;
}
if (Z_TYPE_P(inner_array) != IS_ARRAY) {
return false;
}
inner_array_hash = HASH_OF(inner_array);
metadata->capacity += zend_hash_num_elements(inner_array_hash);
} ZEND_HASH_FOREACH_END();
#endif
metadata->metadata = gpr_malloc(metadata->capacity * sizeof(grpc_metadata));
#if PHP_MAJOR_VERSION < 7
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;
@ -203,113 +257,7 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
metadata->count += 1;
}
}
return true;
}
#else
static zend_object_handlers call_ce_handlers;
/* Frees and destroys an instance of wrapped_grpc_call */
static void free_wrapped_grpc_call(zend_object *object) {
wrapped_grpc_call *call = wrapped_grpc_call_from_obj(object);
if (call->owned && call->wrapped != NULL) {
grpc_call_destroy(call->wrapped);
}
zend_object_std_dtor(&call->std);
}
/* Initializes an instance of wrapped_grpc_call to be associated with an
* object of a class specified by class_type */
zend_object *create_wrapped_grpc_call(zend_class_entry *class_type) {
wrapped_grpc_call *intern;
intern = ecalloc(1, sizeof(wrapped_grpc_call) +
zend_object_properties_size(class_type));
zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);
intern->std.handlers = &call_ce_handlers;
return &intern->std;
}
/* 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 */
void grpc_php_wrap_call(grpc_call *wrapped, bool owned, zval *call_object) {
object_init_ex(call_object, grpc_ce_call);
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(call_object);
call->wrapped = wrapped;
call->owned = owned;
}
/* Creates and returns a PHP array object with the data in a
* grpc_metadata_array. Returns NULL on failure */
void grpc_parse_metadata_array(grpc_metadata_array *metadata_array,
zval *array) {
int count = metadata_array->count;
grpc_metadata *elements = metadata_array->metadata;
int i;
zval *data;
HashTable *array_hash;
zval inner_array;
char *str_key;
char *str_val;
size_t key_len;
array_init(array);
array_hash = HASH_OF(array);
grpc_metadata *elem;
for (i = 0; i < count; i++) {
elem = &elements[i];
key_len = strlen(elem->key);
str_key = ecalloc(key_len + 1, sizeof(char));
memcpy(str_key, elem->key, key_len);
str_val = ecalloc(elem->value_length + 1, sizeof(char));
memcpy(str_val, elem->value, elem->value_length);
if ((data = zend_hash_str_find(array_hash, str_key, key_len)) != NULL) {
if (Z_TYPE_P(data) != IS_ARRAY) {
zend_throw_exception(zend_exception_get_default(),
"Metadata hash somehow contains wrong types.",
1);
efree(str_key);
efree(str_val);
return;
}
add_next_index_stringl(data, str_val, elem->value_length);
} else {
array_init(&inner_array);
add_next_index_stringl(&inner_array, str_val, elem->value_length);
add_assoc_zval(array, str_key, &inner_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;
HashTable *inner_array_hash;
zend_string *key;
if (Z_TYPE_P(array) != IS_ARRAY) {
return false;
}
grpc_metadata_array_init(metadata);
array_hash = HASH_OF(array);
ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, inner_array) {
if (key == NULL) {
return false;
}
if (Z_TYPE_P(inner_array) != IS_ARRAY) {
return false;
}
inner_array_hash = HASH_OF(inner_array);
metadata->capacity += zend_hash_num_elements(inner_array_hash);
}
ZEND_HASH_FOREACH_END();
metadata->metadata = gpr_malloc(metadata->capacity * sizeof(grpc_metadata));
ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, inner_array) {
if (key == NULL) {
return false;
@ -326,10 +274,21 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
metadata->count += 1;
} ZEND_HASH_FOREACH_END();
} ZEND_HASH_FOREACH_END();
#endif
return true;
}
#endif
/* 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 TSRMLS_DC) {
zval *call_object;
PHP_GRPC_MAKE_STD_ZVAL(call_object);
object_init_ex(call_object, grpc_ce_call);
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(call_object);
call->wrapped = wrapped;
call->owned = owned;
return call_object;
}
/**
* Constructs a new instance of the Call class.
@ -341,18 +300,11 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
PHP_METHOD(Call, __construct) {
zval *channel_obj;
char *method;
php_grpc_int method_len;
zval *deadline_obj;
char *host_override = NULL;
#if PHP_MAJOR_VERSION < 7
int method_len;
int host_override_len = 0;
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
size_t method_len;
size_t host_override_len = 0;
php_grpc_int host_override_len = 0;
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
#endif
/* "OsO|s" == 1 Object, 1 string, 1 Object, 1 optional string */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OsO|s", &channel_obj,
@ -364,13 +316,7 @@ PHP_METHOD(Call, __construct) {
"an optional String", 1 TSRMLS_CC);
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(
channel_obj TSRMLS_CC);
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(channel_obj);
#endif
if (channel->wrapped == NULL) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"Call cannot be constructed from a closed Channel",
@ -378,13 +324,7 @@ PHP_METHOD(Call, __construct) {
return;
}
add_property_zval(getThis(), "channel", channel_obj);
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *deadline =
(wrapped_grpc_timeval *)zend_object_store_get_object(
deadline_obj TSRMLS_CC);
#else
wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj);
#endif
call->wrapped =
grpc_channel_create_call(channel->wrapped, NULL, GRPC_PROPAGATE_DEFAULTS,
completion_queue, method, host_override,
@ -398,9 +338,11 @@ PHP_METHOD(Call, __construct) {
* @return object Object with results of all actions
*/
PHP_METHOD(Call, startBatch) {
zval *result;
PHP_GRPC_MAKE_STD_ZVAL(result);
object_init(result);
php_grpc_ulong index;
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
zval **value;
zval **inner_value;
HashPosition array_pointer;
@ -408,22 +350,16 @@ PHP_METHOD(Call, startBatch) {
zval **message_flags;
char *key;
uint key_len;
ulong index;
zval *result;
zval *recv_status;
MAKE_STD_ZVAL(result);
object_init(result);
#else
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
zval *value;
zval *inner_value;
zval *message_value;
zval *message_flags;
zend_string *key;
zend_ulong index;
zval recv_status;
object_init(return_value);
#endif
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
grpc_op ops[8];
size_t op_num = 0;
@ -595,7 +531,7 @@ PHP_METHOD(Call, startBatch) {
#else
array_hash = HASH_OF(array);
array_hash = HASH_OF(array);
ZEND_HASH_FOREACH_KEY_VAL(array_hash, index, key, value) {
if (key) {
zend_throw_exception(spl_ce_InvalidArgumentException,
@ -713,8 +649,7 @@ array_hash = HASH_OF(array);
ops[op_num].flags = 0;
ops[op_num].reserved = NULL;
op_num++;
}
ZEND_HASH_FOREACH_END();
} ZEND_HASH_FOREACH_END();
#endif
@ -776,43 +711,44 @@ array_hash = HASH_OF(array);
}
}
#else
zval recv_md;
for (int i = 0; i < op_num; i++) {
switch(ops[i].op) {
case GRPC_OP_SEND_INITIAL_METADATA:
add_property_bool(return_value, "send_metadata", true);
add_property_bool(result, "send_metadata", true);
break;
case GRPC_OP_SEND_MESSAGE:
add_property_bool(return_value, "send_message", true);
add_property_bool(result, "send_message", true);
break;
case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
add_property_bool(return_value, "send_close", true);
add_property_bool(result, "send_close", true);
break;
case GRPC_OP_SEND_STATUS_FROM_SERVER:
add_property_bool(return_value, "send_status", true);
add_property_bool(result, "send_status", true);
break;
case GRPC_OP_RECV_INITIAL_METADATA:
grpc_parse_metadata_array(&recv_metadata, array);
add_property_zval(return_value, "metadata", array);
recv_md = *grpc_parse_metadata_array(&recv_metadata);
add_property_zval(result, "metadata", &recv_md);
break;
case GRPC_OP_RECV_MESSAGE:
byte_buffer_to_string(message, &message_str, &message_len);
if (message_str == NULL) {
add_property_null(return_value, "message");
add_property_null(result, "message");
} else {
add_property_stringl(return_value, "message", message_str,
add_property_stringl(result, "message", message_str,
message_len);
}
break;
case GRPC_OP_RECV_STATUS_ON_CLIENT:
object_init(&recv_status);
grpc_parse_metadata_array(&recv_trailing_metadata, array);
add_property_zval(&recv_status, "metadata", array);
recv_md = *grpc_parse_metadata_array(&recv_trailing_metadata);
add_property_zval(&recv_status, "metadata", &recv_md);
add_property_long(&recv_status, "code", status);
add_property_string(&recv_status, "details", status_details);
add_property_zval(return_value, "status", &recv_status);
add_property_zval(result, "status", &recv_status);
break;
case GRPC_OP_RECV_CLOSE_ON_SERVER:
add_property_bool(return_value, "cancelled", cancelled);
add_property_bool(result, "cancelled", cancelled);
break;
default:
break;
@ -836,11 +772,7 @@ cleanup:
grpc_byte_buffer_destroy(message);
}
}
#if PHP_MAJOR_VERSION < 7
RETURN_DESTROY_ZVAL(result);
#else
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -848,14 +780,8 @@ cleanup:
* @return string The URI of the endpoint
*/
PHP_METHOD(Call, getPeer) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
RETURN_STRING(grpc_call_get_peer(call->wrapped), 1);
#else
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
RETURN_STRING(grpc_call_get_peer(call->wrapped));
#endif
PHP_GRPC_RETURN_STRING(grpc_call_get_peer(call->wrapped), 1);
}
/**
@ -863,12 +789,7 @@ PHP_METHOD(Call, getPeer) {
* has not already ended with another status.
*/
PHP_METHOD(Call, cancel) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
#endif
grpc_call_cancel(call->wrapped, NULL);
}
@ -889,17 +810,9 @@ PHP_METHOD(Call, setCredentials) {
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_call_credentials *creds =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
creds_obj TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_call_credentials *creds =
Z_WRAPPED_GRPC_CALL_CREDS_P(creds_obj);
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
#endif
grpc_call_error error = GRPC_CALL_ERROR;
error = grpc_call_set_credentials(call->wrapped, creds->wrapped);

@ -48,31 +48,19 @@
/* Class entry for the Call PHP class */
extern zend_class_entry *grpc_ce_call;
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_call that can be associated with a PHP object */
typedef struct wrapped_grpc_call {
zend_object std;
PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_call)
bool owned;
grpc_call *wrapped;
} wrapped_grpc_call;
PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call)
/* Creates a Call object that wraps the given grpc_call struct */
zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC);
#if PHP_MAJOR_VERSION < 7
/* Creates and returns a PHP associative array of metadata from a C array of
* call metadata */
zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC);
#define Z_WRAPPED_GRPC_CALL_P(zv) \
(wrapped_grpc_call *)zend_object_store_get_object(zv TSRMLS_CC)
#else
/* Wrapper struct for grpc_call that can be associated with a PHP object */
typedef struct wrapped_grpc_call {
bool owned;
grpc_call *wrapped;
zend_object std;
} wrapped_grpc_call;
static inline wrapped_grpc_call
*wrapped_grpc_call_from_obj(zend_object *obj) {
return (wrapped_grpc_call*)((char*)(obj) -
@ -81,15 +69,14 @@ static inline wrapped_grpc_call
#define Z_WRAPPED_GRPC_CALL_P(zv) wrapped_grpc_call_from_obj(Z_OBJ_P((zv)))
/* Creates a Call object that wraps the given grpc_call struct */
void grpc_php_wrap_call(grpc_call *wrapped, bool owned, zval *call_object);
#endif /* PHP_MAJOR_VERSION */
/* Creates and returns a PHP associative array of metadata from a C array of
* call metadata */
void grpc_parse_metadata_array(grpc_metadata_array *metadata_array,
zval *array);
zval *grpc_parse_metadata_array(grpc_metadata_array *metadata_array TSRMLS_DC);
#endif /* PHP_MAJOR_VERSION */
/* Creates a Call object that wraps the given grpc_call struct */
zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC);
/* Initializes the Call PHP class */
void grpc_init_call(TSRMLS_D);

@ -86,17 +86,6 @@ zend_object_value create_wrapped_grpc_call_credentials(
return retval;
}
zval *grpc_php_wrap_call_credentials(grpc_call_credentials *wrapped TSRMLS_DC) {
zval *credentials_object;
MAKE_STD_ZVAL(credentials_object);
object_init_ex(credentials_object, grpc_ce_call_credentials);
wrapped_grpc_call_credentials *credentials =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
credentials_object TSRMLS_CC);
credentials->wrapped = wrapped;
return credentials_object;
}
#else
static zend_object_handlers call_credentials_ce_handlers;
@ -124,16 +113,19 @@ zend_object *create_wrapped_grpc_call_credentials(zend_class_entry
return &intern->std;
}
void grpc_php_wrap_call_credentials(grpc_call_credentials *wrapped,
zval *credentials_object) {
#endif
zval *grpc_php_wrap_call_credentials(grpc_call_credentials
*wrapped TSRMLS_DC) {
zval *credentials_object;
PHP_GRPC_MAKE_STD_ZVAL(credentials_object);
object_init_ex(credentials_object, grpc_ce_call_credentials);
wrapped_grpc_call_credentials *credentials =
Z_WRAPPED_GRPC_CALL_CREDS_P(credentials_object);
credentials->wrapped = wrapped;
return credentials_object;
}
#endif
/**
* Create composite credentials from two existing credentials.
* @param CallCredentials cred1 The first credential
@ -153,29 +145,17 @@ PHP_METHOD(CallCredentials, createComposite) {
1 TSRMLS_CC);
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_call_credentials *cred1 =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
cred1_obj TSRMLS_CC);
Z_WRAPPED_GRPC_CALL_CREDS_P(cred1_obj);
wrapped_grpc_call_credentials *cred2 =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
cred2_obj TSRMLS_CC);
Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj);
grpc_call_credentials *creds =
grpc_composite_call_credentials_create(cred1->wrapped, cred2->wrapped,
NULL);
zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC);
zval *creds_object;
PHP_GRPC_MAKE_STD_ZVAL(creds_object);
creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC);
RETURN_DESTROY_ZVAL(creds_object);
#else
wrapped_grpc_call_credentials *cred1 =
Z_WRAPPED_GRPC_CALL_CREDS_P(cred1_obj);
wrapped_grpc_call_credentials *cred2 =
Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj);
grpc_call_credentials *creds =
grpc_composite_call_credentials_create(cred1->wrapped,
cred2->wrapped, NULL);
grpc_php_wrap_call_credentials(creds, return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -216,13 +196,10 @@ PHP_METHOD(CallCredentials, createFromPlugin) {
grpc_call_credentials *creds =
grpc_metadata_credentials_create_from_plugin(plugin, NULL);
#if PHP_MAJOR_VERSION < 7
zval *creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC);
zval *creds_object;
PHP_GRPC_MAKE_STD_ZVAL(creds_object);
creds_object = grpc_php_wrap_call_credentials(creds TSRMLS_CC);
RETURN_DESTROY_ZVAL(creds_object);
#else
grpc_php_wrap_call_credentials(creds, return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/* Callback function for plugin creds API */
@ -235,37 +212,28 @@ void plugin_get_metadata(void *ptr, grpc_auth_metadata_context context,
/* prepare to call the user callback function with info from the
* grpc_auth_metadata_context */
#if PHP_MAJOR_VERSION < 7
zval **params[1];
zval *arg;
zval *retval;
MAKE_STD_ZVAL(arg);
PHP_GRPC_MAKE_STD_ZVAL(arg);
object_init(arg);
add_property_string(arg, "service_url", context.service_url, true);
add_property_string(arg, "method_name", context.method_name, true);
php_grpc_add_property_string(arg, "service_url", context.service_url, true);
php_grpc_add_property_string(arg, "method_name", context.method_name, true);
zval *retval;
PHP_GRPC_MAKE_STD_ZVAL(retval);
#if PHP_MAJOR_VERSION < 7
zval **params[1];
params[0] = &arg;
state->fci->param_count = 1;
state->fci->params = params;
state->fci->retval_ptr_ptr = &retval;
#else
zval arg;
zval retval;
object_init(&arg);
add_property_string(&arg, "service_url", context.service_url);
add_property_string(&arg, "method_name", context.method_name);
state->fci->param_count = 1;
state->fci->params = &arg;
state->fci->retval = &retval;
state->fci->params = arg;
state->fci->retval = retval;
#endif
state->fci->param_count = 1;
/* call the user callback function */
zend_call_function(state->fci, state->fci_cache TSRMLS_CC);
#if PHP_MAJOR_VERSION < 7
if (Z_TYPE_P(retval) != IS_ARRAY) {
#else
if (Z_TYPE_P(&retval) != IS_ARRAY) {
#endif
zend_throw_exception(spl_ce_InvalidArgumentException,
"plugin callback must return metadata array",
1 TSRMLS_CC);
@ -273,11 +241,7 @@ void plugin_get_metadata(void *ptr, grpc_auth_metadata_context context,
}
grpc_metadata_array metadata;
#if PHP_MAJOR_VERSION < 7
if (!create_metadata_array(retval, &metadata)) {
#else
if (!create_metadata_array(&retval, &metadata)) {
#endif
zend_throw_exception(spl_ce_InvalidArgumentException,
"invalid metadata", 1 TSRMLS_CC);
grpc_metadata_array_destroy(&metadata);

@ -49,23 +49,18 @@
/* Class entry for the CallCredentials PHP class */
extern zend_class_entry *grpc_ce_call_credentials;
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_call_credentials that can be associated
* with a PHP object */
typedef struct wrapped_grpc_call_credentials {
zend_object std;
PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_call_credentials)
grpc_call_credentials *wrapped;
} wrapped_grpc_call_credentials;
PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_call_credentials)
#else
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_call_credentials that can be associated
* with a PHP object */
typedef struct wrapped_grpc_call_credentials {
grpc_call_credentials *wrapped;
zend_object std;
} wrapped_grpc_call_credentials;
#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \
(wrapped_grpc_call_credentials *)zend_object_store_get_object(zv TSRMLS_CC)
#else
static inline wrapped_grpc_call_credentials
*wrapped_grpc_call_creds_from_obj(zend_object *obj) {
@ -75,7 +70,7 @@ static inline wrapped_grpc_call_credentials
std));
}
#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \
#define Z_WRAPPED_GRPC_CALL_CREDS_P(zv) \
wrapped_grpc_call_creds_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */

@ -86,19 +86,58 @@ zend_object_value create_wrapped_grpc_channel(zend_class_entry *class_type
return retval;
}
#else
static zend_object_handlers channel_ce_handlers;
/* Frees and destroys an instance of wrapped_grpc_channel */
static void free_wrapped_grpc_channel(zend_object *object) {
wrapped_grpc_channel *channel = wrapped_grpc_channel_from_obj(object);
if (channel->wrapped != NULL) {
grpc_channel_destroy(channel->wrapped);
}
zend_object_std_dtor(&channel->std);
}
/* Initializes an instance of wrapped_grpc_channel to be associated with an
* object of a class specified by class_type */
zend_object *create_wrapped_grpc_channel(zend_class_entry *class_type) {
wrapped_grpc_channel *intern;
intern = ecalloc(1, sizeof(wrapped_grpc_channel) +
zend_object_properties_size(class_type));
zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);
intern->std.handlers = &channel_ce_handlers;
return &intern->std;
}
#endif
void php_grpc_read_args_array(zval *args_array,
grpc_channel_args *args TSRMLS_DC) {
HashTable *array_hash;
HashPosition array_pointer;
int args_index;
#if PHP_MAJOR_VERSION < 7
HashPosition array_pointer;
zval **data;
char *key;
uint key_len;
ulong index;
#else
zval *data;
zend_string *key;
#endif
array_hash = Z_ARRVAL_P(args_array);
if (!array_hash) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"array_hash is NULL", 1);
return;
}
args->num_args = zend_hash_num_elements(array_hash);
args->args = ecalloc(args->num_args, sizeof(grpc_arg));
args_index = 0;
#if PHP_MAJOR_VERSION < 7
for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer);
zend_hash_get_current_data_ex(array_hash, (void **)&data,
&array_pointer) == SUCCESS;
@ -126,47 +165,7 @@ void php_grpc_read_args_array(zval *args_array,
}
args_index++;
}
}
#else
static zend_object_handlers channel_ce_handlers;
/* Frees and destroys an instance of wrapped_grpc_channel */
static void free_wrapped_grpc_channel(zend_object *object) {
wrapped_grpc_channel *channel = wrapped_grpc_channel_from_obj(object);
if (channel->wrapped != NULL) {
grpc_channel_destroy(channel->wrapped);
}
zend_object_std_dtor(&channel->std);
}
/* Initializes an instance of wrapped_grpc_channel to be associated with an
* object of a class specified by class_type */
zend_object *create_wrapped_grpc_channel(zend_class_entry *class_type) {
wrapped_grpc_channel *intern;
intern = ecalloc(1, sizeof(wrapped_grpc_channel) +
zend_object_properties_size(class_type));
zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);
intern->std.handlers = &channel_ce_handlers;
return &intern->std;
}
void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) {
HashTable *array_hash;
int args_index;
zval *data;
zend_string *key;
array_hash = HASH_OF(args_array);
if (!array_hash) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"array_hash is NULL", 1);
return;
}
args->num_args = zend_hash_num_elements(array_hash);
args->args = ecalloc(args->num_args, sizeof(grpc_arg));
args_index = 0;
ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, data) {
if (key == NULL) {
zend_throw_exception(spl_ce_InvalidArgumentException,
@ -189,9 +188,8 @@ void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) {
}
args_index++;
} ZEND_HASH_FOREACH_END();
}
#endif
}
/**
* Construct an instance of the Channel class. If the $args array contains a
@ -201,18 +199,14 @@ void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) {
* @param array $args The arguments to pass to the Channel (optional)
*/
PHP_METHOD(Channel, __construct) {
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(
getThis() TSRMLS_CC);
zval **creds_obj = NULL;
int target_length;
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
zval *creds_obj = NULL;
size_t target_length;
#endif
char *target;
php_grpc_int target_length;
zval *args_array = NULL;
grpc_channel_args args;
HashTable *array_hash;
@ -277,14 +271,8 @@ PHP_METHOD(Channel, __construct) {
* @return string The URI of the endpoint
*/
PHP_METHOD(Channel, getTarget) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
RETURN_STRING(grpc_channel_get_target(channel->wrapped), 1);
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
RETURN_STRING(grpc_channel_get_target(channel->wrapped));
#endif
PHP_GRPC_RETURN_STRING(grpc_channel_get_target(channel->wrapped), 1);
}
/**
@ -293,12 +281,7 @@ PHP_METHOD(Channel, getTarget) {
* @return long The grpc connectivity state
*/
PHP_METHOD(Channel, getConnectivityState) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
#endif
bool try_to_connect = false;
/* "|b" == 1 optional bool */
@ -320,14 +303,8 @@ PHP_METHOD(Channel, getConnectivityState) {
* before deadline
*/
PHP_METHOD(Channel, watchConnectivityState) {
#if PHP_MAJOR_VERSION < 7
long last_state;
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
zend_long last_state;
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
#endif
php_grpc_long last_state;
zval *deadline_obj;
/* "lO" == 1 long 1 object */
@ -339,13 +316,7 @@ PHP_METHOD(Channel, watchConnectivityState) {
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *deadline =
(wrapped_grpc_timeval *)zend_object_store_get_object(
deadline_obj TSRMLS_CC);
#else
wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj);
#endif
grpc_channel_watch_connectivity_state(channel->wrapped,
(grpc_connectivity_state)last_state,
deadline->wrapped, completion_queue,
@ -360,12 +331,7 @@ PHP_METHOD(Channel, watchConnectivityState) {
* Close the channel
*/
PHP_METHOD(Channel, close) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel *channel =
(wrapped_grpc_channel *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_channel *channel = Z_WRAPPED_GRPC_CHANNEL_P(getThis());
#endif
if (channel->wrapped != NULL) {
grpc_channel_destroy(channel->wrapped);
channel->wrapped = NULL;

@ -48,21 +48,17 @@
/* Class entry for the PHP Channel class */
extern zend_class_entry *grpc_ce_channel;
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_channel that can be associated with a PHP object */
typedef struct wrapped_grpc_channel {
zend_object std;
PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_channel)
grpc_channel *wrapped;
} wrapped_grpc_channel;
PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_channel)
#else
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_channel that can be associated with a PHP object */
typedef struct wrapped_grpc_channel {
grpc_channel *wrapped;
zend_object std;
} wrapped_grpc_channel;
#define Z_WRAPPED_GRPC_CHANNEL_P(zv) \
(wrapped_grpc_channel *)zend_object_store_get_object(zv TSRMLS_CC)
#else
static inline wrapped_grpc_channel
*wrapped_grpc_channel_from_obj(zend_object *obj) {
@ -70,7 +66,7 @@ static inline wrapped_grpc_channel
XtOffsetOf(wrapped_grpc_channel, std));
}
#define Z_WRAPPED_GRPC_CHANNEL_P(zv) \
#define Z_WRAPPED_GRPC_CHANNEL_P(zv) \
wrapped_grpc_channel_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */

@ -96,18 +96,6 @@ zend_object_value create_wrapped_grpc_channel_credentials(
return retval;
}
zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials
*wrapped TSRMLS_DC) {
zval *credentials_object;
MAKE_STD_ZVAL(credentials_object);
object_init_ex(credentials_object, grpc_ce_channel_credentials);
wrapped_grpc_channel_credentials *credentials =
(wrapped_grpc_channel_credentials *)zend_object_store_get_object(
credentials_object TSRMLS_CC);
credentials->wrapped = wrapped;
return credentials_object;
}
#else
static zend_object_handlers channel_credentials_ce_handlers;
@ -135,16 +123,19 @@ zend_object *create_wrapped_grpc_channel_credentials(zend_class_entry
return &intern->std;
}
void grpc_php_wrap_channel_credentials(grpc_channel_credentials *wrapped,
zval *credentials_object) {
#endif
zval *grpc_php_wrap_channel_credentials(grpc_channel_credentials
*wrapped TSRMLS_DC) {
zval *credentials_object;
PHP_GRPC_MAKE_STD_ZVAL(credentials_object);
object_init_ex(credentials_object, grpc_ce_channel_credentials);
wrapped_grpc_channel_credentials *credentials =
Z_WRAPPED_GRPC_CHANNEL_CREDS_P(credentials_object);
credentials->wrapped = wrapped;
return credentials_object;
}
#endif
/**
* Set default roots pem.
* @param string pem_roots PEM encoding of the server root certificates
@ -152,11 +143,7 @@ void grpc_php_wrap_channel_credentials(grpc_channel_credentials *wrapped,
*/
PHP_METHOD(ChannelCredentials, setDefaultRootsPem) {
char *pem_roots;
#if PHP_MAJOR_VERSION < 7
int pem_roots_length;
#else
size_t pem_roots_length;
#endif
php_grpc_int pem_roots_length;
/* "s" == 1 string */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pem_roots,
@ -175,13 +162,10 @@ PHP_METHOD(ChannelCredentials, setDefaultRootsPem) {
*/
PHP_METHOD(ChannelCredentials, createDefault) {
grpc_channel_credentials *creds = grpc_google_default_credentials_create();
#if PHP_MAJOR_VERSION < 7
zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC);
zval *creds_object;
PHP_GRPC_MAKE_STD_ZVAL(creds_object);
creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC);
RETURN_DESTROY_ZVAL(creds_object);
#else
grpc_php_wrap_channel_credentials(creds, return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -197,11 +181,9 @@ PHP_METHOD(ChannelCredentials, createSsl) {
char *pem_root_certs = NULL;
grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
#if PHP_MAJOR_VERSION < 7
int root_certs_length = 0, private_key_length = 0, cert_chain_length = 0;
#else
size_t root_certs_length = 0, private_key_length = 0, cert_chain_length = 0;
#endif
php_grpc_int root_certs_length = 0;
php_grpc_int private_key_length = 0;
php_grpc_int cert_chain_length = 0;
pem_key_cert_pair.private_key = pem_key_cert_pair.cert_chain = NULL;
@ -219,13 +201,10 @@ PHP_METHOD(ChannelCredentials, createSsl) {
grpc_channel_credentials *creds = grpc_ssl_credentials_create(
pem_root_certs,
pem_key_cert_pair.private_key == NULL ? NULL : &pem_key_cert_pair, NULL);
#if PHP_MAJOR_VERSION < 7
zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC);
zval *creds_object;
PHP_GRPC_MAKE_STD_ZVAL(creds_object);
creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC);
RETURN_DESTROY_ZVAL(creds_object);
#else
grpc_php_wrap_channel_credentials(creds, return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -246,29 +225,17 @@ PHP_METHOD(ChannelCredentials, createComposite) {
"createComposite expects 2 Credentials", 1 TSRMLS_CC);
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_channel_credentials *cred1 =
(wrapped_grpc_channel_credentials *)zend_object_store_get_object(
cred1_obj TSRMLS_CC);
Z_WRAPPED_GRPC_CHANNEL_CREDS_P(cred1_obj);
wrapped_grpc_call_credentials *cred2 =
(wrapped_grpc_call_credentials *)zend_object_store_get_object(
cred2_obj TSRMLS_CC);
Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj);
grpc_channel_credentials *creds =
grpc_composite_channel_credentials_create(cred1->wrapped, cred2->wrapped,
NULL);
zval *creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC);
zval *creds_object;
PHP_GRPC_MAKE_STD_ZVAL(creds_object);
creds_object = grpc_php_wrap_channel_credentials(creds TSRMLS_CC);
RETURN_DESTROY_ZVAL(creds_object);
#else
wrapped_grpc_channel_credentials *cred1 =
Z_WRAPPED_GRPC_CHANNEL_CREDS_P(cred1_obj);
wrapped_grpc_call_credentials *cred2 =
Z_WRAPPED_GRPC_CALL_CREDS_P(cred2_obj);
grpc_channel_credentials *creds =
grpc_composite_channel_credentials_create(cred1->wrapped,
cred2->wrapped, NULL);
grpc_php_wrap_channel_credentials(creds, return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**

@ -49,23 +49,18 @@
/* Class entry for the ChannelCredentials PHP class */
extern zend_class_entry *grpc_ce_channel_credentials;
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_channel_credentials that can be associated
* with a PHP object */
typedef struct wrapped_grpc_channel_credentials {
zend_object std;
PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_channel_credentials)
grpc_channel_credentials *wrapped;
} wrapped_grpc_channel_credentials;
PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_channel_credentials)
#else
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_channel_credentials that can be associated
* with a PHP object */
typedef struct wrapped_grpc_channel_credentials {
grpc_channel_credentials *wrapped;
zend_object std;
} wrapped_grpc_channel_credentials;
#define Z_WRAPPED_GRPC_CHANNEL_CREDS_P(zv) \
(wrapped_grpc_channel_credentials *)zend_object_store_get_object(zv TSRMLS_CC)
#else
static inline wrapped_grpc_channel_credentials
*wrapped_grpc_channel_creds_from_obj(zend_object *obj) {
@ -75,7 +70,7 @@ static inline wrapped_grpc_channel_credentials
XtOffsetOf(wrapped_grpc_channel_credentials, std));
}
#define Z_WRAPPED_GRPC_CHANNEL_CREDS_P(zv) \
#define Z_WRAPPED_GRPC_CHANNEL_CREDS_P(zv) \
wrapped_grpc_channel_creds_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */

@ -0,0 +1,84 @@
/*
*
* Copyright 2016, 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 PHP7_WRAPPER_GRPC_H
#define PHP7_WRAPPER_GRPC_H
#if PHP_MAJOR_VERSION < 7
#define php_grpc_int int
#define php_grpc_long long
#define php_grpc_ulong ulong
#define php_grpc_add_property_string(arg, name, context, b) \
add_property_string(arg, name, context, b)
#define php_grpc_add_property_stringl(res, name, str, len, b) \
add_property_stringl(res, name, str, len, b)
#define php_grpc_add_next_index_stringl(data, str, len, b) \
add_next_index_stringl(data, str, len, b)
#define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val, dup)
#define PHP_GRPC_MAKE_STD_ZVAL(pzv) MAKE_STD_ZVAL(pzv)
#define PHP_GRPC_WRAP_OBJECT_START(name) \
typedef struct name { \
zend_object std;
#define PHP_GRPC_WRAP_OBJECT_END(name) \
} name;
#else
#define php_grpc_int size_t
#define php_grpc_long zend_long
#define php_grpc_ulong zend_ulong
#define php_grpc_add_property_string(arg, name, context, b) \
add_property_string(arg, name, context)
#define php_grpc_add_property_stringl(res, name, str, len, b) \
add_property_stringl(res, name, str, len)
#define php_grpc_add_next_index_stringl(data, str, len, b) \
add_next_index_stringl(data, str, len)
#define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val)
#define PHP_GRPC_MAKE_STD_ZVAL(pzv) \
zval _stack_zval_##pzv; \
pzv = &(_stack_zval_##pzv)
#define PHP_GRPC_WRAP_OBJECT_START(name) \
typedef struct name {
#define PHP_GRPC_WRAP_OBJECT_END(name) \
zend_object std; \
} name;
#endif /* PHP_MAJOR_VERSION */
#endif /* PHP7_WRAPPER_GRPC_H */

@ -57,6 +57,8 @@ extern zend_module_entry grpc_module_entry;
#include "php.h"
#include "php7_wrapper.h"
#include "grpc/grpc.h"
#define RETURN_DESTROY_ZVAL(val) \

@ -129,12 +129,7 @@ zend_object *create_wrapped_grpc_server(zend_class_entry *class_type) {
* @param array $args The arguments to pass to the server (optional)
*/
PHP_METHOD(Server, __construct) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#endif
zval *args_array = NULL;
grpc_channel_args args;
@ -172,16 +167,10 @@ PHP_METHOD(Server, requestCall) {
grpc_metadata_array metadata;
grpc_event event;
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
zval *result;
MAKE_STD_ZVAL(result);
PHP_GRPC_MAKE_STD_ZVAL(result);
object_init(result);
#else
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
object_init(return_value);
#endif
grpc_call_details_init(&details);
grpc_metadata_array_init(&metadata);
@ -202,40 +191,32 @@ PHP_METHOD(Server, requestCall) {
1 TSRMLS_CC);
goto cleanup;
}
php_grpc_add_property_string(result, "method", details.method, true);
php_grpc_add_property_string(result, "host", details.host, true);
#if PHP_MAJOR_VERSION < 7
add_property_zval(result, "call", grpc_php_wrap_call(call, true TSRMLS_CC));
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 TSRMLS_CC));
add_property_zval(result, "metadata", grpc_parse_metadata_array(&metadata
TSRMLS_CC));
cleanup:
grpc_call_details_destroy(&details);
grpc_metadata_array_destroy(&metadata);
RETURN_DESTROY_ZVAL(result);
#else
zval zv_call;
zval zv_timeval;
zval zv_md;
grpc_php_wrap_call(call, true, &zv_call);
grpc_php_wrap_timeval(details.deadline, &zv_timeval);
grpc_parse_metadata_array(&metadata, &zv_md);
add_property_zval(return_value, "call", &zv_call);
add_property_string(return_value, "method", details.method);
add_property_string(return_value, "host", details.host);
add_property_zval(return_value, "absolute_deadline", &zv_timeval);
add_property_zval(return_value, "metadata", &zv_md);
//TODO(thinkerou): why use zval* to unit test error?
zv_call = *grpc_php_wrap_call(call, true);
zv_timeval = *grpc_php_wrap_timeval(details.deadline);
zv_md = *grpc_parse_metadata_array(&metadata);
add_property_zval(result, "call", &zv_call);
add_property_zval(result, "absolute_deadline", &zv_timeval);
add_property_zval(result, "metadata", &zv_md);
#endif
cleanup:
grpc_call_details_destroy(&details);
grpc_metadata_array_destroy(&metadata);
RETURN_DESTROY_ZVAL(return_value);
#endif
RETURN_DESTROY_ZVAL(result);
}
/**
@ -245,14 +226,8 @@ cleanup:
*/
PHP_METHOD(Server, addHttp2Port) {
const char *addr;
#if PHP_MAJOR_VERSION < 7
int addr_len;
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
size_t addr_len;
php_grpc_int addr_len;
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#endif
/* "s" == 1 string */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len)
@ -266,15 +241,9 @@ PHP_METHOD(Server, addHttp2Port) {
PHP_METHOD(Server, addSecureHttp2Port) {
const char *addr;
php_grpc_int addr_len;
zval *creds_obj;
#if PHP_MAJOR_VERSION < 7
int addr_len;
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
size_t addr_len;
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#endif
/* "sO" == 1 string, 1 object */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sO", &addr, &addr_len,
@ -285,14 +254,8 @@ PHP_METHOD(Server, addSecureHttp2Port) {
"add_http2_port expects a string and a ServerCredentials", 1 TSRMLS_CC);
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_server_credentials *creds =
(wrapped_grpc_server_credentials *)zend_object_store_get_object(
creds_obj TSRMLS_CC);
#else
wrapped_grpc_server_credentials *creds =
Z_WRAPPED_GRPC_SERVER_CREDS_P(creds_obj);
#endif
RETURN_LONG(grpc_server_add_secure_http2_port(server->wrapped, addr,
creds->wrapped));
}
@ -302,12 +265,7 @@ PHP_METHOD(Server, addSecureHttp2Port) {
* @return Void
*/
PHP_METHOD(Server, start) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_server *server =
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_server *server = Z_WRAPPED_GRPC_SERVER_P(getThis());
#endif
grpc_server_start(server->wrapped);
}

@ -48,21 +48,17 @@
/* Class entry for the Server PHP class */
extern zend_class_entry *grpc_ce_server;
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_server that can be associated with a PHP object */
typedef struct wrapped_grpc_server {
zend_object std;
PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_server)
grpc_server *wrapped;
} wrapped_grpc_server;
PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_server)
#else
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_server that can be associated with a PHP object */
typedef struct wrapped_grpc_server {
grpc_server *wrapped;
zend_object std;
} wrapped_grpc_server;
#define Z_WRAPPED_GRPC_SERVER_P(zv) \
(wrapped_grpc_server *)zend_object_store_get_object(zv TSRMLS_CC)
#else
static inline wrapped_grpc_server
*wrapped_grpc_server_from_obj(zend_object *obj) {
@ -70,7 +66,7 @@ static inline wrapped_grpc_server
XtOffsetOf(wrapped_grpc_server, std));
}
#define Z_WRAPPED_GRPC_SERVER_P(zv) \
#define Z_WRAPPED_GRPC_SERVER_P(zv) \
wrapped_grpc_server_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */

@ -84,18 +84,6 @@ zend_object_value create_wrapped_grpc_server_credentials(
return retval;
}
zval *grpc_php_wrap_server_credentials(grpc_server_credentials
*wrapped TSRMLS_DC) {
zval *server_credentials_object;
MAKE_STD_ZVAL(server_credentials_object);
object_init_ex(server_credentials_object, grpc_ce_server_credentials);
wrapped_grpc_server_credentials *server_credentials =
(wrapped_grpc_server_credentials *)zend_object_store_get_object(
server_credentials_object TSRMLS_CC);
server_credentials->wrapped = wrapped;
return server_credentials_object;
}
#else
static zend_object_handlers server_credentials_ce_handlers;
@ -123,16 +111,19 @@ zend_object *create_wrapped_grpc_server_credentials(zend_class_entry
return &intern->std;
}
void grpc_php_wrap_server_credentials(grpc_server_credentials *wrapped,
zval *server_credentials_object) {
#endif
zval *grpc_php_wrap_server_credentials(grpc_server_credentials
*wrapped TSRMLS_DC) {
zval *server_credentials_object;
PHP_GRPC_MAKE_STD_ZVAL(server_credentials_object);
object_init_ex(server_credentials_object, grpc_ce_server_credentials);
wrapped_grpc_server_credentials *server_credentials =
Z_WRAPPED_GRPC_SERVER_CREDS_P(server_credentials_object);
server_credentials->wrapped = wrapped;
return server_credentials_object;
}
#endif
/**
* Create SSL credentials.
* @param string pem_root_certs PEM encoding of the server root certificates
@ -144,11 +135,9 @@ PHP_METHOD(ServerCredentials, createSsl) {
char *pem_root_certs = 0;
grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
#if PHP_MAJOR_VERSION < 7
int root_certs_length = 0, private_key_length, cert_chain_length;
#else
size_t root_certs_length = 0, private_key_length, cert_chain_length;
#endif
php_grpc_int root_certs_length = 0;
php_grpc_int private_key_length;
php_grpc_int cert_chain_length;
/* "s!ss" == 1 nullable string, 2 strings */
/* TODO: support multiple key cert pairs. */
@ -165,13 +154,10 @@ PHP_METHOD(ServerCredentials, createSsl) {
grpc_server_credentials *creds = grpc_ssl_server_credentials_create_ex(
pem_root_certs, &pem_key_cert_pair, 1,
GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, NULL);
#if PHP_MAJOR_VERSION < 7
zval *creds_object = grpc_php_wrap_server_credentials(creds TSRMLS_CC);
zval *creds_object;
PHP_GRPC_MAKE_STD_ZVAL(creds_object);
creds_object = grpc_php_wrap_server_credentials(creds TSRMLS_CC);
RETURN_DESTROY_ZVAL(creds_object);
#else
grpc_php_wrap_server_credentials(creds, return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
static zend_function_entry server_credentials_methods[] = {

@ -49,30 +49,26 @@
/* Class entry for the Server_Credentials PHP class */
extern zend_class_entry *grpc_ce_server_credentials;
#if PHP_MAJOR_VERSION < 7
/* Wrapper struct for grpc_server_credentials that can be associated with a PHP
* object */
typedef struct wrapped_grpc_server_credentials {
zend_object std;
PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_server_credentials)
grpc_server_credentials *wrapped;
} wrapped_grpc_server_credentials;
PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_server_credentials)
#else
#if PHP_MAJOR_VERSION < 7
typedef struct wrapped_grpc_server_credentials {
grpc_server_credentials *wrapped;
zend_object std;
} wrapped_grpc_server_credentials;
#define Z_WRAPPED_GRPC_SERVER_CREDS_P(zv) \
(wrapped_grpc_server_credentials *)zend_object_store_get_object(zv TSRMLS_CC)
#else
static inline wrapped_grpc_server_credentials
*wrapped_grpc_server_creds_from_obj(zend_object *obj) {
return (wrapped_grpc_server_credentials*)
((char*)(obj) -
XtOffsetOf(wrapped_grpc_server_credentials, std));
((char*)(obj) - XtOffsetOf(wrapped_grpc_server_credentials, std));
}
#define Z_WRAPPED_GRPC_SERVER_CREDS_P(zv) \
#define Z_WRAPPED_GRPC_SERVER_CREDS_P(zv) \
wrapped_grpc_server_creds_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */

@ -56,9 +56,9 @@ zend_class_entry *grpc_ce_timeval;
/* Frees and destroys an instance of wrapped_grpc_call */
void free_wrapped_grpc_timeval(void *object TSRMLS_DC) {
wrapped_grpc_timeval *timeval = (wrapped_grpc_timeval *)object;
zend_object_std_dtor(&timeval->std TSRMLS_CC);
efree(timeval);
wrapped_grpc_timeval *timeval = (wrapped_grpc_timeval *)object;
zend_object_std_dtor(&timeval->std TSRMLS_CC);
efree(timeval);
}
/* Initializes an instance of wrapped_grpc_timeval to be associated with an
@ -78,17 +78,6 @@ zend_object_value create_wrapped_grpc_timeval(zend_class_entry *class_type
return retval;
}
zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) {
zval *timeval_object;
MAKE_STD_ZVAL(timeval_object);
object_init_ex(timeval_object, grpc_ce_timeval);
wrapped_grpc_timeval *timeval =
(wrapped_grpc_timeval *)zend_object_store_get_object(
timeval_object TSRMLS_CC);
memcpy(&timeval->wrapped, &wrapped, sizeof(gpr_timespec));
return timeval_object;
}
#else
static zend_object_handlers timeval_ce_handlers;
@ -111,27 +100,24 @@ zend_object *create_wrapped_grpc_timeval(zend_class_entry *class_type) {
return &intern->std;
}
void grpc_php_wrap_timeval(gpr_timespec wrapped, zval *timeval_object) {
#endif
zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC) {
zval *timeval_object;
PHP_GRPC_MAKE_STD_ZVAL(timeval_object);
object_init_ex(timeval_object, grpc_ce_timeval);
wrapped_grpc_timeval *timeval = Z_WRAPPED_GRPC_TIMEVAL_P(timeval_object);
memcpy(&timeval->wrapped, &wrapped, sizeof(gpr_timespec));
return timeval_object;
}
#endif
/**
* Constructs a new instance of the Timeval class
* @param long $usec The number of microseconds in the interval
*/
PHP_METHOD(Timeval, __construct) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *timeval =
(wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC);
long microseconds;
#else
wrapped_grpc_timeval *timeval = Z_WRAPPED_GRPC_TIMEVAL_P(getThis());
zend_long microseconds;
#endif
php_grpc_long microseconds;
/* "l" == 1 long */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &microseconds) ==
@ -160,23 +146,14 @@ PHP_METHOD(Timeval, add) {
"add expects a Timeval", 1 TSRMLS_CC);
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *self =
(wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC);
wrapped_grpc_timeval *other =
(wrapped_grpc_timeval *)zend_object_store_get_object(other_obj TSRMLS_CC);
zval *sum =
wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis());
wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj);
zval *sum;
PHP_GRPC_MAKE_STD_ZVAL(sum);
sum =
grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped)
TSRMLS_CC);
RETURN_DESTROY_ZVAL(sum);
#else
wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis());
wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj);
grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped),
return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -195,22 +172,14 @@ PHP_METHOD(Timeval, subtract) {
"subtract expects a Timeval", 1 TSRMLS_CC);
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *self =
(wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC);
wrapped_grpc_timeval *other =
(wrapped_grpc_timeval *)zend_object_store_get_object(other_obj TSRMLS_CC);
zval *diff =
wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis());
wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj);
zval *diff;
PHP_GRPC_MAKE_STD_ZVAL(diff);
diff =
grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped)
TSRMLS_CC);
RETURN_DESTROY_ZVAL(diff);
#else
wrapped_grpc_timeval *self = Z_WRAPPED_GRPC_TIMEVAL_P(getThis());
wrapped_grpc_timeval *other = Z_WRAPPED_GRPC_TIMEVAL_P(other_obj);
grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped),
return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -232,15 +201,8 @@ PHP_METHOD(Timeval, compare) {
"compare expects two Timevals", 1 TSRMLS_CC);
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *a =
(wrapped_grpc_timeval *)zend_object_store_get_object(a_obj TSRMLS_CC);
wrapped_grpc_timeval *b =
(wrapped_grpc_timeval *)zend_object_store_get_object(b_obj TSRMLS_CC);
#else
wrapped_grpc_timeval *a = Z_WRAPPED_GRPC_TIMEVAL_P(a_obj);
wrapped_grpc_timeval *b = Z_WRAPPED_GRPC_TIMEVAL_P(b_obj);
#endif
long result = gpr_time_cmp(a->wrapped, b->wrapped);
RETURN_LONG(result);
}
@ -265,19 +227,9 @@ PHP_METHOD(Timeval, similar) {
"compare expects three Timevals", 1 TSRMLS_CC);
return;
}
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *a =
(wrapped_grpc_timeval *)zend_object_store_get_object(a_obj TSRMLS_CC);
wrapped_grpc_timeval *b =
(wrapped_grpc_timeval *)zend_object_store_get_object(b_obj TSRMLS_CC);
wrapped_grpc_timeval *thresh =
(wrapped_grpc_timeval *)zend_object_store_get_object(
thresh_obj TSRMLS_CC);
#else
wrapped_grpc_timeval *a = Z_WRAPPED_GRPC_TIMEVAL_P(a_obj);
wrapped_grpc_timeval *b = Z_WRAPPED_GRPC_TIMEVAL_P(b_obj);
wrapped_grpc_timeval *thresh = Z_WRAPPED_GRPC_TIMEVAL_P(thresh_obj);
#endif
int result = gpr_time_similar(a->wrapped, b->wrapped, thresh->wrapped);
RETURN_BOOL(result);
}
@ -287,13 +239,10 @@ PHP_METHOD(Timeval, similar) {
* @return Timeval The current time
*/
PHP_METHOD(Timeval, now) {
#if PHP_MAJOR_VERSION < 7
zval *now = grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME) TSRMLS_CC);
zval *now;
PHP_GRPC_MAKE_STD_ZVAL(now);
now = grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME) TSRMLS_CC);
RETURN_DESTROY_ZVAL(now);
#else
grpc_php_wrap_timeval(gpr_now(GPR_CLOCK_REALTIME), return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -301,18 +250,13 @@ PHP_METHOD(Timeval, now) {
* @return Timeval Zero length time interval
*/
PHP_METHOD(Timeval, zero) {
#if PHP_MAJOR_VERSION < 7
zval *grpc_php_timeval_zero =
zval *grpc_php_timeval_zero;
PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_zero);
grpc_php_timeval_zero =
grpc_php_wrap_timeval(gpr_time_0(GPR_CLOCK_REALTIME) TSRMLS_CC);
RETURN_ZVAL(grpc_php_timeval_zero,
false, /* Copy original before returning? */
true /* Destroy original before returning */);
#else
grpc_php_wrap_timeval(gpr_time_0(GPR_CLOCK_REALTIME), return_value);
RETURN_ZVAL(return_value,
false, /* Copy original before returning? */
true /* Destroy original before returning */);
#endif
}
/**
@ -320,14 +264,11 @@ PHP_METHOD(Timeval, zero) {
* @return Timeval Infinite future time value
*/
PHP_METHOD(Timeval, infFuture) {
#if PHP_MAJOR_VERSION < 7
zval *grpc_php_timeval_inf_future =
zval *grpc_php_timeval_inf_future;
PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_inf_future);
grpc_php_timeval_inf_future =
grpc_php_wrap_timeval(gpr_inf_future(GPR_CLOCK_REALTIME) TSRMLS_CC);
RETURN_DESTROY_ZVAL(grpc_php_timeval_inf_future);
#else
grpc_php_wrap_timeval(gpr_inf_future(GPR_CLOCK_REALTIME), return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -335,14 +276,11 @@ PHP_METHOD(Timeval, infFuture) {
* @return Timeval Infinite past time value
*/
PHP_METHOD(Timeval, infPast) {
#if PHP_MAJOR_VERSION < 7
zval *grpc_php_timeval_inf_past =
zval *grpc_php_timeval_inf_past;
PHP_GRPC_MAKE_STD_ZVAL(grpc_php_timeval_inf_past);
grpc_php_timeval_inf_past =
grpc_php_wrap_timeval(gpr_inf_past(GPR_CLOCK_REALTIME) TSRMLS_CC);
RETURN_DESTROY_ZVAL(grpc_php_timeval_inf_past);
#else
grpc_php_wrap_timeval(gpr_inf_past(GPR_CLOCK_REALTIME), return_value);
RETURN_DESTROY_ZVAL(return_value);
#endif
}
/**
@ -350,12 +288,7 @@ PHP_METHOD(Timeval, infPast) {
* @return void
*/
PHP_METHOD(Timeval, sleepUntil) {
#if PHP_MAJOR_VERSION < 7
wrapped_grpc_timeval *this =
(wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC);
#else
wrapped_grpc_timeval *this = Z_WRAPPED_GRPC_TIMEVAL_P(getThis());
#endif
gpr_sleep_until(this->wrapped);
}

@ -50,27 +50,24 @@
extern zend_class_entry *grpc_ce_timeval;
/* Wrapper struct for timeval that can be associated with a PHP object */
PHP_GRPC_WRAP_OBJECT_START(wrapped_grpc_timeval)
gpr_timespec wrapped;
PHP_GRPC_WRAP_OBJECT_END(wrapped_grpc_timeval)
#if PHP_MAJOR_VERSION < 7
typedef struct wrapped_grpc_timeval {
zend_object std;
gpr_timespec wrapped;
} wrapped_grpc_timeval;
#define Z_WRAPPED_GRPC_TIMEVAL_P(zv) \
(wrapped_grpc_timeval *)zend_object_store_get_object(zv TSRMLS_CC)
#else
typedef struct wrapped_grpc_timeval {
gpr_timespec wrapped;
zend_object std;
} wrapped_grpc_timeval;
static inline wrapped_grpc_timeval
*wrapped_grpc_timeval_from_obj(zend_object *obj) {
return (wrapped_grpc_timeval*)((char*)(obj) -
XtOffsetOf(wrapped_grpc_timeval, std));
}
#define Z_WRAPPED_GRPC_TIMEVAL_P(zv) \
#define Z_WRAPPED_GRPC_TIMEVAL_P(zv) \
wrapped_grpc_timeval_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */
@ -82,10 +79,6 @@ void grpc_init_timeval(TSRMLS_D);
void grpc_shutdown_timeval(TSRMLS_D);
/* Creates a Timeval object that wraps the given timeval struct */
#if PHP_MAJOR_VERSION < 7
zval *grpc_php_wrap_timeval(gpr_timespec wrapped TSRMLS_DC);
#else
void grpc_php_wrap_timeval(gpr_timespec wrapped, zval *timeval_object);
#endif /* PHP_MAJOR_VERSION */
#endif /* NET_GRPC_PHP_GRPC_TIMEVAL_H_ */

@ -14,3 +14,4 @@ doc/
_grpcio_metadata.py
htmlcov/
grpc/_cython/_credentials
poison.c

@ -184,6 +184,71 @@ class BuildPy(build_py.build_py):
build_py.build_py.run(self)
def _poison_extensions(extensions, message):
"""Includes a file that will always fail to compile in all extensions."""
poison_filename = os.path.join(PYTHON_STEM, 'poison.c')
with open(poison_filename, 'w') as poison:
poison.write('#error {}'.format(message))
for extension in extensions:
extension.sources = [poison_filename]
def check_and_update_cythonization(extensions):
"""Replace .pyx files with their generated counterparts and return whether or
not cythonization still needs to occur."""
for extension in extensions:
generated_pyx_sources = []
other_sources = []
for source in extension.sources:
base, file_ext = os.path.splitext(source)
if file_ext == '.pyx':
generated_pyx_source = next(
(base + gen_ext for gen_ext in ('.c', '.cpp',)
if os.path.isfile(base + gen_ext)), None)
if generated_pyx_source:
generated_pyx_sources.append(generated_pyx_source)
else:
sys.stderr.write('Cython-generated files are missing...\n')
return False
else:
other_sources.append(source)
extension.sources = generated_pyx_sources + other_sources
sys.stderr.write('Found cython-generated files...\n')
return True
def try_cythonize(extensions, linetracing=False, mandatory=True):
"""Attempt to cythonize the extensions.
Args:
extensions: A list of `distutils.extension.Extension`.
linetracing: A bool indicating whether or not to enable linetracing.
mandatory: Whether or not having Cython-generated files is mandatory. If it
is, extensions will be poisoned when they can't be fully generated.
"""
try:
# Break import style to ensure we have access to Cython post-setup_requires
import Cython.Build
except ImportError:
if mandatory:
sys.stderr.write(
"This package needs to generate C files with Cython but it cannot. "
"Poisoning extension sources to disallow extension commands...")
_poison_extensions(
extensions,
"Extensions have been poisoned due to missing Cython-generated code.")
return extensions
cython_compiler_directives = {}
if linetracing:
additional_define_macros = [('CYTHON_TRACE_NOGIL', '1')]
cython_compiler_directives['linetrace'] = True
return Cython.Build.cythonize(
extensions,
include_path=[
include_dir for extension in extensions for include_dir in extension.include_dirs
],
compiler_directives=cython_compiler_directives
)
class BuildExt(build_ext.build_ext):
"""Custom build_ext command to enable compiler-specific flags."""
@ -201,6 +266,8 @@ class BuildExt(build_ext.build_ext):
if compiler in BuildExt.LINK_OPTIONS:
for extension in self.extensions:
extension.extra_link_args += list(BuildExt.LINK_OPTIONS[compiler])
if not check_and_update_cythonization(self.extensions):
self.extensions = try_cythonize(self.extensions)
try:
build_ext.build_ext.build_extensions(self)
except Exception as error:

@ -642,8 +642,8 @@
endif
else
PC_LIBS_GRPCXX = -lprotobuf
PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
endif
PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
else
ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a

@ -1,6 +1,6 @@
%YAML 1.2
--- |
# Copyright 2015, Google Inc.
# Copyright 2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -32,34 +32,8 @@
FROM debian:jessie
<%include file="../../apt_get_basic.include"/>
<%include file="../../python_deps.include"/>
<%include file="../../ruby_deps.include"/>
<%include file="../../php_deps.include"/>
<%include file="../../run_tests_addons.include"/>
# ronn: a ruby tool used to convert markdown to man pages, used during the
# install of Protobuf extensions
#
# rake: a ruby version of make used to build the PHP Protobuf extension
RUN /bin/bash -l -c "rvm all do gem install ronn rake"
# Install composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency
# into composer cache to prevent "composer install" from cloning on each build.
RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git ${'\\'}
/root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/
# Download the patched PHP protobuf so that PHP gRPC clients can be generated
# from proto3 schemas.
RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php
RUN /bin/bash -l -c "rvm use ruby-2.1 ${'\\'}
&& cd /var/local/git/protobuf-php ${'\\'}
&& rvm all do rake pear:package version=1.0 ${'\\'}
&& pear install Protobuf-1.0.tgz"
# Define the default command.
CMD ["bash"]
<%include file="../../php_common_deps.include"/>

@ -0,0 +1,37 @@
%YAML 1.2
--- |
# Copyright 2016, 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.
FROM debian:jessie
<%include file="../../php7_deps.include"/>
<%include file="../../ruby_deps.include"/>
<%include file="../../run_tests_addons.include"/>
<%include file="../../php_common_deps.include"/>

@ -0,0 +1,45 @@
#=================
# PHP7 dependencies
# Install Git and basic packages.
RUN apt-get update && apt-get install -y ${'\\'}
autoconf ${'\\'}
automake ${'\\'}
build-essential ${'\\'}
ccache ${'\\'}
curl ${'\\'}
git ${'\\'}
libcurl4-openssl-dev ${'\\'}
libgmp-dev ${'\\'}
libgmp3-dev ${'\\'}
libssl-dev ${'\\'}
libtool ${'\\'}
libxml2-dev ${'\\'}
pkg-config ${'\\'}
re2c ${'\\'}
time ${'\\'}
unzip ${'\\'}
wget ${'\\'}
zip && apt-get clean
# Install other dependencies
RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz
RUN cd /var/local ${'\\'}
&& tar -zxvf bison-2.6.4.tar.gz ${'\\'}
&& cd /var/local/bison-2.6.4 ${'\\'}
&& ./configure ${'\\'}
&& make ${'\\'}
&& make install
# Compile PHP7 from source
RUN git clone https://github.com/php/php-src /var/local/git/php-src
RUN cd /var/local/git/php-src ${'\\'}
&& git checkout PHP-7.0.9 ${'\\'}
&& ./buildconf --force ${'\\'}
&& ./configure ${'\\'}
--with-gmp ${'\\'}
--with-openssl ${'\\'}
--with-zlib ${'\\'}
&& make ${'\\'}
&& make install

@ -0,0 +1,21 @@
# ronn: a ruby tool used to convert markdown to man pages, used during the
# install of Protobuf extensions
#
# rake: a ruby version of make used to build the PHP Protobuf extension
RUN /bin/bash -l -c "rvm all do gem install ronn rake"
# 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.
RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php
RUN /bin/bash -l -c "rvm use ruby-2.1 ${'\\'}
&& cd /var/local/git/protobuf-php ${'\\'}
&& rvm all do rake pear:package version=1.0 ${'\\'}
&& pear install Protobuf-1.0.tgz"
# Define the default command.
CMD ["bash"]

@ -3,11 +3,5 @@
# Install dependencies
RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' ${'\\'}
>> /etc/apt/sources.list.d/dotdeb.list"
RUN /bin/bash -l -c "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 -
RUN apt-get update && apt-get install -y ${'\\'}
git php5 php5-dev phpunit unzip

@ -47,11 +47,6 @@
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency
# into composer cache to prevent "composer install" from cloning on each build.
RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git ${'\\'}
/root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/
# Download the patched PHP protobuf so that PHP gRPC clients can be generated
# from proto3 schemas.
RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php

@ -0,0 +1,38 @@
%YAML 1.2
--- |
# Copyright 2016, 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.
FROM debian:jessie
<%include file="../../php7_deps.include"/>
<%include file="../../python_deps.include"/>
<%include file="../../run_tests_addons.include"/>
# Define the default command.
CMD ["bash"]

@ -70,7 +70,8 @@ static void on_read(grpc_exec_ctx *exec_ctx, grpc_fd *emfd,
g_number_of_reads++;
g_number_of_bytes_read += (int)byte_count;
grpc_pollset_kick(g_pollset, NULL);
GPR_ASSERT(
GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
@ -179,8 +180,10 @@ static void test_receive(int number_of_clients) {
while (g_number_of_reads == number_of_reads_before &&
gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0) {
grpc_pollset_worker *worker = NULL;
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline);
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_work",
grpc_pollset_work(&exec_ctx, g_pollset, &worker,
gpr_now(GPR_CLOCK_MONOTONIC), deadline)));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@ -199,7 +202,8 @@ static void test_receive(int number_of_clients) {
GPR_ASSERT(g_number_of_orphan_calls == 1);
}
static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool success) {
static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p,
grpc_error *error) {
grpc_pollset_destroy(p);
}

@ -1,4 +1,4 @@
# Copyright 2015, Google Inc.
# Copyright 2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -63,21 +63,6 @@ RUN apt-get update && apt-get install -y \
# Build profiling
RUN apt-get update && apt-get install -y time && apt-get clean
#====================
# Python dependencies
# Install dependencies
RUN apt-get update && apt-get install -y \
python-all-dev \
python3-all-dev \
python-pip
# Install Python packages from PyPI
RUN pip install pip --upgrade
RUN pip install virtualenv
RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0
#==================
# Ruby dependencies
@ -98,12 +83,6 @@ RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
# Install dependencies
RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \
>> /etc/apt/sources.list.d/dotdeb.list"
RUN /bin/bash -l -c "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 -
RUN apt-get update && apt-get install -y \
git php5 php5-dev phpunit unzip
@ -128,11 +107,6 @@ RUN /bin/bash -l -c "rvm all do gem install ronn rake"
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency
# into composer cache to prevent "composer install" from cloning on each build.
RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git \
/root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/
# Download the patched PHP protobuf so that PHP gRPC clients can be generated
# from proto3 schemas.
RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php
@ -144,3 +118,4 @@ RUN /bin/bash -l -c "rvm use ruby-2.1 \
# Define the default command.
CMD ["bash"]

@ -0,0 +1,125 @@
# Copyright 2016, 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.
FROM debian:jessie
#=================
# PHP7 dependencies
# Install Git and basic packages.
RUN apt-get update && apt-get install -y \
autoconf \
automake \
build-essential \
ccache \
curl \
git \
libcurl4-openssl-dev \
libgmp-dev \
libgmp3-dev \
libssl-dev \
libtool \
libxml2-dev \
pkg-config \
re2c \
time \
unzip \
wget \
zip && apt-get clean
# Install other dependencies
RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz
RUN cd /var/local \
&& tar -zxvf bison-2.6.4.tar.gz \
&& cd /var/local/bison-2.6.4 \
&& ./configure \
&& make \
&& make install
# Compile PHP7 from source
RUN git clone https://github.com/php/php-src /var/local/git/php-src
RUN cd /var/local/git/php-src \
&& git checkout PHP-7.0.9 \
&& ./buildconf --force \
&& ./configure \
--with-gmp \
--with-openssl \
--with-zlib \
&& make \
&& make install
#==================
# Ruby dependencies
# Install rvm
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
RUN \curl -sSL https://get.rvm.io | bash -s stable
# Install Ruby 2.1
RUN /bin/bash -l -c "rvm install ruby-2.1"
RUN /bin/bash -l -c "rvm use --default ruby-2.1"
RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc"
RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc"
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
# Prepare ccache
RUN ln -s /usr/bin/ccache /usr/local/bin/gcc
RUN ln -s /usr/bin/ccache /usr/local/bin/g++
RUN ln -s /usr/bin/ccache /usr/local/bin/cc
RUN ln -s /usr/bin/ccache /usr/local/bin/c++
RUN ln -s /usr/bin/ccache /usr/local/bin/clang
RUN ln -s /usr/bin/ccache /usr/local/bin/clang++
RUN mkdir /var/local/jenkins
# ronn: a ruby tool used to convert markdown to man pages, used during the
# install of Protobuf extensions
#
# rake: a ruby version of make used to build the PHP Protobuf extension
RUN /bin/bash -l -c "rvm all do gem install ronn rake"
# 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.
RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php
RUN /bin/bash -l -c "rvm use ruby-2.1 \
&& cd /var/local/git/protobuf-php \
&& rvm all do rake pear:package version=1.0 \
&& pear install Protobuf-1.0.tgz"
# Define the default command.
CMD ["bash"]

@ -0,0 +1,52 @@
#!/bin/bash
# Copyright 2016, 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.
#
# Builds PHP interop server and client in a base image.
set -ex
mkdir -p /var/local/git
git clone --recursive /var/local/jenkins/grpc /var/local/git/grpc
# copy service account keys if available
cp -r /var/local/jenkins/service_account $HOME || true
cd /var/local/git/grpc
rvm --default use ruby-2.1
# gRPC core and protobuf need to be installed
make install
(cd src/php/ext/grpc && phpize && ./configure && make)
(cd third_party/protobuf && make install)
(cd src/php && composer install)
(cd src/php && protoc-gen-php -i tests/interop/ -o tests/interop/ tests/interop/test.proto)

@ -103,12 +103,6 @@ RUN pip install --upgrade google-api-python-client
# Install dependencies
RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \
>> /etc/apt/sources.list.d/dotdeb.list"
RUN /bin/bash -l -c "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 -
RUN apt-get update && apt-get install -y \
git php5 php5-dev phpunit unzip
@ -133,11 +127,6 @@ RUN /bin/bash -l -c "rvm all do gem install ronn rake"
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# As an attempt to work around #4212, try to prefetch Protobuf-PHP dependency
# into composer cache to prevent "composer install" from cloning on each build.
RUN git clone --mirror https://github.com/stanley-cheung/Protobuf-PHP.git \
/root/.composer/cache/vcs/git-github.com-stanley-cheung-Protobuf-PHP.git/
# Download the patched PHP protobuf so that PHP gRPC clients can be generated
# from proto3 schemas.
RUN git clone https://github.com/stanley-cheung/Protobuf-PHP.git /var/local/git/protobuf-php

@ -100,12 +100,6 @@ RUN /bin/bash -l -c "nvm alias default 4"
# Install dependencies
RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \
>> /etc/apt/sources.list.d/dotdeb.list"
RUN /bin/bash -l -c "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 -
RUN apt-get update && apt-get install -y \
git php5 php5-dev phpunit unzip

@ -0,0 +1,105 @@
# Copyright 2016, 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.
FROM debian:jessie
#=================
# PHP7 dependencies
# Install Git and basic packages.
RUN apt-get update && apt-get install -y \
autoconf \
automake \
build-essential \
ccache \
curl \
git \
libcurl4-openssl-dev \
libgmp-dev \
libgmp3-dev \
libssl-dev \
libtool \
libxml2-dev \
pkg-config \
re2c \
time \
unzip \
wget \
zip && apt-get clean
# Install other dependencies
RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz
RUN cd /var/local \
&& tar -zxvf bison-2.6.4.tar.gz \
&& cd /var/local/bison-2.6.4 \
&& ./configure \
&& make \
&& make install
# Compile PHP7 from source
RUN git clone https://github.com/php/php-src /var/local/git/php-src
RUN cd /var/local/git/php-src \
&& git checkout PHP-7.0.9 \
&& ./buildconf --force \
&& ./configure \
--with-gmp \
--with-openssl \
--with-zlib \
&& make \
&& make install
#====================
# Python dependencies
# Install dependencies
RUN apt-get update && apt-get install -y \
python-all-dev \
python3-all-dev \
python-pip
# Install Python packages from PyPI
RUN pip install pip --upgrade
RUN pip install virtualenv
RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0
# Prepare ccache
RUN ln -s /usr/bin/ccache /usr/local/bin/gcc
RUN ln -s /usr/bin/ccache /usr/local/bin/g++
RUN ln -s /usr/bin/ccache /usr/local/bin/cc
RUN ln -s /usr/bin/ccache /usr/local/bin/c++
RUN ln -s /usr/bin/ccache /usr/local/bin/clang
RUN ln -s /usr/bin/ccache /usr/local/bin/clang++
RUN mkdir /var/local/jenkins
# Define the default command.
CMD ["bash"]

@ -83,12 +83,6 @@ RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0
# Install dependencies
RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \
>> /etc/apt/sources.list.d/dotdeb.list"
RUN /bin/bash -l -c "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 -
RUN apt-get update && apt-get install -y \
git php5 php5-dev phpunit unzip

@ -268,6 +268,31 @@ class PHPLanguage:
return 'php'
class PHP7Language:
def __init__(self):
self.client_cwd = None
self.safename = str(self)
def client_cmd(self, args):
return ['src/php/bin/interop_client.sh'] + args
def cloud_to_prod_env(self):
return {}
def global_env(self):
return {}
def unimplemented_test_cases(self):
return _SKIP_COMPRESSION
def unimplemented_test_cases_server(self):
return []
def __str__(self):
return 'php7'
class RubyLanguage:
def __init__(self):
@ -346,6 +371,7 @@ _LANGUAGES = {
'java' : JavaLanguage(),
'node' : NodeLanguage(),
'php' : PHPLanguage(),
'php7' : PHP7Language(),
'ruby' : RubyLanguage(),
'python' : PythonLanguage(),
}
@ -409,7 +435,7 @@ def auth_options(language, test_case):
default_account_arg = '--default_service_account=830293263384-compute@developer.gserviceaccount.com'
if test_case in ['jwt_token_creds', 'per_rpc_creds', 'oauth2_auth_token']:
if language in ['csharp', 'node', 'php', 'python', 'ruby']:
if language in ['csharp', 'node', 'php', 'php7', 'python', 'ruby']:
env['GOOGLE_APPLICATION_CREDENTIALS'] = key_filepath
else:
cmdargs += [key_file_arg]

@ -381,6 +381,42 @@ class PhpLanguage(object):
return 'php'
class Php7Language(object):
def configure(self, config, args):
self.config = config
self.args = args
_check_compiler(self.args.compiler, ['default'])
def test_specs(self):
return [self.config.job_spec(['src/php/bin/run_tests.sh'], None,
environ=_FORCE_ENVIRON_FOR_WRAPPERS)]
def pre_build_steps(self):
return []
def make_targets(self):
return ['static_c', 'shared_c']
def make_options(self):
return []
def build_steps(self):
return [['tools/run_tests/build_php.sh']]
def post_tests_steps(self):
return [['tools/run_tests/post_tests_php.sh']]
def makefile_name(self):
return 'Makefile'
def dockerfile_dir(self):
return 'tools/dockerfile/test/php7_jessie_%s' % _docker_arch_suffix(self.args.arch)
def __str__(self):
return 'php7'
class PythonConfig(collections.namedtuple('PythonConfig', [
'name', 'build', 'run'])):
"""Tuple of commands (named s.t. 'what it says on the tin' applies)"""
@ -749,6 +785,7 @@ _LANGUAGES = {
'c': CLanguage('c', 'c'),
'node': NodeLanguage(),
'php': PhpLanguage(),
'php7': Php7Language(),
'python': PythonLanguage(),
'ruby': RubyLanguage(),
'csharp': CSharpLanguage(),

Loading…
Cancel
Save