diff options
author | Craig Tiller <ctiller@google.com> | 2016-02-25 12:57:56 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-02-25 12:57:56 -0800 |
commit | 21679875659f382991f4c4e9e8bea34e93bc9b7f (patch) | |
tree | b3e79e0b396fbd43e4df0269058b1ef3b672e6ff /src | |
parent | ee1f1f347de8c9a74d8b2cf01840a44fbed83996 (diff) | |
parent | f7806b766bf88d2173ef37a4205d1393bbd73d60 (diff) |
Merge github.com:grpc/grpc into hide-the-pollset
Diffstat (limited to 'src')
25 files changed, 231 insertions, 154 deletions
diff --git a/src/core/client_config/subchannel_index.c b/src/core/client_config/subchannel_index.c index f78a7fd588..3f948998f9 100644 --- a/src/core/client_config/subchannel_index.c +++ b/src/core/client_config/subchannel_index.c @@ -149,11 +149,13 @@ static const gpr_avl_vtable subchannel_avl_vtable = { void grpc_subchannel_index_init(void) { g_subchannel_index = gpr_avl_create(&subchannel_avl_vtable); gpr_mu_init(&g_mu); + gpr_tls_init(&subchannel_index_exec_ctx); } void grpc_subchannel_index_shutdown(void) { gpr_mu_destroy(&g_mu); gpr_avl_unref(g_subchannel_index); + gpr_tls_destroy(&subchannel_index_exec_ctx); } grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx, diff --git a/src/core/compression/algorithm.c b/src/core/compression/compression_algorithm.c index 6f3a8eb28e..6f3a8eb28e 100644 --- a/src/core/compression/algorithm.c +++ b/src/core/compression/compression_algorithm.c diff --git a/src/core/security/base64.c b/src/core/security/b64.c index 8367c160c3..c40b528e2f 100644 --- a/src/core/security/base64.c +++ b/src/core/security/b64.c @@ -31,7 +31,7 @@ * */ -#include "src/core/security/base64.h" +#include "src/core/security/b64.h" #include <stdint.h> #include <string.h> diff --git a/src/core/security/base64.h b/src/core/security/b64.h index 31ae982691..3e3b521120 100644 --- a/src/core/security/base64.h +++ b/src/core/security/b64.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/core/security/google_default_credentials.c b/src/core/security/google_default_credentials.c index 25006e16c7..3b3e38882a 100644 --- a/src/core/security/google_default_credentials.c +++ b/src/core/security/google_default_credentials.c @@ -41,7 +41,7 @@ #include "src/core/httpcli/httpcli.h" #include "src/core/support/env.h" -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" #include "src/core/surface/api_trace.h" /* -- Constants. -- */ diff --git a/src/core/security/json_token.c b/src/core/security/json_token.c index 762f02989a..372e5bfc5a 100644 --- a/src/core/security/json_token.c +++ b/src/core/security/json_token.c @@ -39,7 +39,7 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include "src/core/security/base64.h" +#include "src/core/security/b64.h" #include "src/core/support/string.h" #include <openssl/bio.h> diff --git a/src/core/security/jwt_verifier.c b/src/core/security/jwt_verifier.c index 042a117f5d..928c6c148d 100644 --- a/src/core/security/jwt_verifier.c +++ b/src/core/security/jwt_verifier.c @@ -37,7 +37,7 @@ #include <string.h> #include "src/core/httpcli/httpcli.h" -#include "src/core/security/base64.h" +#include "src/core/security/b64.h" #include "src/core/tsi/ssl_types.h" #include <grpc/support/alloc.h> diff --git a/src/core/security/security_connector.c b/src/core/security/security_connector.c index b46205323b..51a99b4492 100644 --- a/src/core/security/security_connector.c +++ b/src/core/security/security_connector.c @@ -35,20 +35,20 @@ #include <string.h> +#include <grpc/support/alloc.h> +#include <grpc/support/host_port.h> +#include <grpc/support/log.h> +#include <grpc/support/slice_buffer.h> +#include <grpc/support/string_util.h> + #include "src/core/security/credentials.h" #include "src/core/security/handshake.h" #include "src/core/security/secure_endpoint.h" #include "src/core/security/security_context.h" #include "src/core/support/env.h" -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" #include "src/core/support/string.h" #include "src/core/transport/chttp2/alpn.h" - -#include <grpc/support/alloc.h> -#include <grpc/support/host_port.h> -#include <grpc/support/log.h> -#include <grpc/support/slice_buffer.h> -#include <grpc/support/string_util.h> #include "src/core/tsi/fake_transport_security.h" #include "src/core/tsi/ssl_transport_security.h" diff --git a/src/core/support/env_linux.c b/src/core/support/env_linux.c index 1ca6fa1aff..fe51f846b7 100644 --- a/src/core/support/env_linux.c +++ b/src/core/support/env_linux.c @@ -43,7 +43,9 @@ #include "src/core/support/env.h" #include <dlfcn.h> +#include <features.h> #include <stdlib.h> +#include <string.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> @@ -60,12 +62,22 @@ char *gpr_getenv(const char *name) { const char *names[] = {"secure_getenv", "__secure_getenv", "getenv"}; for (size_t i = 0; getenv_func == NULL && i < GPR_ARRAY_SIZE(names); i++) { getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]); + if (getenv_func != NULL && strstr(names[i], "secure") == NULL) { + gpr_log(GPR_DEBUG, + "Warning: insecure environment read function '%s' used", + names[i]); + } } char *result = getenv_func(name); return result == NULL ? result : gpr_strdup(result); -#else +#elif __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) char *result = secure_getenv(name); return result == NULL ? result : gpr_strdup(result); +#else + gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used", + "getenv"); + char *result = getenv(name); + return result == NULL ? result : gpr_strdup(result); #endif } diff --git a/src/core/support/file.c b/src/core/support/load_file.c index 8c673dbcc6..650bd62ccb 100644 --- a/src/core/support/file.c +++ b/src/core/support/load_file.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,7 @@ * */ -#include "src/core/support/file.h" +#include "src/core/support/load_file.h" #include <errno.h> #include <string.h> diff --git a/src/core/support/file.h b/src/core/support/load_file.h index d8b7cea44f..746319a50d 100644 --- a/src/core/support/file.h +++ b/src/core/support/load_file.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,8 +31,8 @@ * */ -#ifndef GRPC_INTERNAL_CORE_SUPPORT_FILE_H -#define GRPC_INTERNAL_CORE_SUPPORT_FILE_H +#ifndef GRPC_INTERNAL_CORE_SUPPORT_LOAD_FILE_H +#define GRPC_INTERNAL_CORE_SUPPORT_LOAD_FILE_H #include <stdio.h> @@ -42,22 +42,14 @@ extern "C" { #endif -/* File utility functions */ - /* Loads the content of a file into a slice. add_null_terminator will add a NULL terminator if non-zero. The success parameter, if not NULL, will be set to 1 in case of success and 0 in case of failure. */ gpr_slice gpr_load_file(const char *filename, int add_null_terminator, int *success); -/* Creates a temporary file from a prefix. - If tmp_filename is not NULL, *tmp_filename is assigned the name of the - created file and it is the responsibility of the caller to gpr_free it - unless an error occurs in which case it will be set to NULL. */ -FILE *gpr_tmpfile(const char *prefix, char **tmp_filename); - #ifdef __cplusplus } #endif -#endif /* GRPC_INTERNAL_CORE_SUPPORT_FILE_H */ +#endif /* GRPC_INTERNAL_CORE_SUPPORT_LOAD_FILE_H */ diff --git a/src/core/support/tmpfile.h b/src/core/support/tmpfile.h new file mode 100644 index 0000000000..cecc71e242 --- /dev/null +++ b/src/core/support/tmpfile.h @@ -0,0 +1,55 @@ +/* + * + * Copyright 2015-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 GRPC_INTERNAL_CORE_SUPPORT_TMPFILE_H +#define GRPC_INTERNAL_CORE_SUPPORT_TMPFILE_H + +#include <stdio.h> + +#include <grpc/support/slice.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Creates a temporary file from a prefix. + If tmp_filename is not NULL, *tmp_filename is assigned the name of the + created file and it is the responsibility of the caller to gpr_free it + unless an error occurs in which case it will be set to NULL. */ +FILE *gpr_tmpfile(const char *prefix, char **tmp_filename); + +#ifdef __cplusplus +} +#endif + +#endif /* GRPC_INTERNAL_CORE_SUPPORT_TMPFILE_H */ diff --git a/src/core/support/file_posix.c b/src/core/support/tmpfile_posix.c index c11c07148a..b16eeacf9d 100644 --- a/src/core/support/file_posix.c +++ b/src/core/support/tmpfile_posix.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,7 +35,7 @@ #ifdef GPR_POSIX_FILE -#include "src/core/support/file.h" +#include "src/core/support/tmpfile.h" #include <errno.h> #include <stdlib.h> diff --git a/src/core/support/file_win32.c b/src/core/support/tmpfile_win32.c index 355744f79a..3000f0029f 100644 --- a/src/core/support/file_win32.c +++ b/src/core/support/tmpfile_win32.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,8 +44,8 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> -#include "src/core/support/file.h" #include "src/core/support/string_win32.h" +#include "src/core/support/tmpfile.h" FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) { FILE *result = NULL; diff --git a/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs b/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs index eeaa7add81..dfaee5d9d7 100644 --- a/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs +++ b/src/csharp/Grpc.Core/Internal/DefaultSslRootsOverride.cs @@ -56,7 +56,7 @@ namespace Grpc.Core.Internal { lock (staticLock) { - var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(RootsPemResourceName); + var stream = typeof(DefaultSslRootsOverride).GetTypeInfo().Assembly.GetManifestResourceStream(RootsPemResourceName); if (stream == null) { throw new IOException(string.Format("Error loading the embedded resource \"{0}\"", RootsPemResourceName)); diff --git a/src/csharp/Grpc.Core/Internal/PlatformApis.cs b/src/csharp/Grpc.Core/Internal/PlatformApis.cs index f0c5b0f63f..fb1acfb607 100644 --- a/src/csharp/Grpc.Core/Internal/PlatformApis.cs +++ b/src/csharp/Grpc.Core/Internal/PlatformApis.cs @@ -53,12 +53,18 @@ namespace Grpc.Core.Internal static PlatformApis() { +#if DNXCORE50 + isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + isMacOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); +#else var platform = Environment.OSVersion.Platform; // PlatformID.MacOSX is never returned, commonly used trick is to identify Mac is by using uname. isMacOSX = (platform == PlatformID.Unix && GetUname() == "Darwin"); isLinux = (platform == PlatformID.Unix && !isMacOSX); isWindows = (platform == PlatformID.Win32NT || platform == PlatformID.Win32S || platform == PlatformID.Win32Windows); +#endif isMono = Type.GetType("Mono.Runtime") != null; } diff --git a/src/csharp/README.md b/src/csharp/README.md index 65ae0b5efd..b4fa945ac9 100644 --- a/src/csharp/README.md +++ b/src/csharp/README.md @@ -12,9 +12,9 @@ Beta PREREQUISITES -------------- -- Windows: .NET Framework 4.5+, Visual Studio 2013 or 2015. -- Linux: Mono 3.2.8+, MonoDevelop 5.9 with NuGet add-in installed. -- Mac OS X: [homebrew][], Xamarin Studio with NuGet add-in installed. +- Windows: .NET Framework 4.5+, Visual Studio 2013 or 2015 +- Linux: Mono 4+, MonoDevelop 5.9+ (with NuGet add-in installed) +- Mac OS X: Xamarin Studio 5.9+ HOW TO USE -------------- @@ -24,66 +24,28 @@ HOW TO USE - Open Visual Studio and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project options -> Manage NuGet Packages). - That will also pull all the transitive dependencies (including the native libraries that + That will also pull all the transitive dependencies (including the gRPC native library that gRPC C# is using internally). **Linux (Debian)** -- Add [Debian jessie-backports][] to your `sources.list` file. Example: - - ```sh - echo "deb http://http.debian.net/debian jessie-backports main" | \ - sudo tee -a /etc/apt/sources.list - ``` - -- Install the gRPC Debian package - - ```sh - sudo apt-get update - sudo apt-get install libgrpc0 - ``` - -- gRPC C# depends on native shared library `libgrpc_csharp_ext.so` (Unix flavor of grpc_csharp_ext.dll). - This library is not part of the base gRPC debian package and needs to be installed manually from - a `.deb` file. Download the debian package `libgrpc_csharp_ext` from corresponding gRPC release on GitHub - and install it using `dpkg`. - - ```sh - # choose version corresponding to the version of libgrpc you've installed. - wget https://github.com/grpc/grpc/releases/download/release-0_11_0/libgrpc-csharp-ext0_0.11.0.0-1_amd64.deb - dpkg -i libgrpc-csharp-ext0_0.11.0.0-1_amd64.deb - ``` - - Open MonoDevelop and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages). + That will also pull all the transitive dependencies (including the gRPC native library that + gRPC C# is using internally). -- NOTE: Currently, there are no debian packages for the latest version Protocol Buffers compiler (_protoc_) - and the gRPC _protoc_ plugin. You can install them using [gRPC Linuxbrew instructions][]. +- NOTE: gRPC C# doesn't have a good story yet for shipping precompiled Linux version of Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin. You can install them using [gRPC Linuxbrew instructions][]. **Mac OS X** -- WARNING: As of now gRPC C# only works on 64bit version of Mono (because we don't compile - the native extension for C# in 32bit mode yet). That means your development experience - with Xamarin Studio on MacOS will not be great, as you won't be able to run your - code directly from Xamarin Studio (which requires 32bit version of Mono). - -- Install [homebrew][]. Run the following command to install gRPC C# native dependencies. - - ```sh - $ curl -fsSL https://goo.gl/getgrpc | bash - - ``` - This will download and run the [gRPC install script][], then install the latest version of gRPC C core and native C# extension. - It also installs Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin for C#. - -- Install 64-bit version of mono with command `brew install mono`. - - Open Xamarin Studio and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages). + That will also pull all the transitive dependencies (including the gRPC native library that + gRPC C# is using internally). -- *You will be able to build your project in Xamarin Studio, but to run or test it, - you will need to run it under 64-bit version of Mono.* +- NOTE: gRPC C# doesn't have a good story yet for shipping precompiled Mac OS X version of Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin. You can install them using [gRPC Homebrew instructions][]. BUILD FROM SOURCE ----------------- @@ -94,7 +56,7 @@ If you are a user of gRPC C#, go to Usage section above. **Windows** - The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution. You can - either build the native solution in `vsprojects/grpc.sln` from Visual Studio manually, or you can use + either build the native solution in `vsprojects/grpc_csharp_ext.sln` from Visual Studio manually, or you can use a convenience batch script that builds everything for you. ``` @@ -102,30 +64,28 @@ If you are a user of gRPC C#, go to Usage section above. > buildall.bat ``` -- Open Grpc.sln using Visual Studio. NuGet dependencies will be restored - upon build (you need to have NuGet add-in installed). +- Open Grpc.sln using Visual Studio. **Linux** +- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution: ```sh - $ sudo apt-get install mono-devel - $ sudo apt-get install nunit nunit-console + # from the gRPC repository root + $ make CONFIG=dbg grpc_csharp_ext ``` -You can use older versions of MonoDevelop, but then you might need to restore -NuGet dependencies manually (by `nuget restore`), because older versions of MonoDevelop -don't support NuGet add-in. +- Use MonoDevelop to open the solution Grpc.sln + +**Mac OS X** -- Compile and install the gRPC C# extension library (that will be used via - P/Invoke from C#). +- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution. + ```sh - $ make grpc_csharp_ext - $ sudo make install_grpc_csharp_ext + # from the gRPC repository root + $ tools/run_tests/run_tests.py -c dbg -l csharp --build_only ``` -- Use MonoDevelop to open the solution Grpc.sln - -- Build the solution & run all the tests from test view. +- Use Xamarin Studio to open the solution Grpc.sln RUNNING TESTS ------------- @@ -135,17 +95,9 @@ gRPC C# is using NUnit as the testing framework. Under Visual Studio, make sure NUnit test adapter is installed (under "Extensions and Updates"). Then you should be able to run all the tests using Test Explorer. -Under Monodevelop, make sure you installed "NUnit support" in Add-in manager. +Under Monodevelop or Xamarin Studio, make sure you installed "NUnit support" in Add-in manager. Then you should be able to run all the test from the Test View. -After building the solution, you can also run the tests from command line -using nunit-console tool. - -```sh -# from Grpc.Core.Test/bin/Debug directory -$ nunit-console Grpc.Core.Tests.dll -``` - gRPC team uses a Python script to simplify facilitate running tests for different languages. @@ -176,27 +128,15 @@ CONTENTS - Grpc.IntegrationTesting: Cross-language gRPC implementation testing (interop testing). -TROUBLESHOOTING +THE NATIVE DEPENDENCY --------------- -### Problem: Unable to load DLL 'grpc_csharp_ext.dll' - -Internally, gRPC C# uses a native library written in C (gRPC C core) and invokes its functionality via P/Invoke. `grpc_csharp_ext` library is a native extension library that facilitates this by wrapping some C core API into a form that's more digestible for P/Invoke. If you get the above error, it means that the native dependencies could not be located by the C# runtime (or they are incompatible with the current runtime, so they could not be loaded). The solution to this is environment specific. - -- If you are developing on Windows in Visual Studio, the `grpc_csharp_ext.dll` that is shipped by gRPC nuget packages should be automatically copied to your build destination folder once you build. By adjusting project properties in your VS project file, you can influence which exact configuration of `grpc_csharp_ext.dll` will be used (based on VS version, bitness, debug/release configuration). - -- If you are running your application that is using gRPC on Windows machine that doesn't have Visual Studio installed, you might need to install [Visual C++ 2013 redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=40784) that contains some system .dll libraries that `grpc_csharp_ext.dll` depends on (see #905 for more details). - -- On Linux (or Docker), you need to first install gRPC C core and `libgrpc_csharp_ext.so` shared libraries. - See [How to Use](#how-to-use) section for details how to install it. - Installation on a machine where your application is going to be deployed is no different. - -- On Mac, you need to first install gRPC C core and `libgrpc_csharp_ext.dylib` shared libraries using Homebrew. See above for installation instruction. - Installation on a machine where your application is going to be deployed is no different. +Internally, gRPC C# uses a native library written in C (gRPC C core) and invokes its functionality via P/Invoke. `grpc_csharp_ext` library is a native extension library that facilitates this by wrapping some C core API into a form that's more digestible for P/Invoke. -- Possible cause for the problem is that the `grpc_csharp_ext` library is installed, but it has different bitness (32/64bit) than your C# runtime (in case you are using mono) or C# application. +Prior to version 0.13, installing `grpc_csharp_ext` was required to make gRPC work on Linux and MacOS. Starting with version 0.13, we have improved the packaging story significantly and precompiled versions of the native library for all supported platforms are now shipped with the NuGet package. Just installing the `Grpc` NuGet package should be the only step needed to use gRPC C#, regardless of your platform (Windows, Linux or Mac) and the bitness (32 or 64bit). [gRPC Linuxbrew instructions]:https://github.com/grpc/homebrew-grpc#quick-install-linux +[gRPC Homebrew instructions]:https://github.com/grpc/homebrew-grpc#quick-install-linux [homebrew]:http://brew.sh [gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install [grpc.io]: http://www.grpc.io/docs/installation/csharp.html diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index 00c4b8830d..9a3e5b5009 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +35,7 @@ #import <XCTest/XCTest.h> #import <GRPCClient/GRPCCall.h> +#import <GRPCClient/GRPCCall+ChannelArg.h> #import <GRPCClient/GRPCCall+OAuth2.h> #import <GRPCClient/GRPCCall+Tests.h> #import <ProtoRPC/ProtoMethod.h> @@ -45,6 +46,7 @@ static NSString * const kHostAddress = @"localhost:5050"; static NSString * const kPackage = @"grpc.testing"; static NSString * const kService = @"TestService"; +static NSString * const kRemoteSSLHost = @"grpc-test.sandbox.googleapis.com"; static ProtoMethod *kInexistentMethod; static ProtoMethod *kEmptyCallMethod; @@ -127,8 +129,7 @@ static ProtoMethod *kUnaryCallMethod; XCTFail(@"Received unexpected response: %@", value); } completionHandler:^(NSError *errorOrNil) { XCTAssertNotNil(errorOrNil, @"Finished without error!"); - // TODO(jcanizales): The server should return code 12 UNIMPLEMENTED, not 5 NOT FOUND. - XCTAssertEqual(errorOrNil.code, 5, @"Finished with unexpected error: %@", errorOrNil); + XCTAssertEqual(errorOrNil.code, 12, @"Finished with unexpected error: %@", errorOrNil); [expectation fulfill]; }]; @@ -191,7 +192,6 @@ static ProtoMethod *kUnaryCallMethod; [self waitForExpectationsWithTimeout:8 handler:nil]; } -// TODO(jcanizales): Activate this test against the remote server. - (void)testMetadata { __weak XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; @@ -200,7 +200,7 @@ static ProtoMethod *kUnaryCallMethod; request.fillOauthScope = YES; GRXWriter *requestsWriter = [GRXWriter writerWithValue:[request data]]; - GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress + GRPCCall *call = [[GRPCCall alloc] initWithHost:kRemoteSSLHost path:kUnaryCallMethod.HTTPPath requestsWriter:requestsWriter]; @@ -257,4 +257,40 @@ static ProtoMethod *kUnaryCallMethod; [self waitForExpectationsWithTimeout:8 handler:nil]; } +// TODO(makarandd): Move to a different file that contains only unit tests +- (void)testExceptions { + // Try to set userAgentPrefix for host that is nil. This should cause + // an exception. + @try { + [GRPCCall setUserAgentPrefix:@"Foo" forHost:nil]; + XCTFail(@"Did not receive an exception when host is nil"); + } @catch(NSException *theException) { + NSLog(@"Received exception as expected: %@", theException.name); + } + + // Try to set parameters to nil for GRPCCall. This should cause an exception + @try { + GRPCCall *call = [[GRPCCall alloc] initWithHost:nil + path:nil + requestsWriter:nil]; + XCTFail(@"Did not receive an exception when parameters are nil"); + } @catch(NSException *theException) { + NSLog(@"Received exception as expected: %@", theException.name); + } + + + // Set state to Finished by force + GRXWriter *requestsWriter = [GRXWriter emptyWriter]; + [requestsWriter finishWithError:nil]; + @try { + GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress + path:kUnaryCallMethod.HTTPPath + requestsWriter:requestsWriter]; + XCTFail(@"Did not receive an exception when GRXWriter has incorrect state."); + } @catch(NSException *theException) { + NSLog(@"Received exception as expected: %@", theException.name); + } + +} + @end diff --git a/src/objective-c/tests/InteropTestsLocalSSL.m b/src/objective-c/tests/InteropTestsLocalSSL.m index 9d7afefbfe..155e334ecb 100644 --- a/src/objective-c/tests/InteropTestsLocalSSL.m +++ b/src/objective-c/tests/InteropTestsLocalSSL.m @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -57,4 +57,15 @@ static NSString * const kLocalSSLHost = @"localhost:5051"; [super setUp]; } +- (void)testExceptions { + // Try to set userAgentPrefix for host that is nil. This should cause + // an exception. + @try { + [GRPCCall useTestCertsPath:nil testName:nil forHost:nil]; + XCTFail(@"Did not receive an exception when parameters are nil"); + } @catch(NSException *theException) { + NSLog(@"Received exception as expected: %@", theException.name); + } +} + @end diff --git a/src/objective-c/tests/RxLibraryUnitTests.m b/src/objective-c/tests/RxLibraryUnitTests.m index a67a4c6cd9..d342662814 100644 --- a/src/objective-c/tests/RxLibraryUnitTests.m +++ b/src/objective-c/tests/RxLibraryUnitTests.m @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -137,4 +137,24 @@ XCTAssertEqualObjects(handler.errorOrNil, anyError); } +- (void)testBufferedPipeFinishWriteWhilePaused { + // Given: + CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler]; + id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:handler.block]; + id anyValue = @7; + + // If: + GRXBufferedPipe *pipe = [GRXBufferedPipe pipe]; + // Write something, then finish + [pipe writeValue:anyValue]; + [pipe writesFinishedWithError:nil]; + // then start the writeable + [pipe startWithWriteable:writeable]; + + // Then: + XCTAssertEqual(handler.timesCalled, 1); + XCTAssertEqualObjects(handler.value, anyValue); + XCTAssertEqualObjects(handler.errorOrNil, nil); +} + @end diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index c020fda284..a543791f5c 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -42,11 +42,9 @@ CORE_SOURCE_FILES = [ 'src/core/support/env_linux.c', 'src/core/support/env_posix.c', 'src/core/support/env_win32.c', - 'src/core/support/file.c', - 'src/core/support/file_posix.c', - 'src/core/support/file_win32.c', 'src/core/support/histogram.c', 'src/core/support/host_port.c', + 'src/core/support/load_file.c', 'src/core/support/log.c', 'src/core/support/log_android.c', 'src/core/support/log_linux.c', @@ -72,6 +70,8 @@ CORE_SOURCE_FILES = [ 'src/core/support/time_precise.c', 'src/core/support/time_win32.c', 'src/core/support/tls_pthread.c', + 'src/core/support/tmpfile_posix.c', + 'src/core/support/tmpfile_win32.c', 'src/core/support/wrap_memcpy.c', 'src/core/census/grpc_context.c', 'src/core/census/grpc_filter.c', @@ -103,7 +103,7 @@ CORE_SOURCE_FILES = [ 'src/core/client_config/subchannel_factory.c', 'src/core/client_config/subchannel_index.c', 'src/core/client_config/uri_parser.c', - 'src/core/compression/algorithm.c', + 'src/core/compression/compression_algorithm.c', 'src/core/compression/message_compress.c', 'src/core/debug/trace.c', 'src/core/httpcli/format_request.c', @@ -204,7 +204,7 @@ CORE_SOURCE_FILES = [ 'src/core/transport/transport.c', 'src/core/transport/transport_op_string.c', 'src/core/httpcli/httpcli_security_connector.c', - 'src/core/security/base64.c', + 'src/core/security/b64.c', 'src/core/security/client_auth_filter.c', 'src/core/security/credentials.c', 'src/core/security/credentials_metadata.c', diff --git a/src/python/grpcio/precompiled.py b/src/python/grpcio/precompiled.py index 05c651b506..ae2a0c835a 100644 --- a/src/python/grpcio/precompiled.py +++ b/src/python/grpcio/precompiled.py @@ -100,3 +100,5 @@ def update_setup_arguments(setup_arguments): sys.stderr.write( 'could not write precompiled extension to directory: {} -> {}\n' .format(url, target_path)) + return + setup_arguments['package_data']['grpc._cython'].append('cygrpc.so') diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c index eefdb93d67..0f9b18fa21 100644 --- a/src/ruby/ext/grpc/rb_grpc.c +++ b/src/ruby/ext/grpc/rb_grpc.c @@ -269,20 +269,9 @@ static void Init_grpc_time_consts() { id_tv_nsec = rb_intern("tv_nsec"); } -/* - TODO: find an alternative to ruby_vm_at_exit that is ok in Ruby 2.0 where - RUBY_TYPED_FREE_IMMEDIATELY is not defined. - - At the moment, registering a function using ruby_vm_at_exit segfaults in Ruby - 2.0. This is not an issue with the gRPC handler. More likely, this was an - in issue with 2.0 that got resolved in 2.1 and has not been backported. -*/ -#ifdef RUBY_TYPED_FREE_IMMEDIATELY -static void grpc_rb_shutdown(ruby_vm_t *vm) { - (void)vm; +static void grpc_rb_shutdown(void) { grpc_shutdown(); } -#endif /* Initialize the GRPC module structs */ @@ -300,18 +289,30 @@ VALUE sym_code = Qundef; VALUE sym_details = Qundef; VALUE sym_metadata = Qundef; +static gpr_once g_once_init = GPR_ONCE_INIT; + +static void grpc_ruby_once_init() { + grpc_init(); + atexit(grpc_rb_shutdown); +} + void Init_grpc_c() { if (!grpc_rb_load_core()) { rb_raise(rb_eLoadError, "Couldn't find or load gRPC's dynamic C core"); return; } - grpc_init(); - -/* TODO: find alternative to ruby_vm_at_exit that is ok in Ruby 2.0 */ -#ifdef RUBY_TYPED_FREE_IMMEDIATELY - ruby_vm_at_exit(grpc_rb_shutdown); -#endif + /* ruby_vm_at_exit doesn't seem to be working. It would crash once every + * blue moon, and some users are getting it repeatedly. See the discussions + * - https://github.com/grpc/grpc/pull/5337 + * - https://bugs.ruby-lang.org/issues/12095 + * + * In order to still be able to handle the (unlikely) situation where the + * extension is loaded by a first Ruby VM that is subsequently destroyed, + * then loaded again by another VM within the same process, we need to + * schedule our initialization and destruction only once. + */ + gpr_once_init(&g_once_init, grpc_ruby_once_init); grpc_rb_mGRPC = rb_define_module("GRPC"); grpc_rb_mGrpcCore = rb_define_module_under(grpc_rb_mGRPC, "Core"); diff --git a/src/ruby/lib/grpc/core/time_consts.rb b/src/ruby/lib/grpc/core/time_consts.rb index e6dae7b08a..c8eae7806b 100644 --- a/src/ruby/lib/grpc/core/time_consts.rb +++ b/src/ruby/lib/grpc/core/time_consts.rb @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -require 'grpc' +require 'grpc/grpc' # GRPC contains the General RPC module. module GRPC diff --git a/src/ruby/lib/grpc/errors.rb b/src/ruby/lib/grpc/errors.rb index f1201c1704..2227ee1f12 100644 --- a/src/ruby/lib/grpc/errors.rb +++ b/src/ruby/lib/grpc/errors.rb @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -require 'grpc' +require 'grpc/grpc' # GRPC contains the General RPC module. module GRPC |