From 9e9f7b62c706245cd74de1a7f01c03ba0bd96b0b Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 16 May 2016 19:12:12 -0700 Subject: Refactorings and renamings related to compression. Also added levels to the channel args options. --- src/cpp/server/server_builder.cc | 7 +++++++ src/cpp/server/server_context.cc | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/cpp/server') diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 61f0f6ae2a..e6050c3b52 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -125,6 +125,13 @@ std::unique_ptr ServerBuilder::BuildAndStart() { } args.SetInt(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET, compression_options_.enabled_algorithms_bitset); + if (compression_options_.default_level.is_set) { + args.SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL, + compression_options_.default_level.level); + } else if (compression_options_.default_algorithm.is_set) { + args.SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, + compression_options_.default_algorithm.algorithm); + } std::unique_ptr server( new Server(thread_pool.release(), true, max_message_size_, &args)); ServerInitializer* initializer = server->initializer(); diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 204fef1b09..43117fd1e9 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -42,7 +42,6 @@ #include #include -#include "src/core/lib/channel/compress_filter.h" #include "src/core/lib/surface/call.h" namespace grpc { @@ -196,6 +195,9 @@ bool ServerContext::IsCancelled() const { } void ServerContext::set_compression_level(grpc_compression_level level) { + // TODO(dgq): get rid of grpc_call_compression_for_level and propagate the + // compression level by adding a new argument to + // CallOpSendInitialMetadata::SendInitialMetadata. const grpc_compression_algorithm algorithm_for_level = grpc_call_compression_for_level(call_, level); set_compression_algorithm(algorithm_for_level); @@ -210,7 +212,7 @@ void ServerContext::set_compression_algorithm( abort(); } GPR_ASSERT(algorithm_name != NULL); - AddInitialMetadata(GRPC_COMPRESS_REQUEST_ALGORITHM_KEY, algorithm_name); + AddInitialMetadata(GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY, algorithm_name); } grpc::string ServerContext::peer() const { -- cgit v1.2.3 From 2d02456e785053735172186868300d0f4dde3d9e Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Tue, 17 May 2016 23:24:39 -0700 Subject: got rid of grpc_compression_options --- include/grpc++/server_builder.h | 48 +++++++++++----- include/grpc/compression.h | 14 ----- include/grpc/impl/codegen/compression_types.h | 26 --------- src/core/lib/compression/compression_algorithm.c | 22 -------- src/cpp/server/server_builder.cc | 71 ++++++++++++++++++------ test/core/compression/compression_test.c | 30 ---------- 6 files changed, 90 insertions(+), 121 deletions(-) (limited to 'src/cpp/server') diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h index ad629521cb..c48c86d2b8 100644 --- a/include/grpc++/server_builder.h +++ b/include/grpc++/server_builder.h @@ -66,29 +66,43 @@ class ServerBuilder { /// The service must exist for the lifetime of the \a Server instance returned /// by \a BuildAndStart(). /// Matches requests with any :authority - void RegisterService(Service* service); + ServerBuilder& RegisterService(Service* service); /// Register a generic service. /// Matches requests with any :authority - void RegisterAsyncGenericService(AsyncGenericService* service); + ServerBuilder& RegisterAsyncGenericService(AsyncGenericService* service); /// Register a service. This call does not take ownership of the service. /// The service must exist for the lifetime of the \a Server instance returned /// by BuildAndStart(). /// Only matches requests with :authority \a host - void RegisterService(const grpc::string& host, Service* service); + ServerBuilder& RegisterService(const grpc::string& host, Service* service); /// Set max message size in bytes. - void SetMaxMessageSize(int max_message_size) { + ServerBuilder& SetMaxMessageSize(int max_message_size) { max_message_size_ = max_message_size; + return *this; } - /// Set the compression options to be used by the server. - void SetCompressionOptions(const grpc_compression_options& options) { - compression_options_ = options; - } + /// Set the support status for compression algorithms. All algorithms are + /// enabled by default. + /// + /// Incoming calls compressed with an unsupported algorithm will fail with + /// GRPC_STATUS_UNIMPLEMENTED. + ServerBuilder& SetCompressionAlgorithmSupportStatus( + grpc_compression_algorithm algorithm, bool enabled); + + /// The default compression level to use for all channel calls in the + /// absence of a call-specific level. + ServerBuilder& SetDefaultCompressionLevel(grpc_compression_level level); + + /// The default compression algorithm to use for all channel calls in the + /// absence of a call-specific level. Note that it overrides any compression + /// level set by \a SetDefaultCompressionLevel. + ServerBuilder& SetDefaultCompressionAlgorithm( + grpc_compression_algorithm algorithm); - void SetOption(std::unique_ptr option); + ServerBuilder& SetOption(std::unique_ptr option); /// Tries to bind \a server to the given \a addr. /// @@ -101,9 +115,9 @@ class ServerBuilder { /// number. \a nullptr otherwise. /// // TODO(dgq): the "port" part seems to be a misnomer. - void AddListeningPort(const grpc::string& addr, - std::shared_ptr creds, - int* selected_port = nullptr); + ServerBuilder& AddListeningPort(const grpc::string& addr, + std::shared_ptr creds, + int* selected_port = nullptr); /// Add a completion queue for handling asynchronous services /// Caller is required to keep this completion queue live until @@ -136,7 +150,6 @@ class ServerBuilder { }; int max_message_size_; - grpc_compression_options compression_options_; std::vector> options_; std::vector> services_; std::vector ports_; @@ -144,6 +157,15 @@ class ServerBuilder { std::shared_ptr creds_; std::map> plugins_; AsyncGenericService* generic_service_; + struct { + bool is_set; + grpc_compression_level level; + } maybe_default_compression_level_; + struct { + bool is_set; + grpc_compression_algorithm algorithm; + } maybe_default_compression_algorithm_; + uint32_t enabled_compression_algorithms_bitset_; }; } // namespace grpc diff --git a/include/grpc/compression.h b/include/grpc/compression.h index 04816b9f3a..3eba00c986 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -55,20 +55,6 @@ GRPCAPI int grpc_compression_algorithm_parse( GRPCAPI int grpc_compression_algorithm_name( grpc_compression_algorithm algorithm, char **name); -GRPCAPI void grpc_compression_options_init(grpc_compression_options *opts); - -/** Mark \a algorithm as enabled in \a opts. */ -GRPCAPI void grpc_compression_options_enable_algorithm( - grpc_compression_options *opts, grpc_compression_algorithm algorithm); - -/** Mark \a algorithm as disabled in \a opts. */ -GRPCAPI void grpc_compression_options_disable_algorithm( - grpc_compression_options *opts, grpc_compression_algorithm algorithm); - -/** Returns true if \a algorithm is marked as enabled in \a opts. */ -GRPCAPI int grpc_compression_options_is_algorithm_enabled( - const grpc_compression_options *opts, grpc_compression_algorithm algorithm); - #ifdef __cplusplus } #endif diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index 7cf68bfaf8..19c2cefcf4 100644 --- a/include/grpc/impl/codegen/compression_types.h +++ b/include/grpc/impl/codegen/compression_types.h @@ -74,32 +74,6 @@ typedef enum { GRPC_COMPRESS_LEVEL_COUNT } grpc_compression_level; -typedef struct grpc_compression_options { - /** All algs are enabled by default. This option corresponds to the channel - * argument key behind \a GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET - */ - uint32_t enabled_algorithms_bitset; - - /** The default channel compression level. It'll be used in the absence of - * call specific settings. This option corresponds to the channel argument key - * behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL. If present, takes - * precedence over \a default_algorithm. - * TODO(dgq): currently only available for server channels. */ - struct { - bool is_set; - grpc_compression_algorithm level; - } default_level; - - /** The default channel compression algorithm. It'll be used in the absence of - * call specific settings. This option corresponds to the channel argument key - * behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM. */ - struct { - bool is_set; - grpc_compression_algorithm algorithm; - } default_algorithm; - -} grpc_compression_options; - #ifdef __cplusplus } #endif diff --git a/src/core/lib/compression/compression_algorithm.c b/src/core/lib/compression/compression_algorithm.c index c7f834d989..6cbdbd81b0 100644 --- a/src/core/lib/compression/compression_algorithm.c +++ b/src/core/lib/compression/compression_algorithm.c @@ -124,25 +124,3 @@ grpc_mdelem *grpc_compression_encoding_mdelem( } return NULL; } - -void grpc_compression_options_init(grpc_compression_options *opts) { - opts->enabled_algorithms_bitset = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; - opts->default_level.is_set = false; - opts->default_algorithm.is_set = false; -} - -void grpc_compression_options_enable_algorithm( - grpc_compression_options *opts, grpc_compression_algorithm algorithm) { - GPR_BITSET(&opts->enabled_algorithms_bitset, algorithm); -} - -void grpc_compression_options_disable_algorithm( - grpc_compression_options *opts, grpc_compression_algorithm algorithm) { - GPR_BITCLEAR(&opts->enabled_algorithms_bitset, algorithm); -} - -int grpc_compression_options_is_algorithm_enabled( - const grpc_compression_options *opts, - grpc_compression_algorithm algorithm) { - return GPR_BITGET(opts->enabled_algorithms_bitset, algorithm); -} diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index e6050c3b52..bbea9355ba 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -37,6 +37,8 @@ #include #include #include + +#include "include/grpc/support/useful.h" #include "src/cpp/server/thread_pool_interface.h" namespace grpc { @@ -52,12 +54,18 @@ static void do_plugin_list_init(void) { ServerBuilder::ServerBuilder() : max_message_size_(-1), generic_service_(nullptr) { - grpc_compression_options_init(&compression_options_); gpr_once_init(&once_init_plugin_list, do_plugin_list_init); for (auto factory : (*g_plugin_factory_list)) { std::unique_ptr plugin = factory(); plugins_[plugin->name()] = std::move(plugin); } + // all compression algorithms enabled by default. + enabled_compression_algorithms_bitset_ = + (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; + memset(&maybe_default_compression_level_, 0, + sizeof(maybe_default_compression_level_)); + memset(&maybe_default_compression_algorithm_, 0, + sizeof(maybe_default_compression_algorithm_)); } std::unique_ptr ServerBuilder::AddCompletionQueue() { @@ -66,35 +74,65 @@ std::unique_ptr ServerBuilder::AddCompletionQueue() { return std::unique_ptr(cq); } -void ServerBuilder::RegisterService(Service* service) { +ServerBuilder& ServerBuilder::RegisterService(Service* service) { services_.emplace_back(new NamedService(service)); + return *this; } -void ServerBuilder::RegisterService(const grpc::string& addr, - Service* service) { +ServerBuilder& ServerBuilder::RegisterService(const grpc::string& addr, + Service* service) { services_.emplace_back(new NamedService(addr, service)); + return *this; } -void ServerBuilder::RegisterAsyncGenericService(AsyncGenericService* service) { +ServerBuilder& ServerBuilder::RegisterAsyncGenericService( + AsyncGenericService* service) { if (generic_service_) { gpr_log(GPR_ERROR, "Adding multiple AsyncGenericService is unsupported for now. " "Dropping the service %p", service); - return; + } else { + generic_service_ = service; } - generic_service_ = service; + return *this; } -void ServerBuilder::SetOption(std::unique_ptr option) { +ServerBuilder& ServerBuilder::SetOption( + std::unique_ptr option) { options_.push_back(std::move(option)); + return *this; +} + +ServerBuilder& ServerBuilder::SetCompressionAlgorithmSupportStatus( + grpc_compression_algorithm algorithm, bool enabled) { + if (enabled) { + GPR_BITSET(&enabled_compression_algorithms_bitset_, algorithm); + } else { + GPR_BITCLEAR(&enabled_compression_algorithms_bitset_, algorithm); + } + return *this; } -void ServerBuilder::AddListeningPort(const grpc::string& addr, - std::shared_ptr creds, - int* selected_port) { +ServerBuilder& ServerBuilder::SetDefaultCompressionLevel( + grpc_compression_level level) { + maybe_default_compression_level_.level = level; + return *this; +} + +ServerBuilder& ServerBuilder::SetDefaultCompressionAlgorithm( + grpc_compression_algorithm algorithm) { + maybe_default_compression_algorithm_.is_set = true; + maybe_default_compression_algorithm_.algorithm = algorithm; + return *this; +} + +ServerBuilder& ServerBuilder::AddListeningPort( + const grpc::string& addr, std::shared_ptr creds, + int* selected_port) { Port port = {addr, creds, selected_port}; ports_.push_back(port); + return *this; } std::unique_ptr ServerBuilder::BuildAndStart() { @@ -124,13 +162,14 @@ std::unique_ptr ServerBuilder::BuildAndStart() { args.SetInt(GRPC_ARG_MAX_MESSAGE_LENGTH, max_message_size_); } args.SetInt(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET, - compression_options_.enabled_algorithms_bitset); - if (compression_options_.default_level.is_set) { + enabled_compression_algorithms_bitset_); + if (maybe_default_compression_level_.is_set) { args.SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL, - compression_options_.default_level.level); - } else if (compression_options_.default_algorithm.is_set) { + maybe_default_compression_level_.level); + } + if (maybe_default_compression_algorithm_.is_set) { args.SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, - compression_options_.default_algorithm.algorithm); + maybe_default_compression_algorithm_.algorithm); } std::unique_ptr server( new Server(thread_pool.release(), true, max_message_size_, &args)); diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c index ed6f9e7214..5ee1805222 100644 --- a/test/core/compression/compression_test.c +++ b/test/core/compression/compression_test.c @@ -92,40 +92,10 @@ static void test_compression_algorithm_name(void) { /* the value of "name" is undefined upon failure */ } -static void test_compression_enable_disable_algorithm(void) { - grpc_compression_options options; - grpc_compression_algorithm algorithm; - - gpr_log(GPR_DEBUG, "test_compression_enable_disable_algorithm"); - - grpc_compression_options_init(&options); - for (algorithm = GRPC_COMPRESS_NONE; - algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) { - /* all algorithms are enabled by default */ - GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options, - algorithm) != 0); - } - /* disable one by one */ - for (algorithm = GRPC_COMPRESS_NONE; - algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) { - grpc_compression_options_disable_algorithm(&options, algorithm); - GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options, - algorithm) == 0); - } - /* re-enable one by one */ - for (algorithm = GRPC_COMPRESS_NONE; - algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) { - grpc_compression_options_enable_algorithm(&options, algorithm); - GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options, - algorithm) != 0); - } -} - int main(int argc, char **argv) { grpc_init(); test_compression_algorithm_parse(); test_compression_algorithm_name(); - test_compression_enable_disable_algorithm(); grpc_shutdown(); return 0; -- cgit v1.2.3 From b97e2d145efb4d0b407d18b43d3b7bb38bccf61f Mon Sep 17 00:00:00 2001 From: Adam Michalik Date: Thu, 2 Jun 2016 12:12:55 -0700 Subject: Add C++ support for using external FD --- BUILD | 8 +++ Makefile | 8 +++ build.yaml | 4 ++ include/grpc++/create_channel_posix.h | 57 ++++++++++++++++++++++ include/grpc++/grpc++.h | 2 + include/grpc++/server.h | 6 +++ include/grpc++/server_posix.h | 56 +++++++++++++++++++++ include/grpc/grpc_posix.h | 4 +- include/grpc/impl/codegen/port_platform.h | 5 ++ .../chttp2/client/insecure/channel_create_posix.c | 4 +- .../chttp2/server/insecure/server_chttp2_posix.c | 4 +- src/cpp/client/create_channel_posix.cc | 57 ++++++++++++++++++++++ src/cpp/server/server.cc | 8 +++ src/cpp/server/server_posix.cc | 51 +++++++++++++++++++ src/python/grpcio/grpc/_cython/imports.generated.h | 2 +- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 2 +- tools/doxygen/Doxyfile.c++ | 2 + tools/doxygen/Doxyfile.c++.internal | 4 ++ tools/run_tests/sources_and_headers.json | 6 +++ vsprojects/vcxproj/grpc++/grpc++.vcxproj | 6 +++ vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters | 12 +++++ .../grpc++_unsecure/grpc++_unsecure.vcxproj | 6 +++ .../grpc++_unsecure.vcxproj.filters | 12 +++++ 23 files changed, 318 insertions(+), 8 deletions(-) create mode 100644 include/grpc++/create_channel_posix.h create mode 100644 include/grpc++/server_posix.h create mode 100644 src/cpp/client/create_channel_posix.cc create mode 100644 src/cpp/server/server_posix.cc (limited to 'src/cpp/server') diff --git a/BUILD b/BUILD index f1f3b8bff7..16bbdaa7ce 100644 --- a/BUILD +++ b/BUILD @@ -1236,6 +1236,7 @@ cc_library( "src/cpp/client/client_context.cc", "src/cpp/client/create_channel.cc", "src/cpp/client/create_channel_internal.cc", + "src/cpp/client/create_channel_posix.cc", "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", @@ -1251,6 +1252,7 @@ cc_library( "src/cpp/server/server_builder.cc", "src/cpp/server/server_context.cc", "src/cpp/server/server_credentials.cc", + "src/cpp/server/server_posix.cc", "src/cpp/util/byte_buffer.cc", "src/cpp/util/slice.cc", "src/cpp/util/status.cc", @@ -1264,6 +1266,7 @@ cc_library( "include/grpc++/client_context.h", "include/grpc++/completion_queue.h", "include/grpc++/create_channel.h", + "include/grpc++/create_channel_posix.h", "include/grpc++/generic/async_generic_service.h", "include/grpc++/generic/generic_stub.h", "include/grpc++/grpc++.h", @@ -1291,6 +1294,7 @@ cc_library( "include/grpc++/server.h", "include/grpc++/server_builder.h", "include/grpc++/server_context.h", + "include/grpc++/server_posix.h", "include/grpc++/support/async_stream.h", "include/grpc++/support/async_unary_call.h", "include/grpc++/support/byte_buffer.h", @@ -1380,6 +1384,7 @@ cc_library( "src/cpp/client/client_context.cc", "src/cpp/client/create_channel.cc", "src/cpp/client/create_channel_internal.cc", + "src/cpp/client/create_channel_posix.cc", "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", @@ -1395,6 +1400,7 @@ cc_library( "src/cpp/server/server_builder.cc", "src/cpp/server/server_context.cc", "src/cpp/server/server_credentials.cc", + "src/cpp/server/server_posix.cc", "src/cpp/util/byte_buffer.cc", "src/cpp/util/slice.cc", "src/cpp/util/status.cc", @@ -1408,6 +1414,7 @@ cc_library( "include/grpc++/client_context.h", "include/grpc++/completion_queue.h", "include/grpc++/create_channel.h", + "include/grpc++/create_channel_posix.h", "include/grpc++/generic/async_generic_service.h", "include/grpc++/generic/generic_stub.h", "include/grpc++/grpc++.h", @@ -1435,6 +1442,7 @@ cc_library( "include/grpc++/server.h", "include/grpc++/server_builder.h", "include/grpc++/server_context.h", + "include/grpc++/server_posix.h", "include/grpc++/support/async_stream.h", "include/grpc++/support/async_unary_call.h", "include/grpc++/support/byte_buffer.h", diff --git a/Makefile b/Makefile index 78900aedd8..58358e2333 100644 --- a/Makefile +++ b/Makefile @@ -3431,6 +3431,7 @@ LIBGRPC++_SRC = \ src/cpp/client/client_context.cc \ src/cpp/client/create_channel.cc \ src/cpp/client/create_channel_internal.cc \ + src/cpp/client/create_channel_posix.cc \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ @@ -3446,6 +3447,7 @@ LIBGRPC++_SRC = \ src/cpp/server/server_builder.cc \ src/cpp/server/server_context.cc \ src/cpp/server/server_credentials.cc \ + src/cpp/server/server_posix.cc \ src/cpp/util/byte_buffer.cc \ src/cpp/util/slice.cc \ src/cpp/util/status.cc \ @@ -3459,6 +3461,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/client_context.h \ include/grpc++/completion_queue.h \ include/grpc++/create_channel.h \ + include/grpc++/create_channel_posix.h \ include/grpc++/generic/async_generic_service.h \ include/grpc++/generic/generic_stub.h \ include/grpc++/grpc++.h \ @@ -3486,6 +3489,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/server.h \ include/grpc++/server_builder.h \ include/grpc++/server_context.h \ + include/grpc++/server_posix.h \ include/grpc++/support/async_stream.h \ include/grpc++/support/async_unary_call.h \ include/grpc++/support/byte_buffer.h \ @@ -3786,6 +3790,7 @@ LIBGRPC++_UNSECURE_SRC = \ src/cpp/client/client_context.cc \ src/cpp/client/create_channel.cc \ src/cpp/client/create_channel_internal.cc \ + src/cpp/client/create_channel_posix.cc \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ @@ -3801,6 +3806,7 @@ LIBGRPC++_UNSECURE_SRC = \ src/cpp/server/server_builder.cc \ src/cpp/server/server_context.cc \ src/cpp/server/server_credentials.cc \ + src/cpp/server/server_posix.cc \ src/cpp/util/byte_buffer.cc \ src/cpp/util/slice.cc \ src/cpp/util/status.cc \ @@ -3814,6 +3820,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/client_context.h \ include/grpc++/completion_queue.h \ include/grpc++/create_channel.h \ + include/grpc++/create_channel_posix.h \ include/grpc++/generic/async_generic_service.h \ include/grpc++/generic/generic_stub.h \ include/grpc++/grpc++.h \ @@ -3841,6 +3848,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/server.h \ include/grpc++/server_builder.h \ include/grpc++/server_context.h \ + include/grpc++/server_posix.h \ include/grpc++/support/async_stream.h \ include/grpc++/support/async_unary_call.h \ include/grpc++/support/byte_buffer.h \ diff --git a/build.yaml b/build.yaml index 0a57965ab7..a84309fe28 100644 --- a/build.yaml +++ b/build.yaml @@ -635,6 +635,7 @@ filegroups: - include/grpc++/client_context.h - include/grpc++/completion_queue.h - include/grpc++/create_channel.h + - include/grpc++/create_channel_posix.h - include/grpc++/generic/async_generic_service.h - include/grpc++/generic/generic_stub.h - include/grpc++/grpc++.h @@ -662,6 +663,7 @@ filegroups: - include/grpc++/server.h - include/grpc++/server_builder.h - include/grpc++/server_context.h + - include/grpc++/server_posix.h - include/grpc++/support/async_stream.h - include/grpc++/support/async_unary_call.h - include/grpc++/support/byte_buffer.h @@ -684,6 +686,7 @@ filegroups: - src/cpp/client/client_context.cc - src/cpp/client/create_channel.cc - src/cpp/client/create_channel_internal.cc + - src/cpp/client/create_channel_posix.cc - src/cpp/client/credentials.cc - src/cpp/client/generic_stub.cc - src/cpp/client/insecure_credentials.cc @@ -699,6 +702,7 @@ filegroups: - src/cpp/server/server_builder.cc - src/cpp/server/server_context.cc - src/cpp/server/server_credentials.cc + - src/cpp/server/server_posix.cc - src/cpp/util/byte_buffer.cc - src/cpp/util/slice.cc - src/cpp/util/status.cc diff --git a/include/grpc++/create_channel_posix.h b/include/grpc++/create_channel_posix.h new file mode 100644 index 0000000000..0ca947d044 --- /dev/null +++ b/include/grpc++/create_channel_posix.h @@ -0,0 +1,57 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPCXX_CREATE_CHANNEL_POSIX_H +#define GRPCXX_CREATE_CHANNEL_POSIX_H + +#include + +#include +#include + +namespace grpc { + +#ifdef GPR_SUPPORT_CHANNELS_FROM_FD + +/// Create a new \a Channel communicating over given file descriptor +/// +/// \param target The name of the target. +/// \param fd The file descriptor representing a socket. +std::shared_ptr CreateInsecureChannelFromFd( + const grpc::string& target, int fd); + +#endif // GPR_SUPPORT_CHANNELS_FROM_FD + +} // namespace grpc + +#endif // GRPCXX_CREATE_CHANNEL_POSIX_H diff --git a/include/grpc++/grpc++.h b/include/grpc++/grpc++.h index b7d5fb0bbc..ef07e19975 100644 --- a/include/grpc++/grpc++.h +++ b/include/grpc++/grpc++.h @@ -57,8 +57,10 @@ #include #include #include +#include #include #include #include +#include #endif // GRPCXX_GRPCXX_H diff --git a/include/grpc++/server.h b/include/grpc++/server.h index a0ee0e98e4..7a8858ef19 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -93,6 +93,12 @@ class Server GRPC_FINAL : public ServerInterface, private GrpcLibraryCodegen { /// until all server objects in the process have been destroyed. static void SetGlobalCallbacks(GlobalCallbacks* callbacks); + // Returns a \em raw pointer to the underlying grpc_server instance. + grpc_server* c_server(); + + // Returns a \em raw pointer to the underlying CompletionQueue. + CompletionQueue* completion_queue(); + private: friend class AsyncGenericService; friend class ServerBuilder; diff --git a/include/grpc++/server_posix.h b/include/grpc++/server_posix.h new file mode 100644 index 0000000000..1595ba6e00 --- /dev/null +++ b/include/grpc++/server_posix.h @@ -0,0 +1,56 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPCXX_SERVER_POSIX_H +#define GRPCXX_SERVER_POSIX_H + +#include + +#include +#include + +namespace grpc { + +#ifdef GPR_SUPPORT_CHANNELS_FROM_FD + +/// Adds new client to a \a Server communicating over given file descriptor +/// +/// \param server The server to add a client to. +/// \param fd The file descriptor representing a socket. +void AddInsecureChannelFromFd(Server* server, int fd); + +#endif // GPR_SUPPORT_CHANNELS_FROM_FD + +} // namespace grpc + +#endif // GRPCXX_CREATE_CHANNEL_POSIX_H diff --git a/include/grpc/grpc_posix.h b/include/grpc/grpc_posix.h index 509e51e2c4..06cc3aad8a 100644 --- a/include/grpc/grpc_posix.h +++ b/include/grpc/grpc_posix.h @@ -50,7 +50,7 @@ extern "C" { * functionality on top of GRPC Core. */ -#ifdef GPR_POSIX_SOCKET +#ifdef GPR_SUPPORT_CHANNELS_FROM_FD /** Create a client channel to 'target' using file descriptor 'fd'. The 'target' argument will be used to indicate the name for this channel. See the comment @@ -66,7 +66,7 @@ GRPCAPI void grpc_server_add_insecure_channel_from_fd(grpc_server *server, grpc_completion_queue *cq, int fd); -#endif // GPR_POSIX_SOCKET +#endif // GPR_SUPPORT_CHANNELS_FROM_FD #ifdef __cplusplus } diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index be4215a54b..7fff36cb78 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -129,6 +129,7 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GPR_POSIX_SOCKETUTILS 1 +#define GPR_SUPPORT_CHANNELS_FROM_FD 1 #define GPR_HAVE_UNIX_SOCKET 1 #define GPR_HAVE_IP_PKTINFO 1 #define GPR_HAVE_IPV6_RECVPKTINFO 1 @@ -168,6 +169,7 @@ #define GPR_POSIX_SYNC 1 #define GPR_POSIX_TIME 1 #define GPR_GETPID_IN_UNISTD_H 1 +#define GPR_SUPPORT_CHANNELS_FROM_FD 1 #define GPR_HAVE_MSG_NOSIGNAL 1 #define GPR_HAVE_UNIX_SOCKET 1 #define GPR_HAVE_IP_PKTINFO 1 @@ -194,6 +196,7 @@ #define GPR_POSIX_WAKEUP_FD 1 #define GPR_POSIX_SOCKET 1 #define GPR_POSIX_SOCKETADDR 1 +#define GPR_SUPPORT_CHANNELS_FROM_FD 1 #define GPR_HAVE_UNIX_SOCKET 1 #define GPR_HAVE_IP_PKTINFO 1 #define GPR_HAVE_IPV6_RECVPKTINFO 1 @@ -258,6 +261,7 @@ #define GPR_POSIX_SYNC 1 #define GPR_POSIX_TIME 1 #define GPR_GETPID_IN_UNISTD_H 1 +#define GPR_SUPPORT_CHANNELS_FROM_FD 1 #define GPR_HAVE_SO_NOSIGPIPE 1 #define GPR_HAVE_UNIX_SOCKET 1 #define GPR_HAVE_IP_PKTINFO 1 @@ -289,6 +293,7 @@ #define GPR_POSIX_SYNC 1 #define GPR_POSIX_TIME 1 #define GPR_GETPID_IN_UNISTD_H 1 +#define GPR_SUPPORT_CHANNELS_FROM_FD 1 #define GPR_HAVE_SO_NOSIGPIPE 1 #define GPR_HAVE_UNIX_SOCKET 1 #define GPR_HAVE_IP_PKTINFO 1 diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c index 7d28dbf8a9..d3e27a5963 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c @@ -33,7 +33,7 @@ #include -#ifdef GPR_POSIX_SOCKET +#ifdef GPR_SUPPORT_CHANNELS_FROM_FD #include @@ -85,4 +85,4 @@ grpc_channel *grpc_insecure_channel_create_from_fd( "Failed to create client channel"); } -#endif // GPR_POSIX_SOCKET +#endif // GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c index 1807efc85d..11e5c45289 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c @@ -33,7 +33,7 @@ #include -#ifdef GPR_POSIX_SOCKET +#ifdef GPR_SUPPORT_CHANNELS_FROM_FD #include #include @@ -67,4 +67,4 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server *server, } -#endif // GPR_POSIX_SOCKET +#endif // GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/cpp/client/create_channel_posix.cc b/src/cpp/client/create_channel_posix.cc new file mode 100644 index 0000000000..99ffebd392 --- /dev/null +++ b/src/cpp/client/create_channel_posix.cc @@ -0,0 +1,57 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + +#include +#include +#include +#include +#include + +#include "src/cpp/client/create_channel_internal.h" + +namespace grpc { + +#ifdef GPR_SUPPORT_CHANNELS_FROM_FD + +std::shared_ptr CreateInsecureChannelFromFd( + const grpc::string& target, int fd) { + internal::GrpcLibrary init_lib; + init_lib.init(); + return CreateChannelInternal( + "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr)); +} + +#endif // GPR_SUPPORT_CHANNELS_FROM_FD + +} // namespace grpc diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index f6c3e5747c..72a6150e96 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -329,6 +329,14 @@ void Server::SetGlobalCallbacks(GlobalCallbacks* callbacks) { g_callbacks.reset(callbacks); } +grpc_server* Server::c_server() { + return server_; +} + +CompletionQueue* Server::completion_queue() { + return &cq_; +} + static grpc_server_register_method_payload_handling PayloadHandlingForMethod( RpcServiceMethod* method) { switch (method->method_type()) { diff --git a/src/cpp/server/server_posix.cc b/src/cpp/server/server_posix.cc new file mode 100644 index 0000000000..7ed8cd069c --- /dev/null +++ b/src/cpp/server/server_posix.cc @@ -0,0 +1,51 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include + +namespace grpc { + +#ifdef GPR_SUPPORT_CHANNELS_FROM_FD + +void AddInsecureChannelFromFd(Server* server, int fd) { + grpc_server_add_insecure_channel_from_fd(server->c_server(), + server->completion_queue()->cq(), + fd); + +#endif // GPR_SUPPORT_CHANNELS_FROM_FD + +} + +} // namespace grpc diff --git a/src/python/grpcio/grpc/_cython/imports.generated.h b/src/python/grpcio/grpc/_cython/imports.generated.h index 701a3aec28..16bb5cdfab 100644 --- a/src/python/grpcio/grpc/_cython/imports.generated.h +++ b/src/python/grpcio/grpc/_cython/imports.generated.h @@ -332,7 +332,7 @@ extern grpc_call_error_to_string_type grpc_call_error_to_string_import; typedef grpc_channel *(*grpc_insecure_channel_create_from_fd_type)(const char *target, int fd, const grpc_channel_args *args); extern grpc_insecure_channel_create_from_fd_type grpc_insecure_channel_create_from_fd_import; #define grpc_insecure_channel_create_from_fd grpc_insecure_channel_create_from_fd_import -typedef void(*grpc_server_add_insecure_channel_from_fd_type)(grpc_server *server, int fd); +typedef void(*grpc_server_add_insecure_channel_from_fd_type)(grpc_server *server, grpc_completion_queue *cq, int fd); extern grpc_server_add_insecure_channel_from_fd_type grpc_server_add_insecure_channel_from_fd_import; #define grpc_server_add_insecure_channel_from_fd grpc_server_add_insecure_channel_from_fd_import typedef const grpc_auth_property *(*grpc_auth_property_iterator_next_type)(grpc_auth_property_iterator *it); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 4a7d4b272a..9c86a3690c 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -332,7 +332,7 @@ extern grpc_call_error_to_string_type grpc_call_error_to_string_import; typedef grpc_channel *(*grpc_insecure_channel_create_from_fd_type)(const char *target, int fd, const grpc_channel_args *args); extern grpc_insecure_channel_create_from_fd_type grpc_insecure_channel_create_from_fd_import; #define grpc_insecure_channel_create_from_fd grpc_insecure_channel_create_from_fd_import -typedef void(*grpc_server_add_insecure_channel_from_fd_type)(grpc_server *server, int fd); +typedef void(*grpc_server_add_insecure_channel_from_fd_type)(grpc_server *server, grpc_completion_queue *cq, int fd); extern grpc_server_add_insecure_channel_from_fd_type grpc_server_add_insecure_channel_from_fd_import; #define grpc_server_add_insecure_channel_from_fd grpc_server_add_insecure_channel_from_fd_import typedef const grpc_auth_property *(*grpc_auth_property_iterator_next_type)(grpc_auth_property_iterator *it); diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 0017792020..49c0e1279c 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -765,6 +765,7 @@ include/grpc++/channel.h \ include/grpc++/client_context.h \ include/grpc++/completion_queue.h \ include/grpc++/create_channel.h \ +include/grpc++/create_channel_posix.h \ include/grpc++/generic/async_generic_service.h \ include/grpc++/generic/generic_stub.h \ include/grpc++/grpc++.h \ @@ -792,6 +793,7 @@ include/grpc++/security/server_credentials.h \ include/grpc++/server.h \ include/grpc++/server_builder.h \ include/grpc++/server_context.h \ +include/grpc++/server_posix.h \ include/grpc++/support/async_stream.h \ include/grpc++/support/async_unary_call.h \ include/grpc++/support/byte_buffer.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 1c6884c0df..232951e16c 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -765,6 +765,7 @@ include/grpc++/channel.h \ include/grpc++/client_context.h \ include/grpc++/completion_queue.h \ include/grpc++/create_channel.h \ +include/grpc++/create_channel_posix.h \ include/grpc++/generic/async_generic_service.h \ include/grpc++/generic/generic_stub.h \ include/grpc++/grpc++.h \ @@ -792,6 +793,7 @@ include/grpc++/security/server_credentials.h \ include/grpc++/server.h \ include/grpc++/server_builder.h \ include/grpc++/server_context.h \ +include/grpc++/server_posix.h \ include/grpc++/support/async_stream.h \ include/grpc++/support/async_unary_call.h \ include/grpc++/support/byte_buffer.h \ @@ -872,6 +874,7 @@ src/cpp/client/channel.cc \ src/cpp/client/client_context.cc \ src/cpp/client/create_channel.cc \ src/cpp/client/create_channel_internal.cc \ +src/cpp/client/create_channel_posix.cc \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ @@ -887,6 +890,7 @@ src/cpp/server/server.cc \ src/cpp/server/server_builder.cc \ src/cpp/server/server_context.cc \ src/cpp/server/server_credentials.cc \ +src/cpp/server/server_posix.cc \ src/cpp/util/byte_buffer.cc \ src/cpp/util/slice.cc \ src/cpp/util/status.cc \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 782aa373bf..fe6d3a23a0 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -6435,6 +6435,7 @@ "include/grpc++/client_context.h", "include/grpc++/completion_queue.h", "include/grpc++/create_channel.h", + "include/grpc++/create_channel_posix.h", "include/grpc++/generic/async_generic_service.h", "include/grpc++/generic/generic_stub.h", "include/grpc++/grpc++.h", @@ -6462,6 +6463,7 @@ "include/grpc++/server.h", "include/grpc++/server_builder.h", "include/grpc++/server_context.h", + "include/grpc++/server_posix.h", "include/grpc++/support/async_stream.h", "include/grpc++/support/async_unary_call.h", "include/grpc++/support/byte_buffer.h", @@ -6487,6 +6489,7 @@ "include/grpc++/client_context.h", "include/grpc++/completion_queue.h", "include/grpc++/create_channel.h", + "include/grpc++/create_channel_posix.h", "include/grpc++/generic/async_generic_service.h", "include/grpc++/generic/generic_stub.h", "include/grpc++/grpc++.h", @@ -6514,6 +6517,7 @@ "include/grpc++/server.h", "include/grpc++/server_builder.h", "include/grpc++/server_context.h", + "include/grpc++/server_posix.h", "include/grpc++/support/async_stream.h", "include/grpc++/support/async_unary_call.h", "include/grpc++/support/byte_buffer.h", @@ -6531,6 +6535,7 @@ "src/cpp/client/create_channel.cc", "src/cpp/client/create_channel_internal.cc", "src/cpp/client/create_channel_internal.h", + "src/cpp/client/create_channel_posix.cc", "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", @@ -6548,6 +6553,7 @@ "src/cpp/server/server_builder.cc", "src/cpp/server/server_context.cc", "src/cpp/server/server_credentials.cc", + "src/cpp/server/server_posix.cc", "src/cpp/server/thread_pool_interface.h", "src/cpp/util/byte_buffer.cc", "src/cpp/util/slice.cc", diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj index 660d14a07f..558a33afbd 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -263,6 +263,7 @@ + @@ -290,6 +291,7 @@ + @@ -384,6 +386,8 @@ + + @@ -414,6 +418,8 @@ + + diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters index 6cca360f9f..6b80d97e8e 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -31,6 +31,9 @@ src\cpp\client + + src\cpp\client + src\cpp\client @@ -76,6 +79,9 @@ src\cpp\server + + src\cpp\server + src\cpp\util @@ -111,6 +117,9 @@ include\grpc++ + + include\grpc++ + include\grpc++\generic @@ -192,6 +201,9 @@ include\grpc++ + + include\grpc++ + include\grpc++\support diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj index abf6efbc03..d2886e0eee 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -263,6 +263,7 @@ + @@ -290,6 +291,7 @@ + @@ -371,6 +373,8 @@ + + @@ -401,6 +405,8 @@ + + diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index 086fb5aa46..61b6f3e548 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -16,6 +16,9 @@ src\cpp\client + + src\cpp\client + src\cpp\client @@ -61,6 +64,9 @@ src\cpp\server + + src\cpp\server + src\cpp\util @@ -96,6 +102,9 @@ include\grpc++ + + include\grpc++ + include\grpc++\generic @@ -177,6 +186,9 @@ include\grpc++ + + include\grpc++ + include\grpc++\support -- cgit v1.2.3 From 4ad746e4e0077ea95d3e937a046575701592dd3f Mon Sep 17 00:00:00 2001 From: Adam Michalik Date: Tue, 7 Jun 2016 15:02:59 -0700 Subject: clang-format, fix headers, windows fixes --- include/grpc++/create_channel_posix.h | 6 ++--- include/grpc++/server_posix.h | 4 +-- include/grpc/grpc_posix.h | 1 - .../chttp2/client/insecure/channel_create_posix.c | 30 +++++++++++++--------- .../chttp2/server/insecure/server_chttp2_posix.c | 9 ++++++- src/core/ext/transport/chttp2/transport/internal.h | 2 +- src/core/ext/transport/chttp2/transport/parsing.c | 4 +-- src/core/lib/support/avl.c | 5 ++-- src/cpp/client/create_channel_posix.cc | 5 ++-- src/cpp/server/server.cc | 8 ++---- src/cpp/server/server_posix.cc | 6 ++--- test/core/end2end/fixtures/h2_fd.c | 10 +++----- test/core/statistics/census_log_tests.c | 2 +- 13 files changed, 48 insertions(+), 44 deletions(-) (limited to 'src/cpp/server') diff --git a/include/grpc++/create_channel_posix.h b/include/grpc++/create_channel_posix.h index 0ca947d044..0d96159942 100644 --- a/include/grpc++/create_channel_posix.h +++ b/include/grpc++/create_channel_posix.h @@ -36,8 +36,8 @@ #include -#include #include +#include namespace grpc { @@ -47,8 +47,8 @@ namespace grpc { /// /// \param target The name of the target. /// \param fd The file descriptor representing a socket. -std::shared_ptr CreateInsecureChannelFromFd( - const grpc::string& target, int fd); +std::shared_ptr CreateInsecureChannelFromFd(const grpc::string& target, + int fd); #endif // GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/include/grpc++/server_posix.h b/include/grpc++/server_posix.h index 1595ba6e00..e6066d4eaa 100644 --- a/include/grpc++/server_posix.h +++ b/include/grpc++/server_posix.h @@ -36,8 +36,8 @@ #include -#include #include +#include namespace grpc { @@ -53,4 +53,4 @@ void AddInsecureChannelFromFd(Server* server, int fd); } // namespace grpc -#endif // GRPCXX_CREATE_CHANNEL_POSIX_H +#endif // GRPCXX_SERVER_POSIX_H diff --git a/include/grpc/grpc_posix.h b/include/grpc/grpc_posix.h index 06cc3aad8a..cff0900620 100644 --- a/include/grpc/grpc_posix.h +++ b/include/grpc/grpc_posix.h @@ -34,7 +34,6 @@ #ifndef GRPC_GRPC_POSIX_H #define GRPC_GRPC_POSIX_H - #include #include diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c index d3e27a5963..f1c2456500 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c @@ -41,34 +41,32 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/transport/transport.h" -#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/endpoint.h" +#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/tcp_posix.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/channel.h" - +#include "src/core/lib/transport/transport.h" grpc_channel *grpc_insecure_channel_create_from_fd( const char *target, int fd, const grpc_channel_args *args) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_API_TRACE( - "grpc_insecure_channel_create(target=%p, fd=%d, args=%p)", 3, - (target, fd, args)); + GRPC_API_TRACE("grpc_insecure_channel_create(target=%p, fd=%d, args=%p)", 3, + (target, fd, args)); grpc_arg default_authority_arg; default_authority_arg.type = GRPC_ARG_STRING; default_authority_arg.key = GRPC_ARG_DEFAULT_AUTHORITY; default_authority_arg.value.string = "test.authority"; - grpc_channel_args *final_args = grpc_channel_args_copy_and_add( - args, &default_authority_arg, 1); + grpc_channel_args *final_args = + grpc_channel_args_copy_and_add(args, &default_authority_arg, 1); int flags = fcntl(fd, F_GETFL, 0); GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0); - grpc_endpoint *client = grpc_tcp_create( - grpc_fd_create(fd, "client"), GRPC_TCP_DEFAULT_READ_SLICE_SIZE, - "fd-client"); + grpc_endpoint *client = + grpc_tcp_create(grpc_fd_create(fd, "client"), + GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "fd-client"); grpc_transport *transport = grpc_create_chttp2_transport(&exec_ctx, final_args, client, 1); @@ -85,4 +83,12 @@ grpc_channel *grpc_insecure_channel_create_from_fd( "Failed to create client channel"); } -#endif // GPR_SUPPORT_CHANNELS_FROM_FD +#else // !GPR_SUPPORT_CHANNELS_FROM_FD + +grpc_channel *grpc_insecure_channel_create_from_fd( + const char *target, int fd, const grpc_channel_args *args) { + GPR_ASSERT(0); + return NULL; +} + +#endif // GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c index 11e5c45289..313e9b9208 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c @@ -66,5 +66,12 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server *server, grpc_exec_ctx_finish(&exec_ctx); } +#else // !GPR_SUPPORT_CHANNELS_FROM_FD -#endif // GPR_SUPPORT_CHANNELS_FROM_FD +void grpc_server_add_insecure_channel_from_fd(grpc_server *server, + grpc_completion_queue *cq, + int fd) { + GPR_ASSERT(0); +} + +#endif // GPR_SUPPORT_CHANNELS_FROM_FD diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 5872fd8e0a..86a31cc50b 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -691,7 +691,7 @@ extern int grpc_flowctl_trace; if (!(grpc_http_trace)) \ ; \ else \ - stmt + stmt typedef enum { GRPC_CHTTP2_FLOWCTL_MOVE, diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index 4bd374b7fa..8b6b0cebd0 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -87,8 +87,8 @@ void grpc_chttp2_prepare_to_read( transport_global->settings[GRPC_SENT_SETTINGS], sizeof(transport_parsing->last_sent_settings)); transport_parsing->max_frame_size = - transport_global->settings[GRPC_ACKED_SETTINGS] - [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE]; + transport_global + ->settings[GRPC_ACKED_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE]; /* update the parsing view of incoming window */ while (grpc_chttp2_list_pop_unannounced_incoming_window_available( diff --git a/src/core/lib/support/avl.c b/src/core/lib/support/avl.c index 8d3ce23e6c..c04675e01f 100644 --- a/src/core/lib/support/avl.c +++ b/src/core/lib/support/avl.c @@ -73,8 +73,9 @@ static long node_height(gpr_avl_node *node) { #ifndef NDEBUG static long calculate_height(gpr_avl_node *node) { - return node == NULL ? 0 : 1 + GPR_MAX(calculate_height(node->left), - calculate_height(node->right)); + return node == NULL ? 0 + : 1 + GPR_MAX(calculate_height(node->left), + calculate_height(node->right)); } static gpr_avl_node *assert_invariants(gpr_avl_node *n) { diff --git a/src/cpp/client/create_channel_posix.cc b/src/cpp/client/create_channel_posix.cc index 99ffebd392..60cfed3d62 100644 --- a/src/cpp/client/create_channel_posix.cc +++ b/src/cpp/client/create_channel_posix.cc @@ -31,7 +31,6 @@ * */ - #include #include #include @@ -44,8 +43,8 @@ namespace grpc { #ifdef GPR_SUPPORT_CHANNELS_FROM_FD -std::shared_ptr CreateInsecureChannelFromFd( - const grpc::string& target, int fd) { +std::shared_ptr CreateInsecureChannelFromFd(const grpc::string& target, + int fd) { internal::GrpcLibrary init_lib; init_lib.init(); return CreateChannelInternal( diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 72a6150e96..50fc4733a1 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -329,13 +329,9 @@ void Server::SetGlobalCallbacks(GlobalCallbacks* callbacks) { g_callbacks.reset(callbacks); } -grpc_server* Server::c_server() { - return server_; -} +grpc_server* Server::c_server() { return server_; } -CompletionQueue* Server::completion_queue() { - return &cq_; -} +CompletionQueue* Server::completion_queue() { return &cq_; } static grpc_server_register_method_payload_handling PayloadHandlingForMethod( RpcServiceMethod* method) { diff --git a/src/cpp/server/server_posix.cc b/src/cpp/server/server_posix.cc index 7ed8cd069c..8cb9753a12 100644 --- a/src/cpp/server/server_posix.cc +++ b/src/cpp/server/server_posix.cc @@ -40,12 +40,10 @@ namespace grpc { #ifdef GPR_SUPPORT_CHANNELS_FROM_FD void AddInsecureChannelFromFd(Server* server, int fd) { - grpc_server_add_insecure_channel_from_fd(server->c_server(), - server->completion_queue()->cq(), - fd); + grpc_server_add_insecure_channel_from_fd( + server->c_server(), server->completion_queue()->cq(), fd); #endif // GPR_SUPPORT_CHANNELS_FROM_FD - } } // namespace grpc diff --git a/test/core/end2end/fixtures/h2_fd.c b/test/core/end2end/fixtures/h2_fd.c index 7079080722..e938fe7730 100644 --- a/test/core/end2end/fixtures/h2_fd.c +++ b/test/core/end2end/fixtures/h2_fd.c @@ -36,18 +36,16 @@ #include #include -#include #include #include +#include #include -#include "src/core/lib/iomgr/socket_utils_posix.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/iomgr/socket_utils_posix.h" #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "test/core/util/test_config.h" -typedef struct { - int fd_pair[2]; -} sp_fixture_data; +typedef struct { int fd_pair[2]; } sp_fixture_data; static void create_sockets(int sv[2]) { int flags; @@ -62,7 +60,7 @@ static void create_sockets(int sv[2]) { static grpc_end2end_test_fixture chttp2_create_fixture_socketpair( grpc_channel_args *client_args, grpc_channel_args *server_args) { - sp_fixture_data* fixture_data = gpr_malloc(sizeof(*fixture_data)); + sp_fixture_data *fixture_data = gpr_malloc(sizeof(*fixture_data)); grpc_end2end_test_fixture f; memset(&f, 0, sizeof(f)); diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index 8646a2fdf1..4baae6a73b 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -31,7 +31,6 @@ * */ -#include "src/core/ext/census/census_log.h" #include #include #include @@ -42,6 +41,7 @@ #include #include #include +#include "src/core/ext/census/census_log.h" #include "test/core/util/test_config.h" /* Fills in 'record' of size 'size'. Each byte in record is filled in with the -- cgit v1.2.3