Resolved merge conflicts with master

pull/1014/head
murgatroid99 10 years ago
commit 892c3cac05
  1. 47
      Makefile
  2. 12
      include/grpc/grpc_security.h
  3. 1
      include/grpc/support/atm_gcc_atomic.h
  4. 11
      include/grpc/support/atm_gcc_sync.h
  5. 5
      include/grpc/support/atm_win32.h
  6. 80
      src/compiler/python_generator.cc
  7. 10
      src/compiler/python_plugin.cc
  8. 8
      src/core/iomgr/fd_posix.c
  9. 79
      src/core/security/credentials.c
  10. 16
      src/core/security/credentials.h
  11. 19
      src/core/security/google_default_credentials.c
  12. 79
      src/core/security/json_token.c
  13. 23
      src/core/security/json_token.h
  14. 10
      src/core/transport/chttp2_transport.c
  15. 2
      src/cpp/client/insecure_credentials.cc
  16. 2
      src/cpp/client/secure_credentials.cc
  17. 8
      src/csharp/Grpc.Core.Tests/ClientServerTest.cs
  18. 2
      src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
  19. 35
      src/csharp/Grpc.Core.Tests/PInvokeTest.cs
  20. 10
      src/csharp/Grpc.Core.Tests/Properties/AssemblyInfo.cs
  21. 1
      src/csharp/Grpc.Core.Tests/ServerTest.cs
  22. 1
      src/csharp/Grpc.Core.Tests/TimespecTest.cs
  23. 4
      src/csharp/Grpc.Core/Call.cs
  24. 6
      src/csharp/Grpc.Core/Calls.cs
  25. 5
      src/csharp/Grpc.Core/Channel.cs
  26. 47
      src/csharp/Grpc.Core/ChannelArgs.cs
  27. 1
      src/csharp/Grpc.Core/ClientStreamingAsyncResult.cs
  28. 4
      src/csharp/Grpc.Core/Credentials.cs
  29. 10
      src/csharp/Grpc.Core/Grpc.Core.csproj
  30. 8
      src/csharp/Grpc.Core/GrpcEnvironment.cs
  31. 14
      src/csharp/Grpc.Core/Internal/AsyncCall.cs
  32. 18
      src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
  33. 1
      src/csharp/Grpc.Core/Internal/AsyncCompletion.cs
  34. 8
      src/csharp/Grpc.Core/Internal/BatchContextSafeHandleNotOwned.cs
  35. 7
      src/csharp/Grpc.Core/Internal/CallSafeHandle.cs
  36. 1
      src/csharp/Grpc.Core/Internal/ChannelArgsSafeHandle.cs
  37. 1
      src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
  38. 1
      src/csharp/Grpc.Core/Internal/Enums.cs
  39. 4
      src/csharp/Grpc.Core/Internal/GrpcLog.cs
  40. 17
      src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs
  41. 1
      src/csharp/Grpc.Core/Internal/SafeHandleZeroIsInvalid.cs
  42. 9
      src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
  43. 68
      src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs
  44. 11
      src/csharp/Grpc.Core/Internal/ServerSafeHandle.cs
  45. 1
      src/csharp/Grpc.Core/Internal/ServerStreamingOutputObserver.cs
  46. 11
      src/csharp/Grpc.Core/Internal/Timespec.cs
  47. 15
      src/csharp/Grpc.Core/Marshaller.cs
  48. 1
      src/csharp/Grpc.Core/Method.cs
  49. 1
      src/csharp/Grpc.Core/OperationFailedException.cs
  50. 28
      src/csharp/Grpc.Core/Properties/AssemblyInfo.cs
  51. 4
      src/csharp/Grpc.Core/RpcException.cs
  52. 47
      src/csharp/Grpc.Core/Server.cs
  53. 11
      src/csharp/Grpc.Core/ServerCalls.cs
  54. 109
      src/csharp/Grpc.Core/ServerCredentials.cs
  55. 22
      src/csharp/Grpc.Core/ServerServiceDefinition.cs
  56. 5
      src/csharp/Grpc.Core/StatusCode.cs
  57. 7
      src/csharp/Grpc.Core/Utils/BenchmarkUtil.cs
  58. 4
      src/csharp/Grpc.Core/Utils/ExceptionHelper.cs
  59. 9
      src/csharp/Grpc.Core/Utils/Preconditions.cs
  60. 4
      src/csharp/Grpc.Core/Utils/RecordingObserver.cs
  61. 5
      src/csharp/Grpc.Core/Utils/RecordingQueue.cs
  62. 4
      src/csharp/Grpc.Core/packages.config
  63. 28
      src/csharp/Grpc.Examples.MathClient/Properties/AssemblyInfo.cs
  64. 13
      src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs
  65. 10
      src/csharp/Grpc.Examples.Tests/Properties/AssemblyInfo.cs
  66. 21
      src/csharp/Grpc.Examples/MathExamples.cs
  67. 57
      src/csharp/Grpc.Examples/MathGrpc.cs
  68. 13
      src/csharp/Grpc.Examples/MathServiceImpl.cs
  69. 28
      src/csharp/Grpc.Examples/Properties/AssemblyInfo.cs
  70. 10
      src/csharp/Grpc.Examples/Settings.StyleCop
  71. 10
      src/csharp/Grpc.IntegrationTesting.Client/Properties/AssemblyInfo.cs
  72. 10
      src/csharp/Grpc.IntegrationTesting.Server/Properties/AssemblyInfo.cs
  73. 12
      src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
  74. 31
      src/csharp/Grpc.IntegrationTesting/InteropClient.cs
  75. 12
      src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs
  76. 16
      src/csharp/Grpc.IntegrationTesting/InteropServer.cs
  77. 10
      src/csharp/Grpc.IntegrationTesting/Properties/AssemblyInfo.cs
  78. 11
      src/csharp/Grpc.IntegrationTesting/Settings.StyleCop
  79. 84
      src/csharp/Grpc.IntegrationTesting/TestCredentials.cs
  80. 95
      src/csharp/Grpc.IntegrationTesting/TestServiceGrpc.cs
  81. 33
      src/csharp/Grpc.IntegrationTesting/TestServiceImpl.cs
  82. 1
      src/csharp/Grpc.IntegrationTesting/packages.config
  83. 509
      src/csharp/Settings.StyleCop
  84. 35
      src/csharp/ext/grpc_csharp_ext.c
  85. 6
      src/node/README.md
  86. 2
      src/node/package.json
  87. 2
      src/php/ext/grpc/call.c
  88. 2
      src/php/ext/grpc/call.h
  89. 2
      src/php/ext/grpc/channel.c
  90. 2
      src/php/ext/grpc/channel.h
  91. 2
      src/php/ext/grpc/credentials.c
  92. 2
      src/php/ext/grpc/credentials.h
  93. 2
      src/php/ext/grpc/server.c
  94. 2
      src/php/ext/grpc/server.h
  95. 2
      src/php/ext/grpc/server_credentials.c
  96. 2
      src/php/ext/grpc/server_credentials.h
  97. 2
      src/php/ext/grpc/timeval.c
  98. 2
      src/php/ext/grpc/timeval.h
  99. 2
      src/python/src/grpc/_adapter/_call.c
  100. 3
      src/python/src/grpc/early_adopter/implementations.py
  101. Some files were not shown because too many files have changed in this diff Show More

@ -159,9 +159,14 @@ ifndef VALID_CONFIG_$(CONFIG)
$(error Invalid CONFIG value '$(CONFIG)')
endif
ifeq ($(SYSTEM),Linux)
TMPOUT = /dev/null
else
TMPOUT = `mktemp /tmp/test-out-XXXXXX`
endif
# Detect if we can use C++11
CXX11_CHECK_CMD = $(CXX) -std=c++11 -o /dev/null -c test/build/c++11.cc
CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
# The HOST compiler settings are used to compile the protoc plugins.
@ -194,9 +199,25 @@ LDFLAGS += -g -fPIC
INCLUDES = . include $(GENDIR)
ifeq ($(SYSTEM),Darwin)
INCLUDES += /usr/local/ssl/include /opt/local/include
ifneq ($(wildcard /usr/local/ssl/include),)
INCLUDES += /usr/local/ssl/include
endif
ifneq ($(wildcard /opt/local/include),)
INCLUDES += /opt/local/include
endif
ifneq ($(wildcard /usr/local/include),)
INCLUDES += /usr/local/include
endif
LIBS = m z
LDFLAGS += -L/usr/local/ssl/lib -L/opt/local/lib
ifneq ($(wildcard /usr/local/ssl/lib),)
LDFLAGS += -L/usr/local/ssl/lib
endif
ifneq ($(wildcard /opt/local/lib),)
LDFLAGS += -L/opt/local/lib
endif
ifneq ($(wildcard /usr/local/lib),)
LDFLAGS += -L/usr/local/lib
endif
else
LIBS = rt m z pthread
LDFLAGS += -pthread
@ -251,10 +272,10 @@ else
IS_GIT_FOLDER = true
endif
OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS)
ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/zlib.c -lz $(LDFLAGS)
PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/perftools.c -lprofiler $(LDFLAGS)
PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o /dev/null test/build/protobuf.cc -lprotobuf $(LDFLAGS)
OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS)
ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
PROTOC_CMD = which protoc
PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
@ -2036,10 +2057,10 @@ ifeq ($(SYSTEM),MINGW32)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/gpr.$(SHARED_EXT) $(prefix)/lib/gpr.$(SHARED_EXT)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgpr-imp.a $(prefix)/lib/libgpr-imp.a
else
ifneq ($(SYSTEM),Darwin)
$(E) "[INSTALL] Installing libgpr.$(SHARED_EXT)"
$(Q) $(INSTALL) -d $(prefix)/lib
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgpr.$(SHARED_EXT) $(prefix)/lib/libgpr.$(SHARED_EXT)
ifneq ($(SYSTEM),Darwin)
$(Q) ln -sf libgpr.$(SHARED_EXT) $(prefix)/lib/libgpr.so
endif
endif
@ -2049,10 +2070,10 @@ ifeq ($(SYSTEM),MINGW32)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc.$(SHARED_EXT) $(prefix)/lib/grpc.$(SHARED_EXT)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc-imp.a $(prefix)/lib/libgrpc-imp.a
else
ifneq ($(SYSTEM),Darwin)
$(E) "[INSTALL] Installing libgrpc.$(SHARED_EXT)"
$(Q) $(INSTALL) -d $(prefix)/lib
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) $(prefix)/lib/libgrpc.$(SHARED_EXT)
ifneq ($(SYSTEM),Darwin)
$(Q) ln -sf libgrpc.$(SHARED_EXT) $(prefix)/lib/libgrpc.so
endif
endif
@ -2062,10 +2083,10 @@ ifeq ($(SYSTEM),MINGW32)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc_unsecure.$(SHARED_EXT) $(prefix)/lib/grpc_unsecure.$(SHARED_EXT)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure-imp.a $(prefix)/lib/libgrpc_unsecure-imp.a
else
ifneq ($(SYSTEM),Darwin)
$(E) "[INSTALL] Installing libgrpc_unsecure.$(SHARED_EXT)"
$(Q) $(INSTALL) -d $(prefix)/lib
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) $(prefix)/lib/libgrpc_unsecure.$(SHARED_EXT)
ifneq ($(SYSTEM),Darwin)
$(Q) ln -sf libgrpc_unsecure.$(SHARED_EXT) $(prefix)/lib/libgrpc_unsecure.so
endif
endif
@ -2083,10 +2104,10 @@ ifeq ($(SYSTEM),MINGW32)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc++.$(SHARED_EXT) $(prefix)/lib/grpc++.$(SHARED_EXT)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++-imp.a $(prefix)/lib/libgrpc++-imp.a
else
ifneq ($(SYSTEM),Darwin)
$(E) "[INSTALL] Installing libgrpc++.$(SHARED_EXT)"
$(Q) $(INSTALL) -d $(prefix)/lib
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++.$(SHARED_EXT) $(prefix)/lib/libgrpc++.$(SHARED_EXT)
ifneq ($(SYSTEM),Darwin)
$(Q) ln -sf libgrpc++.$(SHARED_EXT) $(prefix)/lib/libgrpc++.so
endif
endif
@ -2096,10 +2117,10 @@ ifeq ($(SYSTEM),MINGW32)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc++_unsecure.$(SHARED_EXT) $(prefix)/lib/grpc++_unsecure.$(SHARED_EXT)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure-imp.a $(prefix)/lib/libgrpc++_unsecure-imp.a
else
ifneq ($(SYSTEM),Darwin)
$(E) "[INSTALL] Installing libgrpc++_unsecure.$(SHARED_EXT)"
$(Q) $(INSTALL) -d $(prefix)/lib
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.$(SHARED_EXT) $(prefix)/lib/libgrpc++_unsecure.$(SHARED_EXT)
ifneq ($(SYSTEM),Darwin)
$(Q) ln -sf libgrpc++_unsecure.$(SHARED_EXT) $(prefix)/lib/libgrpc++_unsecure.so
endif
endif
@ -2117,10 +2138,10 @@ ifeq ($(SYSTEM),MINGW32)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/grpc_csharp_ext.$(SHARED_EXT)
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext-imp.a $(prefix)/lib/libgrpc_csharp_ext-imp.a
else
ifneq ($(SYSTEM),Darwin)
$(E) "[INSTALL] Installing libgrpc_csharp_ext.$(SHARED_EXT)"
$(Q) $(INSTALL) -d $(prefix)/lib
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/libgrpc_csharp_ext.$(SHARED_EXT)
ifneq ($(SYSTEM),Darwin)
$(Q) ln -sf libgrpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/libgrpc_csharp_ext.so
endif
endif

@ -117,6 +117,15 @@ grpc_credentials *grpc_service_account_credentials_create(
grpc_credentials *grpc_jwt_credentials_create(const char *json_key,
gpr_timespec token_lifetime);
/* Creates an Oauth2 Refresh Token crednetials object. May return NULL if the
input is invalid.
WARNING: Do NOT use this credentials to connect to a non-google service as
this could result in an oauth2 token leak.
- json_refresh_token is the JSON string containing the refresh token itself
along with a client_id and client_secret. */
grpc_credentials *grpc_refresh_token_credentials_create(
const char *json_refresh_token);
/* Creates a fake transport security credentials object for testing. */
grpc_credentials *grpc_fake_transport_security_credentials_create(void);
@ -167,10 +176,9 @@ grpc_server_credentials *grpc_ssl_server_credentials_create(
grpc_server_credentials *grpc_fake_transport_security_server_credentials_create(
void);
/* --- Secure server creation. --- */
/* --- Server-side secure ports. --- */
/* Add a HTTP2 over an encrypted link over tcp listener.
Server must have been created with grpc_secure_server_create.
Returns bound port number on success, 0 on failure.
REQUIRES: server not started */
int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,

@ -43,6 +43,7 @@ typedef gpr_intptr gpr_atm;
#define gpr_atm_full_barrier() (__atomic_thread_fence(__ATOMIC_SEQ_CST))
#define gpr_atm_acq_load(p) (__atomic_load_n((p), __ATOMIC_ACQUIRE))
#define gpr_atm_no_barrier_load(p) (__atomic_load_n((p), __ATOMIC_RELAXED))
#define gpr_atm_rel_store(p, value) \
(__atomic_store_n((p), (gpr_intptr)(value), __ATOMIC_RELEASE))

@ -40,9 +40,11 @@
typedef gpr_intptr gpr_atm;
#define GPR_ATM_COMPILE_BARRIER_() __asm__ __volatile__("" : : : "memory")
#if defined(__i386) || defined(__x86_64__)
/* All loads are acquire loads and all stores are release stores. */
#define GPR_ATM_LS_BARRIER_() __asm__ __volatile__("" : : : "memory")
#define GPR_ATM_LS_BARRIER_() GPR_ATM_COMPILE_BARRIER_()
#else
#define GPR_ATM_LS_BARRIER_() gpr_atm_full_barrier()
#endif
@ -55,12 +57,19 @@ static __inline gpr_atm gpr_atm_acq_load(const gpr_atm *p) {
return value;
}
static __inline gpr_atm gpr_atm_no_barrier_load(const gpr_atm *p) {
gpr_atm value = *p;
GPR_ATM_COMPILE_BARRIER_();
return value;
}
static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
GPR_ATM_LS_BARRIER_();
*p = value;
}
#undef GPR_ATM_LS_BARRIER_
#undef GPR_ATM_COMPILE_BARRIER_
#define gpr_atm_no_barrier_fetch_add(p, delta) \
gpr_atm_full_fetch_add((p), (delta))

@ -49,6 +49,11 @@ static __inline gpr_atm gpr_atm_acq_load(const gpr_atm *p) {
return result;
}
static __inline gpr_atm gpr_atm_no_barrier_load(const gpr_atm *p) {
/* TODO(dklempner): Can we implement something better here? */
gpr_atm_acq_load(p);
}
static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
gpr_atm_full_barrier();
*p = value;

@ -60,8 +60,6 @@ using std::make_pair;
using std::map;
using std::pair;
using std::replace;
using std::string;
using std::strlen;
using std::vector;
namespace grpc_python_generator {
@ -72,14 +70,14 @@ namespace {
// Converts an initializer list of the form { key0, value0, key1, value1, ... }
// into a map of key* to value*. Is merely a readability helper for later code.
map<string, string> ListToDict(const initializer_list<string>& values) {
map<std::string, std::string> ListToDict(const initializer_list<std::string>& values) {
assert(values.size() % 2 == 0);
map<string, string> value_map;
map<std::string, std::string> value_map;
auto value_iter = values.begin();
for (unsigned i = 0; i < values.size()/2; ++i) {
string key = *value_iter;
std::string key = *value_iter;
++value_iter;
string value = *value_iter;
std::string value = *value_iter;
value_map[key] = value;
++value_iter;
}
@ -113,8 +111,8 @@ class IndentScope {
bool PrintServicer(const ServiceDescriptor* service,
Printer* out) {
string doc = "<fill me in later!>";
map<string, string> dict = ListToDict({
std::string doc = "<fill me in later!>";
map<std::string, std::string> dict = ListToDict({
"Service", service->name(),
"Documentation", doc,
});
@ -125,7 +123,7 @@ bool PrintServicer(const ServiceDescriptor* service,
out->Print("__metaclass__ = abc.ABCMeta\n");
for (int i = 0; i < service->method_count(); ++i) {
auto meth = service->method(i);
string arg_name = meth->client_streaming() ?
std::string arg_name = meth->client_streaming() ?
"request_iterator" : "request";
out->Print("@abc.abstractmethod\n");
out->Print("def $Method$(self, $ArgName$, context):\n",
@ -140,8 +138,8 @@ bool PrintServicer(const ServiceDescriptor* service,
}
bool PrintServer(const ServiceDescriptor* service, Printer* out) {
string doc = "<fill me in later!>";
map<string, string> dict = ListToDict({
std::string doc = "<fill me in later!>";
map<std::string, std::string> dict = ListToDict({
"Service", service->name(),
"Documentation", doc,
});
@ -169,8 +167,8 @@ bool PrintServer(const ServiceDescriptor* service, Printer* out) {
bool PrintStub(const ServiceDescriptor* service,
Printer* out) {
string doc = "<fill me in later!>";
map<string, string> dict = ListToDict({
std::string doc = "<fill me in later!>";
map<std::string, std::string> dict = ListToDict({
"Service", service->name(),
"Documentation", doc,
});
@ -181,7 +179,7 @@ bool PrintStub(const ServiceDescriptor* service,
out->Print("__metaclass__ = abc.ABCMeta\n");
for (int i = 0; i < service->method_count(); ++i) {
const MethodDescriptor* meth = service->method(i);
string arg_name = meth->client_streaming() ?
std::string arg_name = meth->client_streaming() ?
"request_iterator" : "request";
auto methdict = ListToDict({"Method", meth->name(), "ArgName", arg_name});
out->Print("@abc.abstractmethod\n");
@ -198,29 +196,29 @@ bool PrintStub(const ServiceDescriptor* service,
// TODO(protobuf team): Export `ModuleName` from protobuf's
// `src/google/protobuf/compiler/python/python_generator.cc` file.
string ModuleName(const string& filename) {
string basename = StripProto(filename);
std::string ModuleName(const std::string& filename) {
std::string basename = StripProto(filename);
basename = StringReplace(basename, "-", "_");
basename = StringReplace(basename, "/", ".");
return basename + "_pb2";
}
bool GetModuleAndMessagePath(const Descriptor* type,
pair<string, string>* out) {
pair<std::string, std::string>* out) {
const Descriptor* path_elem_type = type;
vector<const Descriptor*> message_path;
do {
message_path.push_back(path_elem_type);
path_elem_type = path_elem_type->containing_type();
} while (path_elem_type != nullptr);
string file_name = type->file()->name();
std::string file_name = type->file()->name();
static const int proto_suffix_length = strlen(".proto");
if (!(file_name.size() > static_cast<size_t>(proto_suffix_length) &&
file_name.find_last_of(".proto") == file_name.size() - 1)) {
return false;
}
string module = ModuleName(file_name);
string message_type;
std::string module = ModuleName(file_name);
std::string message_type;
for (auto path_iter = message_path.rbegin();
path_iter != message_path.rend(); ++path_iter) {
message_type += (*path_iter)->name() + ".";
@ -237,21 +235,21 @@ bool PrintServerFactory(const ServiceDescriptor* service, Printer* out) {
"Service", service->name());
{
IndentScope raii_create_server_indent(out);
map<string, string> method_description_constructors;
map<string, pair<string, string>> input_message_modules_and_classes;
map<string, pair<string, string>> output_message_modules_and_classes;
map<std::string, std::string> method_description_constructors;
map<std::string, pair<std::string, std::string>> input_message_modules_and_classes;
map<std::string, pair<std::string, std::string>> output_message_modules_and_classes;
for (int i = 0; i < service->method_count(); ++i) {
const MethodDescriptor* method = service->method(i);
const string method_description_constructor =
string(method->client_streaming() ? "stream_" : "unary_") +
string(method->server_streaming() ? "stream_" : "unary_") +
const std::string method_description_constructor =
std::string(method->client_streaming() ? "stream_" : "unary_") +
std::string(method->server_streaming() ? "stream_" : "unary_") +
"service_description";
pair<string, string> input_message_module_and_class;
pair<std::string, std::string> input_message_module_and_class;
if (!GetModuleAndMessagePath(method->input_type(),
&input_message_module_and_class)) {
return false;
}
pair<string, string> output_message_module_and_class;
pair<std::string, std::string> output_message_module_and_class;
if (!GetModuleAndMessagePath(method->output_type(),
&output_message_module_and_class)) {
return false;
@ -272,7 +270,7 @@ bool PrintServerFactory(const ServiceDescriptor* service, Printer* out) {
for (auto& name_and_description_constructor :
method_description_constructors) {
IndentScope raii_descriptions_indent(out);
const string method_name = name_and_description_constructor.first;
const std::string method_name = name_and_description_constructor.first;
auto input_message_module_and_class =
input_message_modules_and_classes.find(method_name);
auto output_message_module_and_class =
@ -306,27 +304,27 @@ bool PrintServerFactory(const ServiceDescriptor* service, Printer* out) {
}
bool PrintStubFactory(const ServiceDescriptor* service, Printer* out) {
map<string, string> dict = ListToDict({
map<std::string, std::string> dict = ListToDict({
"Service", service->name(),
});
out->Print(dict, "def early_adopter_create_$Service$_stub(host, port):\n");
{
IndentScope raii_create_server_indent(out);
map<string, string> method_description_constructors;
map<string, pair<string, string>> input_message_modules_and_classes;
map<string, pair<string, string>> output_message_modules_and_classes;
map<std::string, std::string> method_description_constructors;
map<std::string, pair<std::string, std::string>> input_message_modules_and_classes;
map<std::string, pair<std::string, std::string>> output_message_modules_and_classes;
for (int i = 0; i < service->method_count(); ++i) {
const MethodDescriptor* method = service->method(i);
const string method_description_constructor =
string(method->client_streaming() ? "stream_" : "unary_") +
string(method->server_streaming() ? "stream_" : "unary_") +
const std::string method_description_constructor =
std::string(method->client_streaming() ? "stream_" : "unary_") +
std::string(method->server_streaming() ? "stream_" : "unary_") +
"invocation_description";
pair<string, string> input_message_module_and_class;
pair<std::string, std::string> input_message_module_and_class;
if (!GetModuleAndMessagePath(method->input_type(),
&input_message_module_and_class)) {
return false;
}
pair<string, string> output_message_module_and_class;
pair<std::string, std::string> output_message_module_and_class;
if (!GetModuleAndMessagePath(method->output_type(),
&output_message_module_and_class)) {
return false;
@ -347,7 +345,7 @@ bool PrintStubFactory(const ServiceDescriptor* service, Printer* out) {
for (auto& name_and_description_constructor :
method_description_constructors) {
IndentScope raii_descriptions_indent(out);
const string method_name = name_and_description_constructor.first;
const std::string method_name = name_and_description_constructor.first;
auto input_message_module_and_class =
input_message_modules_and_classes.find(method_name);
auto output_message_module_and_class =
@ -385,8 +383,8 @@ bool PrintPreamble(const FileDescriptor* file, Printer* out) {
} // namespace
pair<bool, string> GetServices(const FileDescriptor* file) {
string output;
pair<bool, std::string> GetServices(const FileDescriptor* file) {
std::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
StringOutputStream output_stream(&output);

@ -51,18 +51,16 @@ using google::protobuf::compiler::GeneratorContext;
using google::protobuf::compiler::PluginMain;
using google::protobuf::io::CodedOutputStream;
using google::protobuf::io::ZeroCopyOutputStream;
using std::string;
using std::strlen;
class PythonGrpcGenerator : public CodeGenerator {
public:
PythonGrpcGenerator() {}
~PythonGrpcGenerator() {}
bool Generate(const FileDescriptor* file, const string& parameter,
GeneratorContext* context, string* error) const {
bool Generate(const FileDescriptor* file, const std::string& parameter,
GeneratorContext* context, std::string* error) const {
// Get output file name.
string file_name;
std::string file_name;
static const int proto_suffix_length = strlen(".proto");
if (file->name().size() > static_cast<size_t>(proto_suffix_length) &&
file->name().find_last_of(".proto") == file->name().size() - 1) {
@ -77,7 +75,7 @@ class PythonGrpcGenerator : public CodeGenerator {
context->OpenForInsert(file_name, "module_scope"));
CodedOutputStream coded_out(output.get());
bool success = false;
string code = "";
std::string code = "";
tie(success, code) = grpc_python_generator::GetServices(file);
if (success) {
coded_out.WriteRaw(code.data(), code.size());

@ -210,7 +210,7 @@ static void notify_on(grpc_fd *fd, gpr_atm *st, grpc_iomgr_closure *closure,
/* swap was unsuccessful due to an intervening set_ready call.
Fall through to the READY code below */
case READY:
assert(gpr_atm_acq_load(st) == READY);
assert(gpr_atm_no_barrier_load(st) == READY);
gpr_atm_rel_store(st, NOT_READY);
make_callback(closure->cb, closure->cb_arg,
!gpr_atm_acq_load(&fd->shutdown),
@ -245,8 +245,8 @@ static void set_ready_locked(gpr_atm *st, grpc_iomgr_closure *callbacks,
Fall through to the WAITING code below */
state = gpr_atm_acq_load(st);
default: /* waiting */
assert(gpr_atm_acq_load(st) != READY &&
gpr_atm_acq_load(st) != NOT_READY);
assert(gpr_atm_no_barrier_load(st) != READY &&
gpr_atm_no_barrier_load(st) != NOT_READY);
callbacks[(*ncallbacks)++] = *(grpc_iomgr_closure *)state;
gpr_atm_rel_store(st, NOT_READY);
return;
@ -271,7 +271,7 @@ void grpc_fd_shutdown(grpc_fd *fd) {
grpc_iomgr_closure cb[2];
size_t ncb = 0;
gpr_mu_lock(&fd->set_state_mu);
GPR_ASSERT(!gpr_atm_acq_load(&fd->shutdown));
GPR_ASSERT(!gpr_atm_no_barrier_load(&fd->shutdown));
gpr_atm_rel_store(&fd->shutdown, 1);
set_ready_locked(&fd->readst, cb, &ncb);
set_ready_locked(&fd->writest, cb, &ncb);

@ -46,20 +46,6 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
/* -- Constants. -- */
#define GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS 60
#define GRPC_COMPUTE_ENGINE_METADATA_HOST "metadata"
#define GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH \
"/computeMetadata/v1/instance/service-accounts/default/token"
#define GRPC_SERVICE_ACCOUNT_HOST "www.googleapis.com"
#define GRPC_SERVICE_ACCOUNT_TOKEN_PATH "/oauth2/v3/token"
#define GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX \
"grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" \
"assertion="
/* -- Common. -- */
typedef struct {
@ -671,8 +657,8 @@ static void service_account_fetch_oauth2(
}
gpr_asprintf(&body, "%s%s", GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX, jwt);
memset(&request, 0, sizeof(grpc_httpcli_request));
request.host = GRPC_SERVICE_ACCOUNT_HOST;
request.path = GRPC_SERVICE_ACCOUNT_TOKEN_PATH;
request.host = GRPC_GOOGLE_OAUTH2_SERVICE_HOST;
request.path = GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH;
request.hdr_count = 1;
request.hdrs = &header;
request.use_ssl = 1;
@ -703,6 +689,67 @@ grpc_credentials *grpc_service_account_credentials_create(
return &c->base.base;
}
/* -- RefreshToken credentials. -- */
typedef struct {
grpc_oauth2_token_fetcher_credentials base;
grpc_auth_refresh_token refresh_token;
} grpc_refresh_token_credentials;
static void refresh_token_destroy(grpc_credentials *creds) {
grpc_refresh_token_credentials *c =
(grpc_refresh_token_credentials *)creds;
grpc_auth_refresh_token_destruct(&c->refresh_token);
oauth2_token_fetcher_destroy(&c->base.base);
}
static grpc_credentials_vtable refresh_token_vtable = {
refresh_token_destroy, oauth2_token_fetcher_has_request_metadata,
oauth2_token_fetcher_has_request_metadata_only,
oauth2_token_fetcher_get_request_metadata};
static void refresh_token_fetch_oauth2(
grpc_credentials_metadata_request *metadata_req,
grpc_httpcli_response_cb response_cb, gpr_timespec deadline) {
grpc_refresh_token_credentials *c =
(grpc_refresh_token_credentials *)metadata_req->creds;
grpc_httpcli_header header = {"Content-Type",
"application/x-www-form-urlencoded"};
grpc_httpcli_request request;
char *body = NULL;
gpr_asprintf(&body, GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING,
c->refresh_token.client_id, c->refresh_token.client_secret,
c->refresh_token.refresh_token);
memset(&request, 0, sizeof(grpc_httpcli_request));
request.host = GRPC_GOOGLE_OAUTH2_SERVICE_HOST;
request.path = GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH;
request.hdr_count = 1;
request.hdrs = &header;
request.use_ssl = 1;
grpc_httpcli_post(&request, body, strlen(body), deadline, response_cb,
metadata_req);
gpr_free(body);
}
grpc_credentials *grpc_refresh_token_credentials_create(
const char *json_refresh_token) {
grpc_refresh_token_credentials *c;
grpc_auth_refresh_token refresh_token =
grpc_auth_refresh_token_create_from_string(json_refresh_token);
if (!grpc_auth_refresh_token_is_valid(&refresh_token)) {
gpr_log(GPR_ERROR,
"Invalid input for refresh token credentials creation");
return NULL;
}
c = gpr_malloc(sizeof(grpc_refresh_token_credentials));
memset(c, 0, sizeof(grpc_refresh_token_credentials));
init_oauth2_token_fetcher(&c->base, refresh_token_fetch_oauth2);
c->base.base.vtable = &refresh_token_vtable;
c->refresh_token = refresh_token;
return &c->base.base;
}
/* -- Fake Oauth2 credentials. -- */
typedef struct {

@ -64,6 +64,22 @@ typedef enum {
#define GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE \
"application_default_credentials.json"
#define GRPC_SECURE_TOKEN_REFRESH_THRESHOLD_SECS 60
#define GRPC_COMPUTE_ENGINE_METADATA_HOST "metadata"
#define GRPC_COMPUTE_ENGINE_METADATA_TOKEN_PATH \
"/computeMetadata/v1/instance/service-accounts/default/token"
#define GRPC_GOOGLE_OAUTH2_SERVICE_HOST "www.googleapis.com"
#define GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH "/oauth2/v3/token"
#define GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX \
"grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" \
"assertion="
#define GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING \
"client_id=%s&client_secret=%s&refresh_token=%s&grant_type=refresh_token"
/* --- grpc_credentials. --- */
/* It is the caller's responsibility to gpr_free the result if not NULL. */

@ -138,6 +138,23 @@ static grpc_credentials *create_jwt_creds_from_path(char *creds_path) {
return result;
}
/* Takes ownership of creds_path if not NULL. */
static grpc_credentials *create_refresh_token_creds_from_path(
char *creds_path) {
grpc_credentials *result = NULL;
gpr_slice creds_data;
int file_ok = 0;
if (creds_path == NULL) return NULL;
creds_data = gpr_load_file(creds_path, &file_ok);
gpr_free(creds_path);
if (file_ok) {
result = grpc_refresh_token_credentials_create(
(const char *)GPR_SLICE_START_PTR(creds_data));
gpr_slice_unref(creds_data);
}
return result;
}
grpc_credentials *grpc_google_default_credentials_create(void) {
grpc_credentials *result = NULL;
int serving_cached_credentials = 0;
@ -157,7 +174,7 @@ grpc_credentials *grpc_google_default_credentials_create(void) {
if (result != NULL) goto end;
/* Then the well-known file. */
result = create_jwt_creds_from_path(
result = create_refresh_token_creds_from_path(
grpc_get_well_known_google_credentials_file_path());
if (result != NULL) goto end;

@ -52,8 +52,9 @@
/* 1 hour max. */
const gpr_timespec grpc_max_auth_token_lifetime = {3600, 0};
#define GRPC_AUTH_JSON_KEY_TYPE_INVALID "invalid"
#define GRPC_AUTH_JSON_KEY_TYPE_SERVICE_ACCOUNT "service_account"
#define GRPC_AUTH_JSON_TYPE_INVALID "invalid"
#define GRPC_AUTH_JSON_TYPE_SERVICE_ACCOUNT "service_account"
#define GRPC_AUTH_JSON_TYPE_AUTHORIZED_USER "authorized_user"
#define GRPC_JWT_RSA_SHA256_ALGORITHM "RS256"
#define GRPC_JWT_TYPE "JWT"
@ -87,7 +88,7 @@ static int set_json_key_string_property(grpc_json *json, const char *prop_name,
int grpc_auth_json_key_is_valid(const grpc_auth_json_key *json_key) {
return (json_key != NULL) &&
strcmp(json_key->type, GRPC_AUTH_JSON_KEY_TYPE_INVALID);
strcmp(json_key->type, GRPC_AUTH_JSON_TYPE_INVALID);
}
grpc_auth_json_key grpc_auth_json_key_create_from_string(
@ -100,7 +101,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string(
int success = 0;
memset(&result, 0, sizeof(grpc_auth_json_key));
result.type = GRPC_AUTH_JSON_KEY_TYPE_INVALID;
result.type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json == NULL) {
gpr_log(GPR_ERROR, "Invalid json string %s", json_string);
goto end;
@ -108,10 +109,10 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string(
prop_value = json_get_string_property(json, "type");
if (prop_value == NULL ||
strcmp(prop_value, GRPC_AUTH_JSON_KEY_TYPE_SERVICE_ACCOUNT)) {
strcmp(prop_value, GRPC_AUTH_JSON_TYPE_SERVICE_ACCOUNT)) {
goto end;
}
result.type = GRPC_AUTH_JSON_KEY_TYPE_SERVICE_ACCOUNT;
result.type = GRPC_AUTH_JSON_TYPE_SERVICE_ACCOUNT;
if (!set_json_key_string_property(json, "private_key_id",
&result.private_key_id) ||
@ -148,7 +149,7 @@ end:
void grpc_auth_json_key_destruct(grpc_auth_json_key *json_key) {
if (json_key == NULL) return;
json_key->type = GRPC_AUTH_JSON_KEY_TYPE_INVALID;
json_key->type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json_key->client_id != NULL) {
gpr_free(json_key->client_id);
json_key->client_id = NULL;
@ -331,3 +332,67 @@ void grpc_jwt_encode_and_sign_set_override(
grpc_jwt_encode_and_sign_override func) {
g_jwt_encode_and_sign_override = func;
}
/* --- grpc_auth_refresh_token --- */
int grpc_auth_refresh_token_is_valid(
const grpc_auth_refresh_token *refresh_token) {
return (refresh_token != NULL) &&
strcmp(refresh_token->type, GRPC_AUTH_JSON_TYPE_INVALID);
}
grpc_auth_refresh_token grpc_auth_refresh_token_create_from_string(
const char *json_string) {
grpc_auth_refresh_token result;
char *scratchpad = gpr_strdup(json_string);
grpc_json *json = grpc_json_parse_string(scratchpad);
const char *prop_value;
int success = 0;
memset(&result, 0, sizeof(grpc_auth_refresh_token));
result.type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json == NULL) {
gpr_log(GPR_ERROR, "Invalid json string %s", json_string);
goto end;
}
prop_value = json_get_string_property(json, "type");
if (prop_value == NULL ||
strcmp(prop_value, GRPC_AUTH_JSON_TYPE_AUTHORIZED_USER)) {
goto end;
}
result.type = GRPC_AUTH_JSON_TYPE_AUTHORIZED_USER;
if (!set_json_key_string_property(json, "client_secret",
&result.client_secret) ||
!set_json_key_string_property(json, "client_id", &result.client_id) ||
!set_json_key_string_property(json, "refresh_token",
&result.refresh_token)) {
goto end;
}
success = 1;
end:
if (json != NULL) grpc_json_destroy(json);
if (!success) grpc_auth_refresh_token_destruct(&result);
gpr_free(scratchpad);
return result;
}
void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token *refresh_token) {
if (refresh_token == NULL) return;
refresh_token->type = GRPC_AUTH_JSON_TYPE_INVALID;
if (refresh_token->client_id != NULL) {
gpr_free(refresh_token->client_id);
refresh_token->client_id = NULL;
}
if (refresh_token->client_secret != NULL) {
gpr_free(refresh_token->client_secret);
refresh_token->client_secret = NULL;
}
if (refresh_token->refresh_token != NULL) {
gpr_free(refresh_token->refresh_token);
refresh_token->refresh_token = NULL;
}
}

@ -44,7 +44,7 @@
/* --- auth_json_key parsing. --- */
typedef struct {
char *type;
const char *type;
char *private_key_id;
char *client_id;
char *client_email;
@ -79,4 +79,25 @@ typedef char *(*grpc_jwt_encode_and_sign_override)(
void grpc_jwt_encode_and_sign_set_override(
grpc_jwt_encode_and_sign_override func);
/* --- auth_refresh_token parsing. --- */
typedef struct {
const char *type;
char *client_id;
char *client_secret;
char *refresh_token;
} grpc_auth_refresh_token;
/* Returns 1 if the object is valid, 0 otherwise. */
int grpc_auth_refresh_token_is_valid(
const grpc_auth_refresh_token *refresh_token);
/* Creates a refresh token object from string. Returns an invalid object if a
parsing error has been encountered. */
grpc_auth_refresh_token grpc_auth_refresh_token_create_from_string(
const char *json_string);
/* Destructs the object. */
void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token *refresh_token);
#endif /* GRPC_INTERNAL_CORE_SECURITY_JSON_TOKEN_H */

@ -1655,7 +1655,15 @@ static int process_read(transport *t, gpr_slice slice) {
if (!init_frame_parser(t)) {
return 0;
}
t->last_incoming_stream_id = t->incoming_stream_id;
/* t->last_incoming_stream_id is used as last-stream-id when
sending GOAWAY frame.
https://tools.ietf.org/html/draft-ietf-httpbis-http2-17#section-6.8
says that last-stream-id is peer-initiated stream ID. So,
since we don't have server pushed streams, client should send
GOAWAY last-stream-id=0 in this case. */
if (!t->is_client) {
t->last_incoming_stream_id = t->incoming_stream_id;
}
if (t->incoming_frame_size == 0) {
if (!parse_frame_slice(t, gpr_empty_slice(), 1)) {
return 0;

@ -54,7 +54,7 @@ class InsecureCredentialsImpl GRPC_FINAL : public Credentials {
target, grpc_channel_create(target.c_str(), &channel_args)));
}
SecureCredentials* AsSecureCredentials() { return nullptr; }
SecureCredentials* AsSecureCredentials() GRPC_OVERRIDE { return nullptr; }
};
} // namespace

@ -59,7 +59,7 @@ class SecureCredentials GRPC_FINAL : public Credentials {
grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args)));
}
SecureCredentials* AsSecureCredentials() { return this; }
SecureCredentials* AsSecureCredentials() GRPC_OVERRIDE { return this; }
private:
grpc_credentials* const c_creds_;

@ -122,10 +122,13 @@ namespace Grpc.Core.Tests
{
var call = new Call<string, string>(unaryEchoStringMethod, channel);
try {
try
{
Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken));
Assert.Fail();
} catch(RpcException e) {
}
catch (RpcException e)
{
Assert.AreEqual(StatusCode.Unimplemented, e.Status.StatusCode);
}
}
@ -140,4 +143,3 @@ namespace Grpc.Core.Tests
}
}
}

@ -68,7 +68,7 @@ namespace Grpc.Core.Tests
var tp2 = GrpcEnvironment.ThreadPool;
GrpcEnvironment.Shutdown();
Assert.IsFalse(Object.ReferenceEquals(tp1, tp2));
Assert.IsFalse(object.ReferenceEquals(tp1, tp2));
}
}
}

@ -33,13 +33,13 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Internal;
using Grpc.Core.Utils;
using NUnit.Framework;
using System.Runtime.InteropServices;
namespace Grpc.Core.Tests
{
@ -73,14 +73,13 @@ namespace Grpc.Core.Tests
{
BenchmarkUtil.RunBenchmark(
100000, 1000000,
() => {
() =>
{
CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create();
cq.Dispose();
}
);
});
}
/// <summary>
/// Approximate results:
/// (~80ns Mono Linux)
@ -94,10 +93,10 @@ namespace Grpc.Core.Tests
counter = 0;
BenchmarkUtil.RunBenchmark(
1000000, 10000000,
() => {
() =>
{
grpcsharp_test_callback(handler);
}
);
});
Assert.AreNotEqual(0, counter);
}
@ -113,10 +112,10 @@ namespace Grpc.Core.Tests
counter = 0;
BenchmarkUtil.RunBenchmark(
10000, 10000,
() => {
grpcsharp_test_callback(new CompletionCallbackDelegate(Handler));
}
);
() =>
{
grpcsharp_test_callback(new CompletionCallbackDelegate(Handler));
});
Assert.AreNotEqual(0, counter);
}
@ -129,15 +128,15 @@ namespace Grpc.Core.Tests
{
BenchmarkUtil.RunBenchmark(
1000000, 100000000,
() => {
() =>
{
grpcsharp_test_nop(IntPtr.Zero);
}
);
});
}
private void Handler(GRPCOpError op, IntPtr ptr) {
counter ++;
private void Handler(GRPCOpError op, IntPtr ptr)
{
counter++;
}
}
}

@ -1,8 +1,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Grpc.Core.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@ -11,12 +9,4 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

@ -53,6 +53,5 @@ namespace Grpc.Core.Tests
GrpcEnvironment.Shutdown();
}
}
}

@ -86,4 +86,3 @@ namespace Grpc.Core.Internal.Tests
}
}
}

@ -47,7 +47,8 @@ namespace Grpc.Core
Func<TRequest, byte[]> requestSerializer,
Func<byte[], TResponse> responseDeserializer,
TimeSpan timeout,
Channel channel) {
Channel channel)
{
this.methodName = methodName;
this.requestSerializer = requestSerializer;
this.responseDeserializer = responseDeserializer;
@ -95,4 +96,3 @@ namespace Grpc.Core
}
}
}

@ -38,8 +38,6 @@ using Grpc.Core.Internal;
namespace Grpc.Core
{
// NOTE: this class is work-in-progress
/// <summary>
/// Helper methods for generated stubs to make RPC calls.
/// </summary>
@ -89,9 +87,9 @@ namespace Grpc.Core
return new ClientStreamingInputObserver<TRequest, TResponse>(asyncCall);
}
private static CompletionQueueSafeHandle GetCompletionQueue() {
private static CompletionQueueSafeHandle GetCompletionQueue()
{
return GrpcEnvironment.ThreadPool.CompletionQueue;
}
}
}

@ -36,10 +36,13 @@ using Grpc.Core.Internal;
namespace Grpc.Core
{
/// <summary>
/// gRPC Channel
/// </summary>
public class Channel : IDisposable
{
readonly ChannelSafeHandle handle;
readonly String target;
readonly string target;
/// <summary>
/// Creates a channel.

@ -30,6 +30,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@ -37,33 +38,18 @@ using Grpc.Core.Internal;
namespace Grpc.Core
{
// TODO: should we be using the builder pattern?
/// <summary>
/// gRPC channel options.
/// </summary>
public class ChannelArgs
{
public const string SslTargetNameOverrideKey = "grpc.ssl_target_name_override";
public class Builder
{
Dictionary<string,string> stringArgs = new Dictionary<string,string>();
// TODO: AddInteger not supported yet.
public Builder AddString(string key, string value)
{
stringArgs.Add(key, value);
return this;
}
readonly ImmutableDictionary<string, string> stringArgs;
public ChannelArgs Build()
{
return new ChannelArgs(stringArgs);
}
}
Dictionary<string,string> stringArgs;
private ChannelArgs(Dictionary<string, string> stringArgs)
private ChannelArgs(ImmutableDictionary<string, string> stringArgs)
{
// TODO: use immutable dict?
this.stringArgs = new Dictionary<string, string>(stringArgs);
this.stringArgs = stringArgs;
}
public string GetSslTargetNameOverride()
@ -76,11 +62,28 @@ namespace Grpc.Core
return null;
}
public static Builder NewBuilder()
public static Builder CreateBuilder()
{
return new Builder();
}
public class Builder
{
readonly Dictionary<string, string> stringArgs = new Dictionary<string, string>();
// TODO: AddInteger not supported yet.
public Builder AddString(string key, string value)
{
stringArgs.Add(key, value);
return this;
}
public ChannelArgs Build()
{
return new ChannelArgs(stringArgs.ToImmutableDictionary());
}
}
/// <summary>
/// Creates native object for the channel arguments.
/// </summary>

@ -36,6 +36,9 @@ using Grpc.Core.Internal;
namespace Grpc.Core
{
/// <summary>
/// Client-side credentials.
/// </summary>
public abstract class Credentials
{
/// <summary>
@ -74,4 +77,3 @@ namespace Grpc.Core
}
}
}

@ -31,6 +31,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable">
<HintPath>..\packages\System.Collections.Immutable.1.1.34-rc\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Internal\GrpcLog.cs" />
@ -54,7 +57,7 @@
<Compile Include="Internal\ServerSafeHandle.cs" />
<Compile Include="Method.cs" />
<Compile Include="ServerCalls.cs" />
<Compile Include="ServerCallHandler.cs" />
<Compile Include="Internal\ServerCallHandler.cs" />
<Compile Include="Marshaller.cs" />
<Compile Include="ServerServiceDefinition.cs" />
<Compile Include="Utils\RecordingObserver.cs" />
@ -74,6 +77,11 @@
<Compile Include="OperationFailedException.cs" />
<Compile Include="Internal\AsyncCall.cs" />
<Compile Include="Utils\Preconditions.cs" />
<Compile Include="Internal\ServerCredentialsSafeHandle.cs" />
<Compile Include="ServerCredentials.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Choose>
<!-- Under older versions of Monodevelop, Choose is not supported and is just

@ -63,8 +63,9 @@ namespace Grpc.Core
/// lifetime (and call Shutdown once you're done), for the sake of easier testing it's
/// allowed to initialize the environment again after it has been successfully shutdown.
/// </summary>
public static void Initialize() {
lock(staticLock)
public static void Initialize()
{
lock (staticLock)
{
if (instance == null)
{
@ -79,7 +80,7 @@ namespace Grpc.Core
/// </summary>
public static void Shutdown()
{
lock(staticLock)
lock (staticLock)
{
if (instance != null)
{
@ -133,4 +134,3 @@ namespace Grpc.Core
}
}
}

@ -54,7 +54,7 @@ namespace Grpc.Core.Internal
TaskCompletionSource<TResponse> unaryResponseTcs;
// Set after status is received. Only used for streaming response calls.
Nullable<Status> finishedStatus;
Status? finishedStatus;
bool readObserverCompleted; // True if readObserver has already been completed.
@ -64,7 +64,7 @@ namespace Grpc.Core.Internal
this.finishedHandler = CreateBatchCompletionCallback(HandleFinished);
}
public void Initialize(Channel channel, CompletionQueueSafeHandle cq, String methodName)
public void Initialize(Channel channel, CompletionQueueSafeHandle cq, string methodName)
{
var call = CallSafeHandle.Create(channel.Handle, cq, methodName, channel.Target, Timespec.InfFuture);
InitializeInternal(call);
@ -77,9 +77,9 @@ namespace Grpc.Core.Internal
/// <summary>
/// Blocking unary request - unary response call.
/// </summary>
public TResponse UnaryCall(Channel channel, String methodName, TRequest msg)
public TResponse UnaryCall(Channel channel, string methodName, TRequest msg)
{
using(CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
{
byte[] payload = UnsafeSerialize(msg);
@ -254,7 +254,7 @@ namespace Grpc.Core.Internal
/// </summary>
private void HandleUnaryResponse(bool wasError, BatchContextSafeHandleNotOwned ctx)
{
lock(myLock)
lock (myLock)
{
finished = true;
halfclosed = true;
@ -264,9 +264,7 @@ namespace Grpc.Core.Internal
if (wasError)
{
unaryResponseTcs.SetException(new RpcException(
new Status(StatusCode.Internal, "Internal error occured.")
));
unaryResponseTcs.SetException(new RpcException(new Status(StatusCode.Internal, "Internal error occured.")));
return;
}

@ -225,7 +225,7 @@ namespace Grpc.Core.Internal
payload = serializer(msg);
return true;
}
catch(Exception)
catch (Exception)
{
Console.WriteLine("Exception occured while trying to serialize message");
payload = null;
@ -240,7 +240,7 @@ namespace Grpc.Core.Internal
msg = deserializer(payload);
return true;
}
catch(Exception)
catch (Exception)
{
Console.WriteLine("Exception occured while trying to deserialize message");
msg = default(TRead);
@ -254,7 +254,7 @@ namespace Grpc.Core.Internal
{
readObserver.OnNext(value);
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception occured while invoking readObserver.OnNext: " + e);
}
@ -266,7 +266,7 @@ namespace Grpc.Core.Internal
{
readObserver.OnCompleted();
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception occured while invoking readObserver.OnCompleted: " + e);
}
@ -278,7 +278,7 @@ namespace Grpc.Core.Internal
{
readObserver.OnError(error);
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception occured while invoking readObserver.OnError: " + e);
}
@ -290,7 +290,7 @@ namespace Grpc.Core.Internal
{
completionDelegate(error);
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception occured while invoking completion delegate: " + e);
}
@ -302,14 +302,15 @@ namespace Grpc.Core.Internal
/// </summary>
protected CompletionCallbackDelegate CreateBatchCompletionCallback(Action<bool, BatchContextSafeHandleNotOwned> handler)
{
return new CompletionCallbackDelegate( (error, batchContextPtr) => {
return new CompletionCallbackDelegate((error, batchContextPtr) =>
{
try
{
var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);
bool wasError = (error != GRPCOpError.GRPC_OP_OK);
handler(wasError, ctx);
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Caught exception in a native handler: " + e);
}
@ -363,7 +364,6 @@ namespace Grpc.Core.Internal
{
FireCompletion(origCompletionDelegate, null);
}
}
/// <summary>

@ -91,5 +91,4 @@ namespace Grpc.Core.Internal
tcs.SetException(error);
}
}
}

@ -80,16 +80,18 @@ namespace Grpc.Core.Internal
{
return null;
}
byte[] data = new byte[(int) len];
byte[] data = new byte[(int)len];
grpcsharp_batch_context_recv_message_to_buffer(this, data, new UIntPtr((ulong)data.Length));
return data;
}
public CallSafeHandle GetServerRpcNewCall() {
public CallSafeHandle GetServerRpcNewCall()
{
return grpcsharp_batch_context_server_rpc_new_call(this);
}
public string GetServerRpcNewMethod() {
public string GetServerRpcNewMethod()
{
return Marshal.PtrToStringAnsi(grpcsharp_batch_context_server_rpc_new_method(this));
}
}

@ -36,13 +36,14 @@ using Grpc.Core;
namespace Grpc.Core.Internal
{
internal delegate void CompletionCallbackDelegate(GRPCOpError error,IntPtr batchContextPtr);
internal delegate void CompletionCallbackDelegate(GRPCOpError error, IntPtr batchContextPtr);
/// <summary>
/// grpc_call from <grpc/grpc.h>
/// </summary>
internal class CallSafeHandle : SafeHandleZeroIsInvalid
{
const UInt32 GRPC_WRITE_BUFFER_HINT = 1;
const uint GRPC_WRITE_BUFFER_HINT = 1;
[DllImport("grpc_csharp_ext.dll")]
static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline);
@ -179,7 +180,7 @@ namespace Grpc.Core.Internal
Trace.Assert(callError == GRPCCallError.GRPC_CALL_OK, "Status not GRPC_CALL_OK");
}
private static UInt32 GetFlags(bool buffered)
private static uint GetFlags(bool buffered)
{
return buffered ? 0 : GRPC_WRITE_BUFFER_HINT;
}

@ -74,4 +74,3 @@ namespace Grpc.Core.Internal
}
}
}

@ -77,4 +77,3 @@ namespace Grpc.Core.Internal
}
}
}

@ -112,4 +112,3 @@ namespace Grpc.Core.Internal
GRPC_OP_ERROR
}
}

@ -40,7 +40,7 @@ using System.Threading;
namespace Grpc.Core.Internal
{
internal delegate void GprLogDelegate(IntPtr fileStringPtr, Int32 line, UInt64 threadId, IntPtr severityStringPtr, IntPtr msgPtr);
internal delegate void GprLogDelegate(IntPtr fileStringPtr, int line, ulong threadId, IntPtr severityStringPtr, IntPtr msgPtr);
/// <summary>
/// Logs from gRPC C core library can get lost if your application is not a console app.
@ -73,7 +73,7 @@ namespace Grpc.Core.Internal
}
}
private static void HandleWrite(IntPtr fileStringPtr, Int32 line, UInt64 threadId, IntPtr severityStringPtr, IntPtr msgPtr)
private static void HandleWrite(IntPtr fileStringPtr, int line, ulong threadId, IntPtr severityStringPtr, IntPtr msgPtr)
{
try
{

@ -51,12 +51,13 @@ namespace Grpc.Core.Internal
CompletionQueueSafeHandle cq;
public GrpcThreadPool(int poolSize) {
public GrpcThreadPool(int poolSize)
{
this.poolSize = poolSize;
}
public void Start() {
public void Start()
{
lock (myLock)
{
if (cq != null)
@ -73,8 +74,8 @@ namespace Grpc.Core.Internal
}
}
public void Stop() {
public void Stop()
{
lock (myLock)
{
cq.Shutdown();
@ -86,7 +87,6 @@ namespace Grpc.Core.Internal
}
cq.Dispose();
}
}
@ -116,10 +116,9 @@ namespace Grpc.Core.Internal
do
{
completionType = cq.NextWithCallback();
} while(completionType != GRPCCompletionType.GRPC_QUEUE_SHUTDOWN);
}
while (completionType != GRPCCompletionType.GRPC_QUEUE_SHUTDOWN);
Console.WriteLine("Completion queue has shutdown successfully, thread " + Thread.CurrentThread.Name + " exiting.");
}
}
}

@ -64,4 +64,3 @@ namespace Grpc.Core.Internal
}
}
}

@ -36,7 +36,7 @@ using System.Linq;
using Grpc.Core.Internal;
using Grpc.Core.Utils;
namespace Grpc.Core
namespace Grpc.Core.Internal
{
internal interface IServerCallHandler
{
@ -70,7 +70,6 @@ namespace Grpc.Core
handler(request, responseObserver);
finishedTask.Wait();
}
}
@ -93,7 +92,7 @@ namespace Grpc.Core
asyncCall.Initialize(call);
var responseObserver = new ServerStreamingOutputObserver<TRequest,TResponse>(asyncCall);
var responseObserver = new ServerStreamingOutputObserver<TRequest, TResponse>(asyncCall);
var requestObserver = handler(responseObserver);
var finishedTask = asyncCall.ServerSideCallAsync(requestObserver);
finishedTask.Wait();
@ -113,7 +112,7 @@ namespace Grpc.Core
var finishedTask = asyncCall.ServerSideCallAsync(new NullObserver<byte[]>());
// TODO: check result of the completion status.
asyncCall.StartSendStatusFromServer(new Status(StatusCode.Unimplemented, "No such method."), new AsyncCompletionDelegate((error) => {}));
asyncCall.StartSendStatusFromServer(new Status(StatusCode.Unimplemented, "No such method."), new AsyncCompletionDelegate((error) => { }));
finishedTask.Wait();
}
@ -132,7 +131,5 @@ namespace Grpc.Core
public void OnNext(T value)
{
}
}
}

@ -0,0 +1,68 @@
#region Copyright notice and license
// 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.
#endregion
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core.Utils;
namespace Grpc.Core.Internal
{
/// <summary>
/// grpc_server_credentials from <grpc/grpc_security.h>
/// </summary>
internal class ServerCredentialsSafeHandle : SafeHandleZeroIsInvalid
{
[DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)]
static extern ServerCredentialsSafeHandle grpcsharp_ssl_server_credentials_create(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs);
[DllImport("grpc_csharp_ext.dll")]
static extern void grpcsharp_server_credentials_release(IntPtr credentials);
private ServerCredentialsSafeHandle()
{
}
public static ServerCredentialsSafeHandle CreateSslCredentials(string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray)
{
Preconditions.CheckArgument(keyCertPairCertChainArray.Length == keyCertPairPrivateKeyArray.Length);
return grpcsharp_ssl_server_credentials_create(null,
keyCertPairCertChainArray, keyCertPairPrivateKeyArray,
new UIntPtr((ulong)keyCertPairCertChainArray.Length));
}
protected override bool ReleaseHandle()
{
grpcsharp_server_credentials_release(handle);
return true;
}
}
}

@ -53,7 +53,10 @@ namespace Grpc.Core.Internal
static extern ServerSafeHandle grpcsharp_server_create(CompletionQueueSafeHandle cq, IntPtr args);
[DllImport("grpc_csharp_ext.dll")]
static extern Int32 grpcsharp_server_add_http2_port(ServerSafeHandle server, string addr);
static extern int grpcsharp_server_add_http2_port(ServerSafeHandle server, string addr);
[DllImport("grpc_csharp_ext.dll")]
static extern int grpcsharp_server_add_secure_http2_port(ServerSafeHandle server, string addr, ServerCredentialsSafeHandle creds);
[DllImport("grpc_csharp_ext.dll")]
static extern void grpcsharp_server_start(ServerSafeHandle server);
@ -74,7 +77,6 @@ namespace Grpc.Core.Internal
public static ServerSafeHandle NewServer(CompletionQueueSafeHandle cq, IntPtr args)
{
// TODO: also grpc_secure_server_create...
return grpcsharp_server_create(cq, args);
}
@ -83,6 +85,11 @@ namespace Grpc.Core.Internal
return grpcsharp_server_add_http2_port(this, addr);
}
public int AddPort(string addr, ServerCredentialsSafeHandle credentials)
{
return grpcsharp_server_add_secure_http2_port(this, addr, credentials);
}
public void Start()
{
grpcsharp_server_start(this);

@ -40,8 +40,8 @@ namespace Grpc.Core.Internal
[StructLayout(LayoutKind.Sequential)]
internal struct Timespec
{
const int nanosPerSecond = 1000 * 1000 * 1000;
const int nanosPerTick = 100;
const int NanosPerSecond = 1000 * 1000 * 1000;
const int NanosPerTick = 100;
[DllImport("grpc_csharp_ext.dll")]
static extern Timespec gprsharp_now();
@ -99,14 +99,13 @@ namespace Grpc.Core.Internal
public Timespec Add(TimeSpan timeSpan)
{
long nanos = tv_nsec.ToInt64() + (timeSpan.Ticks % TimeSpan.TicksPerSecond) * nanosPerTick;
long overflow_sec = (nanos > nanosPerSecond) ? 1 : 0;
long nanos = tv_nsec.ToInt64() + (timeSpan.Ticks % TimeSpan.TicksPerSecond) * NanosPerTick;
long overflow_sec = (nanos > NanosPerSecond) ? 1 : 0;
Timespec result;
result.tv_nsec = new IntPtr(nanos % nanosPerSecond);
result.tv_nsec = new IntPtr(nanos % NanosPerSecond);
result.tv_sec = new IntPtr(tv_sec.ToInt64() + (timeSpan.Ticks / TimeSpan.TicksPerSecond) + overflow_sec);
return result;
}
}
}

@ -40,8 +40,8 @@ namespace Grpc.Core
/// </summary>
public struct Marshaller<T>
{
readonly Func<T,byte[]> serializer;
readonly Func<byte[],T> deserializer;
readonly Func<T, byte[]> serializer;
readonly Func<byte[], T> deserializer;
public Marshaller(Func<T, byte[]> serializer, Func<byte[], T> deserializer)
{
@ -66,9 +66,12 @@ namespace Grpc.Core
}
}
public static class Marshallers {
public static Marshaller<T> Create<T>(Func<T,byte[]> serializer, Func<byte[],T> deserializer)
/// <summary>
/// Utilities for creating marshallers.
/// </summary>
public static class Marshallers
{
public static Marshaller<T> Create<T>(Func<T, byte[]> serializer, Func<byte[], T> deserializer)
{
return new Marshaller<T>(serializer, deserializer);
}
@ -81,7 +84,5 @@ namespace Grpc.Core
System.Text.Encoding.UTF8.GetString);
}
}
}
}

@ -94,4 +94,3 @@ namespace Grpc.Core
}
}
}

@ -1,24 +1,14 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("Grpc.Core")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
[assembly: AssemblyTitle("Grpc.Core")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.1.*")]
[assembly: InternalsVisibleTo("Grpc.Core.Tests")]

@ -35,6 +35,9 @@ using System;
namespace Grpc.Core
{
/// <summary>
/// Thrown when remote procedure call fails.
/// </summary>
public class RpcException : Exception
{
private readonly Status status;
@ -58,4 +61,3 @@ namespace Grpc.Core
}
}
}

@ -67,18 +67,29 @@ namespace Grpc.Core
}
// only call this before Start()
public void AddServiceDefinition(ServerServiceDefinition serviceDefinition) {
foreach(var entry in serviceDefinition.CallHandlers)
public void AddServiceDefinition(ServerServiceDefinition serviceDefinition)
{
foreach (var entry in serviceDefinition.CallHandlers)
{
callHandlers.Add(entry.Key, entry.Value);
}
}
// only call before Start()
public int AddPort(string addr) {
public int AddPort(string addr)
{
return handle.AddPort(addr);
}
// only call before Start()
public int AddPort(string addr, ServerCredentials credentials)
{
using (var nativeCredentials = credentials.ToNativeCredentials())
{
return handle.AddPort(addr, nativeCredentials);
}
}
public void Start()
{
handle.Start();
@ -98,7 +109,7 @@ namespace Grpc.Core
{
var rpcInfo = newRpcQueue.Take();
//Console.WriteLine("Server received RPC " + rpcInfo.Method);
// Console.WriteLine("Server received RPC " + rpcInfo.Method);
IServerCallHandler callHandler;
if (!callHandlers.TryGetValue(rpcInfo.Method, out callHandler))
@ -107,7 +118,7 @@ namespace Grpc.Core
}
callHandler.StartCall(rpcInfo.Method, rpcInfo.Call, GetCompletionQueue());
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception while handling RPC: " + e);
}
@ -118,7 +129,8 @@ namespace Grpc.Core
/// cleans up used resources.
/// </summary>
/// <returns>The async.</returns>
public async Task ShutdownAsync() {
public async Task ShutdownAsync()
{
handle.ShutdownAndNotify(serverShutdownHandler);
await shutdownTcs.Task;
handle.Dispose();
@ -135,11 +147,13 @@ namespace Grpc.Core
}
}
public void Kill() {
public void Kill()
{
handle.Dispose();
}
private async Task StartHandlingRpcs() {
private async Task StartHandlingRpcs()
{
while (true)
{
await Task.Factory.StartNew(RunRpc);
@ -151,22 +165,27 @@ namespace Grpc.Core
AssertCallOk(handle.RequestCall(GetCompletionQueue(), newServerRpcHandler));
}
private void HandleNewServerRpc(GRPCOpError error, IntPtr batchContextPtr) {
try {
private void HandleNewServerRpc(GRPCOpError error, IntPtr batchContextPtr)
{
try
{
var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);
if (error != GRPCOpError.GRPC_OP_OK) {
if (error != GRPCOpError.GRPC_OP_OK)
{
// TODO: handle error
}
var rpcInfo = new NewRpcInfo(ctx.GetServerRpcNewCall(), ctx.GetServerRpcNewMethod());
// after server shutdown, the callback returns with null call
if (!rpcInfo.Call.IsInvalid) {
if (!rpcInfo.Call.IsInvalid)
{
newRpcQueue.Add(rpcInfo);
}
} catch(Exception e) {
}
catch (Exception e)
{
Console.WriteLine("Caught exception in a native handler: " + e);
}
}

@ -32,17 +32,18 @@
#endregion
using System;
using Grpc.Core.Internal;
namespace Grpc.Core
{
// TODO: perhaps add also serverSideStreaming and clientSideStreaming
public delegate void UnaryRequestServerMethod<TRequest, TResponse> (TRequest request, IObserver<TResponse> responseObserver);
public delegate void UnaryRequestServerMethod<TRequest, TResponse>(TRequest request, IObserver<TResponse> responseObserver);
public delegate IObserver<TRequest> StreamingRequestServerMethod<TRequest, TResponse> (IObserver<TResponse> responseObserver);
internal static class ServerCalls {
public delegate IObserver<TRequest> StreamingRequestServerMethod<TRequest, TResponse>(IObserver<TResponse> responseObserver);
internal static class ServerCalls
{
public static IServerCallHandler UnaryRequestCall<TRequest, TResponse>(Method<TRequest, TResponse> method, UnaryRequestServerMethod<TRequest, TResponse> handler)
{
return new UnaryRequestServerCallHandler<TRequest, TResponse>(method, handler);
@ -52,7 +53,5 @@ namespace Grpc.Core
{
return new StreamingRequestServerCallHandler<TRequest, TResponse>(method, handler);
}
}
}

@ -0,0 +1,109 @@
#region Copyright notice and license
// 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.
#endregion
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Grpc.Core.Internal;
namespace Grpc.Core
{
/// <summary>
/// Server side credentials.
/// </summary>
public abstract class ServerCredentials
{
/// <summary>
/// Creates native object for the credentials.
/// </summary>
/// <returns>The native credentials.</returns>
internal abstract ServerCredentialsSafeHandle ToNativeCredentials();
}
/// <summary>
/// Key certificate pair (in PEM encoding).
/// </summary>
public class KeyCertificatePair
{
readonly string certChain;
readonly string privateKey;
public KeyCertificatePair(string certChain, string privateKey)
{
this.certChain = certChain;
this.privateKey = privateKey;
}
public string CertChain
{
get
{
return certChain;
}
}
public string PrivateKey
{
get
{
return privateKey;
}
}
}
/// <summary>
/// Server-side SSL credentials.
/// </summary>
public class SslServerCredentials : ServerCredentials
{
ImmutableList<KeyCertificatePair> keyCertPairs;
public SslServerCredentials(ImmutableList<KeyCertificatePair> keyCertPairs)
{
this.keyCertPairs = keyCertPairs;
}
internal override ServerCredentialsSafeHandle ToNativeCredentials()
{
int count = keyCertPairs.Count;
string[] certChains = new string[count];
string[] keys = new string[count];
for (int i = 0; i < count; i++)
{
certChains[i] = keyCertPairs[i].CertChain;
keys[i] = keyCertPairs[i].PrivateKey;
}
return ServerCredentialsSafeHandle.CreateSslCredentials(certChains, keys);
}
}
}

@ -33,22 +33,26 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Grpc.Core.Internal;
namespace Grpc.Core
{
/// <summary>
/// Mapping of method names to server call handlers.
/// </summary>
public class ServerServiceDefinition
{
readonly string serviceName;
// TODO: we would need an immutable dictionary here...
readonly Dictionary<string, IServerCallHandler> callHandlers;
readonly ImmutableDictionary<string, IServerCallHandler> callHandlers;
private ServerServiceDefinition(string serviceName, Dictionary<string, IServerCallHandler> callHandlers)
private ServerServiceDefinition(string serviceName, ImmutableDictionary<string, IServerCallHandler> callHandlers)
{
this.serviceName = serviceName;
this.callHandlers = new Dictionary<string, IServerCallHandler>(callHandlers);
this.callHandlers = callHandlers;
}
internal Dictionary<string, IServerCallHandler> CallHandlers
internal ImmutableDictionary<string, IServerCallHandler> CallHandlers
{
get
{
@ -56,8 +60,7 @@ namespace Grpc.Core
}
}
public static Builder CreateBuilder(String serviceName)
public static Builder CreateBuilder(string serviceName)
{
return new Builder(serviceName);
}
@ -65,7 +68,7 @@ namespace Grpc.Core
public class Builder
{
readonly string serviceName;
readonly Dictionary<string, IServerCallHandler> callHandlers = new Dictionary<String, IServerCallHandler>();
readonly Dictionary<string, IServerCallHandler> callHandlers = new Dictionary<string, IServerCallHandler>();
public Builder(string serviceName)
{
@ -90,9 +93,8 @@ namespace Grpc.Core
public ServerServiceDefinition Build()
{
return new ServerServiceDefinition(serviceName, callHandlers);
return new ServerServiceDefinition(serviceName, callHandlers.ToImmutableDictionary());
}
}
}
}

@ -35,9 +35,9 @@ using System;
namespace Grpc.Core
{
// TODO: element names should changed to comply with C# naming conventions.
/// <summary>
/// based on grpc_status_code from grpc/status.h
/// Result of a remote procedure call.
/// Based on grpc_status_code from grpc/status.h
/// </summary>
public enum StatusCode
{
@ -139,4 +139,3 @@ namespace Grpc.Core
DataLoss = 15
}
}

@ -32,10 +32,10 @@
#endregion
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
namespace Grpc.Core.Utils
{
@ -61,8 +61,7 @@ namespace Grpc.Core.Utils
}
stopwatch.Stop();
Console.WriteLine("Elapsed time: " + stopwatch.ElapsedMilliseconds + "ms");
Console.WriteLine("Ops per second: " + (int) ((double) benchmarkIterations * 1000 / stopwatch.ElapsedMilliseconds));
Console.WriteLine("Ops per second: " + (int)((double)benchmarkIterations * 1000 / stopwatch.ElapsedMilliseconds));
}
}
}

@ -42,7 +42,8 @@ namespace Grpc.Core.Utils
/// Otherwise, rethrows the original aggregate exception.
/// Always throws, the exception return type is here only to make the.
/// </summary>
public static Exception UnwrapRpcException(AggregateException ae) {
public static Exception UnwrapRpcException(AggregateException ae)
{
foreach (var e in ae.InnerExceptions)
{
if (e is RpcException)
@ -54,4 +55,3 @@ namespace Grpc.Core.Utils
}
}
}

@ -32,10 +32,10 @@
#endregion
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
namespace Grpc.Core.Utils
{
@ -66,7 +66,7 @@ namespace Grpc.Core.Utils
/// <summary>
/// Throws NullReferenceException if reference is null.
/// </summary>
public static T CheckNotNull<T> (T reference)
public static T CheckNotNull<T>(T reference)
{
if (reference == null)
{
@ -78,7 +78,7 @@ namespace Grpc.Core.Utils
/// <summary>
/// Throws NullReferenceException with given message if reference is null.
/// </summary>
public static T CheckNotNull<T> (T reference, string errorMessage)
public static T CheckNotNull<T>(T reference, string errorMessage)
{
if (reference == null)
{
@ -110,4 +110,3 @@ namespace Grpc.Core.Utils
}
}
}

@ -57,9 +57,9 @@ namespace Grpc.Core.Utils
data.Add(value);
}
public Task<List<T>> ToList() {
public Task<List<T>> ToList()
{
return tcs.Task;
}
}
}

@ -32,9 +32,9 @@
#endregion
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Grpc.Core.Utils
{
@ -81,4 +81,3 @@ namespace Grpc.Core.Utils
}
}
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Collections.Immutable" version="1.1.34-rc" targetFramework="net45" />
</packages>

@ -1,22 +1,12 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("Grpc.Examples.MathClient")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
[assembly: AssemblyTitle("Grpc.Examples.MathClient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.1.*")]

@ -105,7 +105,7 @@ namespace math.Tests
var recorder = new RecordingObserver<Num>();
client.Fib(new FibArgs.Builder { Limit = 6 }.Build(), recorder);
CollectionAssert.AreEqual(new List<long>{1, 1, 2, 3, 5, 8},
CollectionAssert.AreEqual(new List<long> { 1, 1, 2, 3, 5, 8 },
recorder.ToList().Result.ConvertAll((n) => n.Num_));
}
@ -114,7 +114,8 @@ namespace math.Tests
public void Sum()
{
var res = client.Sum();
foreach (var num in new long[] { 10, 20, 30 }) {
foreach (var num in new long[] { 10, 20, 30 })
{
res.Inputs.OnNext(Num.CreateBuilder().SetNum_(num).Build());
}
res.Inputs.OnCompleted();
@ -125,7 +126,8 @@ namespace math.Tests
[Test]
public void DivMany()
{
List<DivArgs> divArgsList = new List<DivArgs>{
List<DivArgs> divArgsList = new List<DivArgs>
{
new DivArgs.Builder { Dividend = 10, Divisor = 3 }.Build(),
new DivArgs.Builder { Dividend = 100, Divisor = 21 }.Build(),
new DivArgs.Builder { Dividend = 7, Divisor = 2 }.Build()
@ -142,9 +144,8 @@ namespace math.Tests
var result = recorder.ToList().Result;
CollectionAssert.AreEqual(new long[] {3, 4, 3}, result.ConvertAll((divReply) => divReply.Quotient));
CollectionAssert.AreEqual(new long[] {1, 16, 1}, result.ConvertAll((divReply) => divReply.Remainder));
CollectionAssert.AreEqual(new long[] { 3, 4, 3 }, result.ConvertAll((divReply) => divReply.Quotient));
CollectionAssert.AreEqual(new long[] { 1, 16, 1 }, result.ConvertAll((divReply) => divReply.Remainder));
}
}
}

@ -1,8 +1,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Grpc.Examples.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@ -11,12 +9,4 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

@ -71,7 +71,8 @@ namespace math
public static void SumExample(MathGrpc.IMathServiceClient stub)
{
List<Num> numbers = new List<Num>
{new Num.Builder { Num_ = 1 }.Build(),
{
new Num.Builder { Num_ = 1 }.Build(),
new Num.Builder { Num_ = 2 }.Build(),
new Num.Builder { Num_ = 3 }.Build()
};
@ -110,24 +111,12 @@ namespace math
public static void DependendRequestsExample(MathGrpc.IMathServiceClient stub)
{
var numberList = new List<Num>
{ new Num.Builder{ Num_ = 1 }.Build(),
new Num.Builder{ Num_ = 2 }.Build(), new Num.Builder{ Num_ = 3 }.Build()
{
new Num.Builder { Num_ = 1 }.Build(),
new Num.Builder { Num_ = 2 }.Build(), new Num.Builder { Num_ = 3 }.Build()
};
numberList.ToObservable();
//IObserver<Num> numbers;
//Task<Num> call = stub.Sum(out numbers);
//foreach (var num in numberList)
//{
// numbers.OnNext(num);
//}
//numbers.OnCompleted();
//Num sum = call.Result;
//DivReply result = stub.Div(new DivArgs.Builder { Dividend = sum.Num_, Divisor = numberList.Count }.Build());
}
}
}

@ -45,35 +45,34 @@ namespace math
/// </summary>
public class MathGrpc
{
readonly static Marshaller<DivArgs> divArgsMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), DivArgs.ParseFrom);
readonly static Marshaller<DivReply> divReplyMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), DivReply.ParseFrom);
readonly static Marshaller<Num> numMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Num.ParseFrom);
readonly static Marshaller<FibArgs> fibArgsMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), FibArgs.ParseFrom);
static readonly Marshaller<DivArgs> DivArgsMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), DivArgs.ParseFrom);
static readonly Marshaller<DivReply> DivReplyMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), DivReply.ParseFrom);
static readonly Marshaller<Num> NumMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Num.ParseFrom);
static readonly Marshaller<FibArgs> FibArgsMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), FibArgs.ParseFrom);
readonly static Method<DivArgs, DivReply> divMethod = new Method<DivArgs, DivReply>(
static readonly Method<DivArgs, DivReply> DivMethod = new Method<DivArgs, DivReply>(
MethodType.Unary,
"/math.Math/Div",
divArgsMarshaller,
divReplyMarshaller
);
readonly static Method<FibArgs, Num> fibMethod = new Method<FibArgs, Num>(
DivArgsMarshaller,
DivReplyMarshaller);
static readonly Method<FibArgs, Num> FibMethod = new Method<FibArgs, Num>(
MethodType.ServerStreaming,
"/math.Math/Fib",
fibArgsMarshaller,
numMarshaller
);
readonly static Method<Num, Num> sumMethod = new Method<Num, Num>(
FibArgsMarshaller,
NumMarshaller);
static readonly Method<Num, Num> SumMethod = new Method<Num, Num>(
MethodType.ClientStreaming,
"/math.Math/Sum",
numMarshaller,
numMarshaller
);
readonly static Method<DivArgs, DivReply> divManyMethod = new Method<DivArgs, DivReply>(
NumMarshaller,
NumMarshaller);
static readonly Method<DivArgs, DivReply> DivManyMethod = new Method<DivArgs, DivReply>(
MethodType.DuplexStreaming,
"/math.Math/DivMany",
divArgsMarshaller,
divReplyMarshaller
);
DivArgsMarshaller,
DivReplyMarshaller);
public interface IMathServiceClient
{
@ -99,31 +98,31 @@ namespace math
public DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<DivArgs, DivReply>(divMethod, channel);
var call = new Grpc.Core.Call<DivArgs, DivReply>(DivMethod, channel);
return Calls.BlockingUnaryCall(call, request, token);
}
public Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<DivArgs, DivReply>(divMethod, channel);
var call = new Grpc.Core.Call<DivArgs, DivReply>(DivMethod, channel);
return Calls.AsyncUnaryCall(call, request, token);
}
public void Fib(FibArgs request, IObserver<Num> responseObserver, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<FibArgs, Num>(fibMethod, channel);
var call = new Grpc.Core.Call<FibArgs, Num>(FibMethod, channel);
Calls.AsyncServerStreamingCall(call, request, responseObserver, token);
}
public ClientStreamingAsyncResult<Num, Num> Sum(CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<Num, Num>(sumMethod, channel);
var call = new Grpc.Core.Call<Num, Num>(SumMethod, channel);
return Calls.AsyncClientStreamingCall(call, token);
}
public IObserver<DivArgs> DivMany(IObserver<DivReply> responseObserver, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<DivArgs, DivReply>(divManyMethod, channel);
var call = new Grpc.Core.Call<DivArgs, DivReply>(DivManyMethod, channel);
return Calls.DuplexStreamingCall(call, responseObserver, token);
}
}
@ -143,10 +142,10 @@ namespace math
public static ServerServiceDefinition BindService(IMathService serviceImpl)
{
return ServerServiceDefinition.CreateBuilder("/math.Math/")
.AddMethod(divMethod, serviceImpl.Div)
.AddMethod(fibMethod, serviceImpl.Fib)
.AddMethod(sumMethod, serviceImpl.Sum)
.AddMethod(divManyMethod, serviceImpl.DivMany).Build();
.AddMethod(DivMethod, serviceImpl.Div)
.AddMethod(FibMethod, serviceImpl.Fib)
.AddMethod(SumMethod, serviceImpl.Sum)
.AddMethod(DivManyMethod, serviceImpl.DivMany).Build();
}
public static IMathServiceClient NewStub(Channel channel)

@ -73,8 +73,8 @@ namespace math
public IObserver<Num> Sum(IObserver<Num> responseObserver)
{
var recorder = new RecordingObserver<Num>();
Task.Factory.StartNew(() => {
Task.Factory.StartNew(() =>
{
List<Num> inputs = recorder.ToList().Result;
long sum = 0;
@ -104,7 +104,7 @@ namespace math
static IEnumerable<Num> FibInternal(long n)
{
long a = 1;
yield return new Num.Builder { Num_=a }.Build();
yield return new Num.Builder { Num_ = a }.Build();
long b = 1;
for (long i = 0; i < n - 1; i++)
@ -112,12 +112,12 @@ namespace math
long temp = a;
a = b;
b = temp + b;
yield return new Num.Builder { Num_=a }.Build();
yield return new Num.Builder { Num_ = a }.Build();
}
}
private class DivObserver : IObserver<DivArgs> {
private class DivObserver : IObserver<DivArgs>
{
readonly IObserver<DivReply> responseObserver;
public DivObserver(IObserver<DivReply> responseObserver)
@ -142,4 +142,3 @@ namespace math
}
}
}

@ -1,22 +1,12 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("Grpc.Examples")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
[assembly: AssemblyTitle("Grpc.Examples")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.1.*")]

@ -0,0 +1,10 @@
<StyleCopSettings Version="105">
<SourceFileList>
<SourceFile>Math.cs</SourceFile>
<Settings>
<GlobalSettings>
<BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
</GlobalSettings>
</Settings>
</SourceFileList>
</StyleCopSettings>

@ -1,8 +1,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Grpc.IntegrationTesting.Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@ -11,12 +9,4 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

@ -1,8 +1,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Grpc.IntegrationTesting.Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@ -11,12 +9,4 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

@ -39,6 +39,10 @@
<Reference Include="Google.ProtocolBuffers">
<HintPath>..\packages\Google.ProtocolBuffers.2.4.1.521\lib\net40\Google.ProtocolBuffers.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Immutable, Version=1.1.34.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.Collections.Immutable.1.1.34-rc\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
@ -49,6 +53,7 @@
<Compile Include="TestServiceImpl.cs" />
<Compile Include="InteropServer.cs" />
<Compile Include="InteropClient.cs" />
<Compile Include="TestCredentials.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@ -75,8 +80,5 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="proto\" />
<Folder Include="data\" />
</ItemGroup>
</Project>
<ItemGroup />
</Project>

@ -38,10 +38,10 @@ using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Google.ProtocolBuffers;
using grpc.testing;
using Grpc.Core;
using Grpc.Core.Utils;
using NUnit.Framework;
using grpc.testing;
namespace Grpc.IntegrationTesting
{
@ -50,8 +50,8 @@ namespace Grpc.IntegrationTesting
private class ClientOptions
{
public bool help;
public string serverHost= "127.0.0.1";
public string serverHostOverride = "foo.test.google.fr";
public string serverHost = "127.0.0.1";
public string serverHostOverride = TestCredentials.DefaultHostOverride;
public int? serverPort;
public string testCase = "large_unary";
public bool useTls;
@ -103,22 +103,13 @@ namespace Grpc.IntegrationTesting
Credentials credentials = null;
if (options.useTls)
{
string caPath = "data/ca.pem"; // Default testing CA
if (!options.useTestCa)
{
caPath = Environment.GetEnvironmentVariable("SSL_CERT_FILE");
if (string.IsNullOrEmpty(caPath))
{
throw new ArgumentException("CA path environment variable is not set.");
}
}
credentials = new SslCredentials(File.ReadAllText(caPath));
credentials = TestCredentials.CreateTestClientCredentials(options.useTestCa);
}
ChannelArgs channelArgs = null;
if (!string.IsNullOrEmpty(options.serverHostOverride))
{
channelArgs = ChannelArgs.NewBuilder()
channelArgs = ChannelArgs.CreateBuilder()
.AddString(ChannelArgs.SslTargetNameOverrideKey, options.serverHostOverride).Build();
}
@ -189,7 +180,7 @@ namespace Grpc.IntegrationTesting
{
Console.WriteLine("running client_streaming");
var bodySizes = new List<int>{27182, 8, 1828, 45904};
var bodySizes = new List<int> { 27182, 8, 1828, 45904 };
var context = client.StreamingInputCall();
foreach (var size in bodySizes)
@ -208,7 +199,7 @@ namespace Grpc.IntegrationTesting
{
Console.WriteLine("running server_streaming");
var bodySizes = new List<int>{31415, 9, 2653, 58979};
var bodySizes = new List<int> { 31415, 9, 2653, 58979 };
var request = StreamingOutputCallRequest.CreateBuilder()
.SetResponseType(PayloadType.COMPRESSABLE)
@ -265,7 +256,6 @@ namespace Grpc.IntegrationTesting
Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
Assert.AreEqual(2653, response.Payload.Body.Length);
inputs.OnNext(StreamingOutputCallRequest.CreateBuilder()
.SetResponseType(PayloadType.COMPRESSABLE)
.AddResponseParameters(ResponseParameters.CreateBuilder().SetSize(58979))
@ -301,17 +291,18 @@ namespace Grpc.IntegrationTesting
public static void RunBenchmarkEmptyUnary(TestServiceGrpc.ITestServiceClient client)
{
BenchmarkUtil.RunBenchmark(10000, 10000,
() => { client.EmptyCall(Empty.DefaultInstance);});
() => { client.EmptyCall(Empty.DefaultInstance); });
}
private static Payload CreateZerosPayload(int size) {
private static Payload CreateZerosPayload(int size)
{
return Payload.CreateBuilder().SetBody(ByteString.CopyFrom(new byte[size])).Build();
}
private static ClientOptions ParseArguments(string[] args)
{
var options = new ClientOptions();
foreach(string arg in args)
foreach (string arg in args)
{
ParseArgument(arg, options);
if (options.help)

@ -35,10 +35,10 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using grpc.testing;
using Grpc.Core;
using Grpc.Core.Utils;
using NUnit.Framework;
using grpc.testing;
namespace Grpc.IntegrationTesting
{
@ -59,9 +59,13 @@ namespace Grpc.IntegrationTesting
server = new Server();
server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl()));
int port = server.AddPort(host + ":0");
int port = server.AddPort(host + ":0", TestCredentials.CreateTestServerCredentials());
server.Start();
channel = new Channel(host + ":" + port);
var channelArgs = ChannelArgs.CreateBuilder()
.AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build();
channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs);
client = TestServiceGrpc.NewStub(channel);
}
@ -113,7 +117,5 @@ namespace Grpc.IntegrationTesting
// TODO: add cancel_after_begin
// TODO: add cancel_after_first_response
}
}

@ -34,13 +34,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Google.ProtocolBuffers;
using grpc.testing;
using Grpc.Core;
using Grpc.Core.Utils;
using NUnit.Framework;
using grpc.testing;
namespace Grpc.IntegrationTesting
{
@ -49,7 +50,7 @@ namespace Grpc.IntegrationTesting
private class ServerOptions
{
public bool help;
public int? port;
public int? port = 8070;
public bool useTls;
}
@ -93,7 +94,14 @@ namespace Grpc.IntegrationTesting
server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl()));
string addr = "0.0.0.0:" + options.port;
server.AddPort(addr);
if (options.useTls)
{
server.AddPort(addr, TestCredentials.CreateTestServerCredentials());
}
else
{
server.AddPort(addr);
}
Console.WriteLine("Running server on " + addr);
server.Start();
@ -105,7 +113,7 @@ namespace Grpc.IntegrationTesting
private static ServerOptions ParseArguments(string[] args)
{
var options = new ServerOptions();
foreach(string arg in args)
foreach (string arg in args)
{
ParseArgument(arg, options);
if (options.help)

@ -1,8 +1,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Grpc.IntegrationTesting")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@ -11,12 +9,4 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

@ -0,0 +1,11 @@
<StyleCopSettings Version="105">
<SourceFileList>
<SourceFile>Messages.cs</SourceFile>
<SourceFile>Empty.cs</SourceFile>
<Settings>
<GlobalSettings>
<BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
</GlobalSettings>
</Settings>
</SourceFileList>
</StyleCopSettings>

@ -0,0 +1,84 @@
#region Copyright notice and license
// 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.
#endregion
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Google.ProtocolBuffers;
using grpc.testing;
using Grpc.Core;
using Grpc.Core.Utils;
using NUnit.Framework;
namespace Grpc.IntegrationTesting
{
/// <summary>
/// SSL Credentials for testing.
/// </summary>
public static class TestCredentials
{
public const string DefaultHostOverride = "foo.test.google.fr";
public const string ClientCertAuthorityPath = "data/ca.pem";
public const string ClientCertAuthorityEnvName = "SSL_CERT_FILE";
public const string ServerCertChainPath = "data/server1.pem";
public const string ServerPrivateKeyPath = "data/server1.key";
public static SslCredentials CreateTestClientCredentials(bool useTestCa)
{
string caPath = ClientCertAuthorityPath;
if (!useTestCa)
{
caPath = Environment.GetEnvironmentVariable(ClientCertAuthorityEnvName);
if (string.IsNullOrEmpty(caPath))
{
throw new ArgumentException("CA path environment variable is not set.");
}
}
return new SslCredentials(File.ReadAllText(caPath));
}
public static SslServerCredentials CreateTestServerCredentials()
{
var keyCertPair = new KeyCertificatePair(
File.ReadAllText(ServerCertChainPath),
File.ReadAllText(ServerPrivateKeyPath));
return new SslServerCredentials(ImmutableList.Create(keyCertPair));
}
}
}

@ -44,50 +44,49 @@ namespace grpc.testing
/// </summary>
public class TestServiceGrpc
{
readonly static Marshaller<Empty> emptyMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Empty.ParseFrom);
readonly static Marshaller<SimpleRequest> simpleRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), SimpleRequest.ParseFrom);
readonly static Marshaller<SimpleResponse> simpleResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), SimpleResponse.ParseFrom);
readonly static Marshaller<StreamingOutputCallRequest> streamingOutputCallRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallRequest.ParseFrom);
readonly static Marshaller<StreamingOutputCallResponse> streamingOutputCallResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallResponse.ParseFrom);
readonly static Marshaller<StreamingInputCallRequest> streamingInputCallRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallRequest.ParseFrom);
readonly static Marshaller<StreamingInputCallResponse> streamingInputCallResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallResponse.ParseFrom);
readonly static Method<Empty, Empty> emptyCallMethod = new Method<Empty, Empty>(
static readonly Marshaller<Empty> EmptyMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Empty.ParseFrom);
static readonly Marshaller<SimpleRequest> SimpleRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), SimpleRequest.ParseFrom);
static readonly Marshaller<SimpleResponse> SimpleResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), SimpleResponse.ParseFrom);
static readonly Marshaller<StreamingOutputCallRequest> StreamingOutputCallRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallRequest.ParseFrom);
static readonly Marshaller<StreamingOutputCallResponse> StreamingOutputCallResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallResponse.ParseFrom);
static readonly Marshaller<StreamingInputCallRequest> StreamingInputCallRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallRequest.ParseFrom);
static readonly Marshaller<StreamingInputCallResponse> StreamingInputCallResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallResponse.ParseFrom);
static readonly Method<Empty, Empty> EmptyCallMethod = new Method<Empty, Empty>(
MethodType.Unary,
"/grpc.testing.TestService/EmptyCall",
emptyMarshaller,
emptyMarshaller
);
readonly static Method<SimpleRequest, SimpleResponse> unaryCallMethod = new Method<SimpleRequest, SimpleResponse>(
EmptyMarshaller,
EmptyMarshaller);
static readonly Method<SimpleRequest, SimpleResponse> UnaryCallMethod = new Method<SimpleRequest, SimpleResponse>(
MethodType.Unary,
"/grpc.testing.TestService/UnaryCall",
simpleRequestMarshaller,
simpleResponseMarshaller
);
readonly static Method<StreamingOutputCallRequest, StreamingOutputCallResponse> streamingOutputCallMethod = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>(
SimpleRequestMarshaller,
SimpleResponseMarshaller);
static readonly Method<StreamingOutputCallRequest, StreamingOutputCallResponse> StreamingOutputCallMethod = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>(
MethodType.ServerStreaming,
"/grpc.testing.TestService/StreamingOutputCall",
streamingOutputCallRequestMarshaller,
streamingOutputCallResponseMarshaller
);
readonly static Method<StreamingInputCallRequest, StreamingInputCallResponse> streamingInputCallMethod = new Method<StreamingInputCallRequest, StreamingInputCallResponse>(
StreamingOutputCallRequestMarshaller,
StreamingOutputCallResponseMarshaller);
static readonly Method<StreamingInputCallRequest, StreamingInputCallResponse> StreamingInputCallMethod = new Method<StreamingInputCallRequest, StreamingInputCallResponse>(
MethodType.ClientStreaming,
"/grpc.testing.TestService/StreamingInputCall",
streamingInputCallRequestMarshaller,
streamingInputCallResponseMarshaller
);
readonly static Method<StreamingOutputCallRequest, StreamingOutputCallResponse> fullDuplexCallMethod = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>(
StreamingInputCallRequestMarshaller,
StreamingInputCallResponseMarshaller);
static readonly Method<StreamingOutputCallRequest, StreamingOutputCallResponse> FullDuplexCallMethod = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>(
MethodType.DuplexStreaming,
"/grpc.testing.TestService/FullDuplexCall",
streamingOutputCallRequestMarshaller,
streamingOutputCallResponseMarshaller
);
readonly static Method<StreamingOutputCallRequest, StreamingOutputCallResponse> halfDuplexCallMethod = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>(
StreamingOutputCallRequestMarshaller,
StreamingOutputCallResponseMarshaller);
static readonly Method<StreamingOutputCallRequest, StreamingOutputCallResponse> HalfDuplexCallMethod = new Method<StreamingOutputCallRequest, StreamingOutputCallResponse>(
MethodType.DuplexStreaming,
"/grpc.testing.TestService/HalfDuplexCall",
streamingOutputCallRequestMarshaller,
streamingOutputCallResponseMarshaller
);
StreamingOutputCallRequestMarshaller,
StreamingOutputCallResponseMarshaller);
public interface ITestServiceClient
{
@ -119,49 +118,49 @@ namespace grpc.testing
public Empty EmptyCall(Empty request, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<Empty, Empty>(emptyCallMethod, channel);
var call = new Grpc.Core.Call<Empty, Empty>(EmptyCallMethod, channel);
return Calls.BlockingUnaryCall(call, request, token);
}
public Task<Empty> EmptyCallAsync(Empty request, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<Empty, Empty>(emptyCallMethod, channel);
var call = new Grpc.Core.Call<Empty, Empty>(EmptyCallMethod, channel);
return Calls.AsyncUnaryCall(call, request, token);
}
public SimpleResponse UnaryCall(SimpleRequest request, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<SimpleRequest, SimpleResponse>(unaryCallMethod, channel);
var call = new Grpc.Core.Call<SimpleRequest, SimpleResponse>(UnaryCallMethod, channel);
return Calls.BlockingUnaryCall(call, request, token);
}
public Task<SimpleResponse> UnaryCallAsync(SimpleRequest request, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<SimpleRequest, SimpleResponse>(unaryCallMethod, channel);
var call = new Grpc.Core.Call<SimpleRequest, SimpleResponse>(UnaryCallMethod, channel);
return Calls.AsyncUnaryCall(call, request, token);
}
public void StreamingOutputCall(StreamingOutputCallRequest request, IObserver<StreamingOutputCallResponse> responseObserver, CancellationToken token = default(CancellationToken)) {
var call = new Grpc.Core.Call<StreamingOutputCallRequest, StreamingOutputCallResponse>(streamingOutputCallMethod, channel);
public void StreamingOutputCall(StreamingOutputCallRequest request, IObserver<StreamingOutputCallResponse> responseObserver, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<StreamingOutputCallRequest, StreamingOutputCallResponse>(StreamingOutputCallMethod, channel);
Calls.AsyncServerStreamingCall(call, request, responseObserver, token);
}
public ClientStreamingAsyncResult<StreamingInputCallRequest, StreamingInputCallResponse> StreamingInputCall(CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<StreamingInputCallRequest, StreamingInputCallResponse>(streamingInputCallMethod, channel);
var call = new Grpc.Core.Call<StreamingInputCallRequest, StreamingInputCallResponse>(StreamingInputCallMethod, channel);
return Calls.AsyncClientStreamingCall(call, token);
}
public IObserver<StreamingOutputCallRequest> FullDuplexCall(IObserver<StreamingOutputCallResponse> responseObserver, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<StreamingOutputCallRequest, StreamingOutputCallResponse>(fullDuplexCallMethod, channel);
var call = new Grpc.Core.Call<StreamingOutputCallRequest, StreamingOutputCallResponse>(FullDuplexCallMethod, channel);
return Calls.DuplexStreamingCall(call, responseObserver, token);
}
public IObserver<StreamingOutputCallRequest> HalfDuplexCall(IObserver<StreamingOutputCallResponse> responseObserver, CancellationToken token = default(CancellationToken))
{
var call = new Grpc.Core.Call<StreamingOutputCallRequest, StreamingOutputCallResponse>(halfDuplexCallMethod, channel);
var call = new Grpc.Core.Call<StreamingOutputCallRequest, StreamingOutputCallResponse>(HalfDuplexCallMethod, channel);
return Calls.DuplexStreamingCall(call, responseObserver, token);
}
}
@ -185,12 +184,12 @@ namespace grpc.testing
public static ServerServiceDefinition BindService(ITestService serviceImpl)
{
return ServerServiceDefinition.CreateBuilder("/grpc.testing.TestService/")
.AddMethod(emptyCallMethod, serviceImpl.EmptyCall)
.AddMethod(unaryCallMethod, serviceImpl.UnaryCall)
.AddMethod(streamingOutputCallMethod, serviceImpl.StreamingOutputCall)
.AddMethod(streamingInputCallMethod, serviceImpl.StreamingInputCall)
.AddMethod(fullDuplexCallMethod, serviceImpl.FullDuplexCall)
.AddMethod(halfDuplexCallMethod, serviceImpl.HalfDuplexCall)
.AddMethod(EmptyCallMethod, serviceImpl.EmptyCall)
.AddMethod(UnaryCallMethod, serviceImpl.UnaryCall)
.AddMethod(StreamingOutputCallMethod, serviceImpl.StreamingOutputCall)
.AddMethod(StreamingInputCallMethod, serviceImpl.StreamingInputCall)
.AddMethod(FullDuplexCallMethod, serviceImpl.FullDuplexCall)
.AddMethod(HalfDuplexCallMethod, serviceImpl.HalfDuplexCall)
.Build();
}

@ -55,14 +55,14 @@ namespace grpc.testing
{
var response = SimpleResponse.CreateBuilder()
.SetPayload(CreateZerosPayload(request.ResponseSize)).Build();
//TODO: check we support ReponseType
// TODO: check we support ReponseType
responseObserver.OnNext(response);
responseObserver.OnCompleted();
}
public void StreamingOutputCall(StreamingOutputCallRequest request, IObserver<StreamingOutputCallResponse> responseObserver)
{
foreach(var responseParam in request.ResponseParametersList)
foreach (var responseParam in request.ResponseParametersList)
{
var response = StreamingOutputCallResponse.CreateBuilder()
.SetPayload(CreateZerosPayload(responseParam.Size)).Build();
@ -74,9 +74,10 @@ namespace grpc.testing
public IObserver<StreamingInputCallRequest> StreamingInputCall(IObserver<StreamingInputCallResponse> responseObserver)
{
var recorder = new RecordingObserver<StreamingInputCallRequest>();
Task.Run(() => {
Task.Run(() =>
{
int sum = 0;
foreach(var req in recorder.ToList().Result)
foreach (var req in recorder.ToList().Result)
{
sum += req.Payload.Body.Length;
}
@ -98,8 +99,8 @@ namespace grpc.testing
throw new NotImplementedException();
}
private class FullDuplexObserver : IObserver<StreamingOutputCallRequest> {
private class FullDuplexObserver : IObserver<StreamingOutputCallRequest>
{
readonly IObserver<StreamingOutputCallResponse> responseObserver;
public FullDuplexObserver(IObserver<StreamingOutputCallResponse> responseObserver)
@ -119,22 +120,18 @@ namespace grpc.testing
public void OnNext(StreamingOutputCallRequest value)
{
// TODO: this is not in order!!!
//Task.Factory.StartNew(() => {
foreach(var responseParam in value.ResponseParametersList)
{
var response = StreamingOutputCallResponse.CreateBuilder()
.SetPayload(CreateZerosPayload(responseParam.Size)).Build();
responseObserver.OnNext(response);
}
//});
foreach (var responseParam in value.ResponseParametersList)
{
var response = StreamingOutputCallResponse.CreateBuilder()
.SetPayload(CreateZerosPayload(responseParam.Size)).Build();
responseObserver.OnNext(response);
}
}
}
private static Payload CreateZerosPayload(int size) {
private static Payload CreateZerosPayload(int size)
{
return Payload.CreateBuilder().SetBody(ByteString.CopyFrom(new byte[size])).Build();
}
}
}

@ -2,4 +2,5 @@
<packages>
<package id="Google.ProtocolBuffers" version="2.4.1.521" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="System.Collections.Immutable" version="1.1.34-rc" targetFramework="net45" />
</packages>

@ -0,0 +1,509 @@
<StyleCopSettings Version="105">
<Analyzers>
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
<Rules>
<Rule Name="ElementsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PartialElementsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="EnumerationItemsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationMustContainValidXml">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustHaveSummary">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PartialElementDocumentationMustHaveSummary">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustHaveSummaryText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PartialElementDocumentationMustHaveSummaryText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustNotHaveDefaultSummary">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParametersMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParameterDocumentationMustMatchElementParameters">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParameterDocumentationMustDeclareParameterName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParameterDocumentationMustHaveText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementReturnValueMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementReturnValueDocumentationMustHaveText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="VoidReturnValueMustNotBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParametersMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParametersMustBeDocumentedPartialClass">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParameterDocumentationMustMatchTypeParameters">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParameterDocumentationMustDeclareParameterName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParameterDocumentationMustHaveText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PropertySummaryDocumentationMustMatchAccessors">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PropertySummaryDocumentationMustOmitSetAccessorWithRestrictedAccess">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustNotBeCopiedAndPasted">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SingleLineCommentsMustNotUseDocumentationStyleSlashes">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationTextMustNotBeEmpty">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationTextMustContainWhitespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationMustMeetCharacterPercentage">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ConstructorSummaryDocumentationMustBeginWithStandardText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DestructorSummaryDocumentationMustBeginWithStandardText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationHeadersMustNotContainBlankLines">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="IncludedDocumentationXPathDoesNotExist">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="IncludeNodeDoesNotContainValidFileAndPath">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="InheritDocMustBeUsedWithInheritingClass">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustBeSpelledCorrectly">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileMustHaveHeader">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustShowCopyright">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustHaveCopyrightText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustContainFileName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderFileNameDocumentationMustMatchFileName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustHaveValidCompanyText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderFileNameDocumentationMustMatchTypeName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.MaintainabilityRules">
<Rules>
<Rule Name="AccessModifierMustBeDeclared">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldsMustBePrivate">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="CodeAnalysisSuppressionMustHaveJustification">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DebugAssertMustProvideMessageText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DebugFailMustProvideMessageText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileMayOnlyContainASingleClass">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="StatementMustNotUseUnnecessaryParenthesis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ArithmeticExpressionsMustDeclarePrecedence">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ConditionalExpressionsMustDeclarePrecedence">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="RemoveDelegateParenthesisWhenPossible">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="AttributeConstructorMustNotUseUnnecessaryParenthesis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="RemoveUnnecessaryCode">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
<Rules>
<Rule Name="NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustNotUseHungarianNotation">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustBeginWithLowerCaseLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="AccessibleFieldsMustBeginWithUpperCaseLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="VariableNamesMustNotBePrefixed">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustNotContainUnderscore">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementMustBeginWithUpperCaseLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
<Rules>
<Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustAppearInTheCorrectOrder">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustBeOrderedByAccess">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="StaticElementsMustAppearBeforeInstanceElements">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PropertyAccessorsMustFollowOrder">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="EventAccessorsMustFollowOrder">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="UsingAliasDirectivesMustBeOrderedAlphabeticallyByAliasName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
<Rules>
<Rule Name="DoNotPrefixCallsWithBaseUnlessLocalImplementationExists">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PrefixLocalCallsWithThis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PrefixCallsCorrectly">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="OpeningParenthesisMustBeOnDeclarationLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ClosingParenthesisMustBeOnLineOfLastParameter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ClosingParenthesisMustBeOnLineOfOpeningParenthesis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="CommaMustBeOnSameLineAsPreviousParameter">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParameterListMustFollowDeclaration">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParameterMustFollowComma">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SplitParametersMustStartOnLineAfterDeclaration">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParametersMustBeOnSameLineOrSeparateLines">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParameterMustNotSpanMultipleLines">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="QueryClauseMustFollowPreviousClause">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="QueryClausesMustBeOnSeparateLinesOrAllOnOneLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="QueryClauseMustBeginOnNewLineWhenPreviousClauseSpansMultipleLines">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="QueryClausesSpanningMultipleLinesMustBeginOnOwnLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="CodeMustNotContainEmptyStatements">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="CodeMustNotContainMultipleStatementsOnOneLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="BlockStatementsMustNotContainEmbeddedComments">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="BlockStatementsMustNotContainEmbeddedRegions">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="UseStringEmptyForEmptyStrings">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.LayoutRules">
<Rules>
<Rule Name="SingleLineCommentsMustNotBeFollowedByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ClosingCurlyBracketMustBeFollowedByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationHeaderMustBePrecededByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SingleLineCommentMustBePrecededByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
</Analyzers>
</StyleCopSettings>

@ -653,6 +653,41 @@ grpcsharp_secure_channel_create(grpc_credentials *creds, const char *target,
return grpc_secure_channel_create(creds, target, args);
}
GPR_EXPORT grpc_server_credentials *GPR_CALLTYPE
grpcsharp_ssl_server_credentials_create(
const char *pem_root_certs, const char **key_cert_pair_cert_chain_array,
const char **key_cert_pair_private_key_array, size_t num_key_cert_pairs) {
size_t i;
grpc_server_credentials *creds;
grpc_ssl_pem_key_cert_pair *key_cert_pairs =
gpr_malloc(sizeof(grpc_ssl_pem_key_cert_pair) * num_key_cert_pairs);
memset(key_cert_pairs, 0,
sizeof(grpc_ssl_pem_key_cert_pair) * num_key_cert_pairs);
for (i = 0; i < num_key_cert_pairs; i++) {
if (key_cert_pair_cert_chain_array[i] ||
key_cert_pair_private_key_array[i]) {
key_cert_pairs[i].cert_chain = key_cert_pair_cert_chain_array[i];
key_cert_pairs[i].private_key = key_cert_pair_private_key_array[i];
}
}
creds = grpc_ssl_server_credentials_create(pem_root_certs, key_cert_pairs,
num_key_cert_pairs);
gpr_free(key_cert_pairs);
return creds;
}
GPR_EXPORT void grpcsharp_server_credentials_release(
grpc_server_credentials *creds) {
grpc_server_credentials_release(creds);
}
GPR_EXPORT gpr_int32 GPR_CALLTYPE
grpcsharp_server_add_secure_http2_port(grpc_server *server, const char *addr,
grpc_server_credentials *creds) {
return grpc_server_add_secure_http2_port(server, addr, creds);
}
/* Logging */
typedef void(GPR_CALLTYPE *grpcsharp_log_func)(const char *file, gpr_int32 line,

@ -10,9 +10,9 @@ This requires `node` to be installed. If you instead have the `nodejs` executabl
## Installation
First, clone this repository (NPM package coming soon). Then follow the instructions in the `INSTALL` file in the root of the repository to install the C core library that this package depends on.
Then, simply run `npm install` in or referencing this directory.
1. Clone [the grpc repository](https://github.com/grpc/grpc).
2. Follow the instructions in the `INSTALL` file in the root of that repository to install the C core library that this package depends on.
3. Run `npm install`.
## Tests

@ -1,6 +1,6 @@
{
"name": "grpc",
"version": "0.5.3",
"version": "0.5.4",
"author": "Google Inc.",
"description": "gRPC Library for Node",
"homepage": "http://www.grpc.io/",

@ -56,6 +56,8 @@
#include "channel.h"
#include "byte_buffer.h"
zend_class_entry *grpc_ce_call;
/* Frees and destroys an instance of wrapped_grpc_call */
void free_wrapped_grpc_call(void *object TSRMLS_DC) {
wrapped_grpc_call *call = (wrapped_grpc_call *)object;

@ -46,7 +46,7 @@
#include "grpc/grpc.h"
/* Class entry for the Call PHP class */
zend_class_entry *grpc_ce_call;
extern zend_class_entry *grpc_ce_call;
/* Wrapper struct for grpc_call that can be associated with a PHP object */
typedef struct wrapped_grpc_call {

@ -54,6 +54,8 @@
#include "server.h"
#include "credentials.h"
zend_class_entry *grpc_ce_channel;
/* Frees and destroys an instance of wrapped_grpc_channel */
void free_wrapped_grpc_channel(void *object TSRMLS_DC) {
wrapped_grpc_channel *channel = (wrapped_grpc_channel *)object;

@ -46,7 +46,7 @@
#include "grpc/grpc.h"
/* Class entry for the PHP Channel class */
zend_class_entry *grpc_ce_channel;
extern zend_class_entry *grpc_ce_channel;
/* Wrapper struct for grpc_channel that can be associated with a PHP object */
typedef struct wrapped_grpc_channel {

@ -49,6 +49,8 @@
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
zend_class_entry *grpc_ce_credentials;
/* Frees and destroys an instance of wrapped_grpc_credentials */
void free_wrapped_grpc_credentials(void *object TSRMLS_DC) {
wrapped_grpc_credentials *creds = (wrapped_grpc_credentials *)object;

@ -47,7 +47,7 @@
#include "grpc/grpc_security.h"
/* Class entry for the Credentials PHP class */
zend_class_entry *grpc_ce_credentials;
extern zend_class_entry *grpc_ce_credentials;
/* Wrapper struct for grpc_credentials that can be associated with a PHP
* object */

@ -56,6 +56,8 @@
#include "server_credentials.h"
#include "timeval.h"
zend_class_entry *grpc_ce_server;
/* Frees and destroys an instance of wrapped_grpc_server */
void free_wrapped_grpc_server(void *object TSRMLS_DC) {
wrapped_grpc_server *server = (wrapped_grpc_server *)object;

@ -46,7 +46,7 @@
#include "grpc/grpc.h"
/* Class entry for the Server PHP class */
zend_class_entry *grpc_ce_server;
extern zend_class_entry *grpc_ce_server;
/* Wrapper struct for grpc_server that can be associated with a PHP object */
typedef struct wrapped_grpc_server {

@ -49,6 +49,8 @@
#include "grpc/grpc.h"
#include "grpc/grpc_security.h"
zend_class_entry *grpc_ce_server_credentials;
/* Frees and destroys an instace of wrapped_grpc_server_credentials */
void free_wrapped_grpc_server_credentials(void *object TSRMLS_DC) {
wrapped_grpc_server_credentials *creds =

@ -47,7 +47,7 @@
#include "grpc/grpc_security.h"
/* Class entry for the Server_Credentials PHP class */
zend_class_entry *grpc_ce_server_credentials;
extern zend_class_entry *grpc_ce_server_credentials;
/* Wrapper struct for grpc_server_credentials that can be associated with a PHP
* object */

@ -50,6 +50,8 @@
#include "grpc/grpc.h"
#include "grpc/support/time.h"
zend_class_entry *grpc_ce_timeval;
/* Frees and destroys an instance of wrapped_grpc_call */
void free_wrapped_grpc_timeval(void *object TSRMLS_DC) { efree(object); }

@ -47,7 +47,7 @@
#include "grpc/support/time.h"
/* Class entry for the Timeval PHP Class */
zend_class_entry *grpc_ce_timeval;
extern zend_class_entry *grpc_ce_timeval;
/* Wrapper struct for timeval that can be associated with a PHP object */
typedef struct wrapped_grpc_timeval {

@ -45,7 +45,7 @@ static int pygrpc_call_init(Call *self, PyObject *args, PyObject *kwds) {
const PyObject *channel;
const char *method;
const char *host;
const double deadline;
double deadline;
static char *kwlist[] = {"channel", "method", "host", "deadline", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!ssd:Call", kwlist,

@ -71,7 +71,8 @@ class _Server(interfaces.Server):
_ONE_DAY_IN_SECONDS)
self._fore_link = _fore.ForeLink(
self._pool, self._breakdown.request_deserializers,
self._breakdown.response_serializers, None, self._key_chain_pairs)
self._breakdown.response_serializers, None, self._key_chain_pairs,
port=self._port)
self._back.join_fore_link(self._fore_link)
self._fore_link.join_rear_link(self._back)
self._fore_link.start()

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save