mirror of https://github.com/grpc/grpc.git
Merge branch 'master' of https://github.com/grpc/grpc into ruby_advanced_interop_client_side
commit
9dc0ca0a70
320 changed files with 6650 additions and 4691 deletions
@ -0,0 +1,47 @@ |
||||
bind( |
||||
name = "nanopb", |
||||
actual = "//third_party/nanopb", |
||||
) |
||||
|
||||
bind( |
||||
name = "libssl", |
||||
actual = "@submodule_boringssl//:ssl", |
||||
) |
||||
|
||||
bind( |
||||
name = "zlib", |
||||
actual = "@submodule_zlib//:z", |
||||
) |
||||
|
||||
bind( |
||||
name = "protobuf", |
||||
actual = "@submodule_protobuf//:protobuf", |
||||
) |
||||
|
||||
bind( |
||||
name = "protobuf_clib", |
||||
actual = "@submodule_protobuf//:protoc_lib", |
||||
) |
||||
|
||||
bind( |
||||
name = "protocol_compiler", |
||||
actual = "@submodule_protobuf//:protoc", |
||||
) |
||||
|
||||
new_local_repository( |
||||
name = "submodule_boringssl", |
||||
path = "third_party/boringssl-with-bazel", |
||||
build_file = "third_party/boringssl-with-bazel/BUILD", |
||||
) |
||||
|
||||
new_local_repository( |
||||
name = "submodule_zlib", |
||||
path = "third_party/zlib", |
||||
build_file = "third_party/zlib.BUILD", |
||||
) |
||||
|
||||
new_local_repository( |
||||
name = "submodule_protobuf", |
||||
path = "third_party/protobuf", |
||||
build_file = "third_party/protobuf/BUILD", |
||||
) |
@ -0,0 +1,9 @@ |
||||
package(default_visibility = ["//:__subpackages__"]) |
||||
|
||||
load(":cc_grpc_library.bzl", "cc_grpc_library") |
||||
|
||||
cc_grpc_library( |
||||
name = "well_known_protos", |
||||
srcs = "@submodule_protobuf//:well_known_protos", |
||||
proto_only = True, |
||||
) |
@ -0,0 +1,62 @@ |
||||
"""Generates and compiles C++ grpc stubs from proto_library rules.""" |
||||
|
||||
load("//:bazel/generate_cc.bzl", "generate_cc") |
||||
|
||||
def cc_grpc_library(name, srcs, deps, proto_only, **kwargs): |
||||
"""Generates C++ grpc classes from a .proto file. |
||||
|
||||
Assumes the generated classes will be used in cc_api_version = 2. |
||||
|
||||
Arguments: |
||||
name: name of rule. |
||||
srcs: a single proto_library, which wraps the .proto files with services. |
||||
deps: a list of C++ proto_library (or cc_proto_library) which provides |
||||
the compiled code of any message that the services depend on. |
||||
**kwargs: rest of arguments, e.g., compatible_with and visibility. |
||||
""" |
||||
if len(srcs) > 1: |
||||
fail("Only one srcs value supported", "srcs") |
||||
|
||||
proto_target = "_" + name + "_only" |
||||
codegen_target = "_" + name + "_codegen" |
||||
codegen_grpc_target = "_" + name + "_grpc_codegen" |
||||
proto_deps = ["_" + dep + "_only" for dep in deps if dep.find(':') == -1] |
||||
proto_deps += [dep.split(':')[0] + ':' + "_" + dep.split(':')[1] + "_only" for dep in deps if dep.find(':') != -1] |
||||
|
||||
native.proto_library( |
||||
name = proto_target, |
||||
srcs = srcs, |
||||
deps = proto_deps, |
||||
**kwargs |
||||
) |
||||
|
||||
generate_cc( |
||||
name = codegen_target, |
||||
srcs = [proto_target], |
||||
**kwargs |
||||
) |
||||
|
||||
if not proto_only: |
||||
generate_cc( |
||||
name = codegen_grpc_target, |
||||
srcs = [proto_target], |
||||
plugin = "//:grpc_cpp_plugin", |
||||
**kwargs |
||||
) |
||||
|
||||
if not proto_only: |
||||
native.cc_library( |
||||
name = name, |
||||
srcs = [":" + codegen_grpc_target, ":" + codegen_target], |
||||
hdrs = [":" + codegen_grpc_target, ":" + codegen_target], |
||||
deps = deps + ["//:grpc++", "//:grpc++_codegen_proto", "//external:protobuf"], |
||||
**kwargs |
||||
) |
||||
else: |
||||
native.cc_library( |
||||
name = name, |
||||
srcs = [":" + codegen_target], |
||||
hdrs = [":" + codegen_target], |
||||
deps = deps + ["//external:protobuf"], |
||||
**kwargs |
||||
) |
@ -0,0 +1,66 @@ |
||||
"""Generates C++ grpc stubs from proto_library rules. |
||||
|
||||
This is an internal rule used by cc_grpc_library, and shouldn't be used |
||||
directly. |
||||
""" |
||||
|
||||
def generate_cc_impl(ctx): |
||||
"""Implementation of the generate_cc rule.""" |
||||
protos = [f for src in ctx.attr.srcs for f in src.proto.direct_sources] |
||||
includes = [f for src in ctx.attr.srcs for f in src.proto.transitive_imports] |
||||
outs = [] |
||||
if ctx.executable.plugin: |
||||
outs += [proto.basename[:-len(".proto")] + ".grpc.pb.h" for proto in protos] |
||||
outs += [proto.basename[:-len(".proto")] + ".grpc.pb.cc" for proto in protos] |
||||
else: |
||||
outs += [proto.basename[:-len(".proto")] + ".pb.h" for proto in protos] |
||||
outs += [proto.basename[:-len(".proto")] + ".pb.cc" for proto in protos] |
||||
out_files = [ctx.new_file(out) for out in outs] |
||||
# The following should be replaced with ctx.configuration.buildout |
||||
# whenever this is added to Skylark. |
||||
dir_out = out_files[0].dirname[:-len(protos[0].dirname)] |
||||
|
||||
arguments = [] |
||||
if ctx.executable.plugin: |
||||
arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path] |
||||
arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] |
||||
else: |
||||
arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] |
||||
arguments += ["-I{0}={0}".format(include.path) for include in includes] |
||||
arguments += [proto.path for proto in protos] |
||||
|
||||
ctx.action( |
||||
inputs = protos + includes, |
||||
outputs = out_files, |
||||
executable = ctx.executable._protoc, |
||||
arguments = arguments, |
||||
) |
||||
|
||||
return struct(files=set(out_files)) |
||||
|
||||
generate_cc = rule( |
||||
attrs = { |
||||
"srcs": attr.label_list( |
||||
mandatory = True, |
||||
non_empty = True, |
||||
providers = ["proto"], |
||||
), |
||||
"plugin": attr.label( |
||||
executable = True, |
||||
providers = ["files_to_run"], |
||||
cfg = "host", |
||||
), |
||||
"flags": attr.string_list( |
||||
mandatory = False, |
||||
allow_empty = True, |
||||
), |
||||
"_protoc": attr.label( |
||||
default = Label("//external:protocol_compiler"), |
||||
executable = True, |
||||
cfg = "host", |
||||
), |
||||
}, |
||||
# We generate .h files, so we need to output to genfiles. |
||||
output_to_genfiles = True, |
||||
implementation = generate_cc_impl, |
||||
) |
@ -0,0 +1,68 @@ |
||||
# 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. |
||||
|
||||
# |
||||
# This is for the gRPC build system. This isn't intended to be used outsite of |
||||
# the BUILD file for gRPC. It contains the mapping for the template system we |
||||
# use to generate other platform's build system files. |
||||
# |
||||
|
||||
def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], external_deps = [], deps = [], standalone = False, language = "C++"): |
||||
copts = [] |
||||
if language.upper() == "C": |
||||
copts = ["-std=c99"] |
||||
native.cc_library( |
||||
name = name, |
||||
srcs = srcs, |
||||
hdrs = hdrs + public_hdrs, |
||||
deps = deps + ["//external:" + dep for dep in external_deps], |
||||
copts = copts, |
||||
linkopts = ["-pthread"], |
||||
includes = [ |
||||
"include" |
||||
] |
||||
) |
||||
|
||||
def grpc_proto_plugin(name, srcs = [], deps = []): |
||||
native.cc_binary( |
||||
name = name, |
||||
srcs = srcs, |
||||
deps = deps, |
||||
) |
||||
|
||||
load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library") |
||||
|
||||
def grpc_proto_library(name, srcs = [], deps = [], well_known_deps = [], has_services = True): |
||||
cc_grpc_library( |
||||
name = name, |
||||
srcs = srcs, |
||||
deps = deps, |
||||
proto_only = not has_services, |
||||
) |
||||
|
@ -0,0 +1,29 @@ |
||||
# C++ Performance Notes |
||||
|
||||
## Streaming write buffering |
||||
|
||||
Generally, each write operation (Write(), WritesDone()) implies a syscall. |
||||
gRPC will try to batch together separate write operations from different |
||||
threads, but currently cannot automatically infer batching in a single stream. |
||||
|
||||
If message k+1 in a stream does not rely on responses from message k, it's |
||||
possible to enable write batching by passing a WriteOptions argument to Write |
||||
with the buffer_hint set: |
||||
|
||||
~~~{.cpp} |
||||
stream_writer->Write(message, WriteOptions().set_buffer_hint()); |
||||
~~~ |
||||
|
||||
The write will be buffered until one of the following is true: |
||||
- the per-stream buffer is filled (controllable with the channel argument |
||||
GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE) - this prevents infinite buffering leading |
||||
to OOM |
||||
- a subsequent Write without buffer_hint set is posted |
||||
- the call is finished for writing (WritesDone() called on the client, |
||||
or Finish() called on an async server stream, or the service handler returns |
||||
for a sync server stream) |
||||
|
||||
## Completion Queues and Threading in the Async API |
||||
|
||||
Right now, the best performance trade-off is having numcpu's threads and one |
||||
completion queue per thread. |
@ -0,0 +1,41 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H |
||||
#define GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H |
||||
|
||||
/* forward declaration for exec_ctx.h */ |
||||
struct grpc_exec_ctx; |
||||
typedef struct grpc_exec_ctx grpc_exec_ctx; |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H */ |
@ -0,0 +1,5 @@ |
||||
Optional plugins for gRPC Core: Modules in this directory extend gRPC Core in |
||||
useful ways. All optional code belongs here. |
||||
|
||||
NOTE: The movement of code between lib and ext is an ongoing effort, so this |
||||
directory currently contains too much of the core library. |
@ -0,0 +1,4 @@ |
||||
# Resolver |
||||
|
||||
Implementations of various name resolution schemes. |
||||
See the [naming spec](/doc/naming.md). |
@ -0,0 +1 @@ |
||||
Transports for gRPC |
@ -0,0 +1 @@ |
||||
CHTTP2 - gRPC's implementation of a HTTP2 based transport |
@ -0,0 +1,6 @@ |
||||
Required elements of gRPC Core: Each module in this directory is required to |
||||
build gRPC. If it's possible to envisage a configuration where code is not |
||||
required, then that code belongs in ext/ instead. |
||||
|
||||
NOTE: The movement of code between lib and ext is an ongoing effort, so this |
||||
directory currently contains too much of the core library. |
@ -0,0 +1,4 @@ |
||||
# Channel |
||||
|
||||
Provides channel/call stack implementation, and implementation of common filters |
||||
for that implementation. |
@ -0,0 +1,54 @@ |
||||
/*
|
||||
* |
||||
* 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 "src/core/lib/channel/handshaker_factory.h" |
||||
|
||||
#include <grpc/support/log.h> |
||||
|
||||
void grpc_handshaker_factory_add_handshakers( |
||||
grpc_exec_ctx *exec_ctx, grpc_handshaker_factory *handshaker_factory, |
||||
const grpc_channel_args *args, grpc_handshake_manager *handshake_mgr) { |
||||
if (handshaker_factory != NULL) { |
||||
GPR_ASSERT(handshaker_factory->vtable != NULL); |
||||
handshaker_factory->vtable->add_handshakers(exec_ctx, handshaker_factory, |
||||
args, handshake_mgr); |
||||
} |
||||
} |
||||
|
||||
void grpc_handshaker_factory_destroy( |
||||
grpc_exec_ctx *exec_ctx, grpc_handshaker_factory *handshaker_factory) { |
||||
if (handshaker_factory != NULL) { |
||||
GPR_ASSERT(handshaker_factory->vtable != NULL); |
||||
handshaker_factory->vtable->destroy(exec_ctx, handshaker_factory); |
||||
} |
||||
} |
@ -0,0 +1,66 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPC_CORE_LIB_CHANNEL_HANDSHAKER_FACTORY_H |
||||
#define GRPC_CORE_LIB_CHANNEL_HANDSHAKER_FACTORY_H |
||||
|
||||
#include <grpc/impl/codegen/grpc_types.h> |
||||
|
||||
#include "src/core/lib/channel/handshaker.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
|
||||
// A handshaker factory is used to create handshakers.
|
||||
|
||||
typedef struct grpc_handshaker_factory grpc_handshaker_factory; |
||||
|
||||
typedef struct { |
||||
void (*add_handshakers)(grpc_exec_ctx *exec_ctx, |
||||
grpc_handshaker_factory *handshaker_factory, |
||||
const grpc_channel_args *args, |
||||
grpc_handshake_manager *handshake_mgr); |
||||
void (*destroy)(grpc_exec_ctx *exec_ctx, |
||||
grpc_handshaker_factory *handshaker_factory); |
||||
} grpc_handshaker_factory_vtable; |
||||
|
||||
struct grpc_handshaker_factory { |
||||
const grpc_handshaker_factory_vtable *vtable; |
||||
}; |
||||
|
||||
void grpc_handshaker_factory_add_handshakers( |
||||
grpc_exec_ctx *exec_ctx, grpc_handshaker_factory *handshaker_factory, |
||||
const grpc_channel_args *args, grpc_handshake_manager *handshake_mgr); |
||||
|
||||
void grpc_handshaker_factory_destroy( |
||||
grpc_exec_ctx *exec_ctx, grpc_handshaker_factory *handshaker_factory); |
||||
|
||||
#endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_FACTORY_H */ |
@ -0,0 +1,113 @@ |
||||
/*
|
||||
* |
||||
* 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 "src/core/lib/channel/handshaker_registry.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
|
||||
//
|
||||
// grpc_handshaker_factory_list
|
||||
//
|
||||
|
||||
typedef struct { |
||||
grpc_handshaker_factory** list; |
||||
size_t num_factories; |
||||
} grpc_handshaker_factory_list; |
||||
|
||||
static void grpc_handshaker_factory_list_register( |
||||
grpc_handshaker_factory_list* list, bool at_start, |
||||
grpc_handshaker_factory* factory) { |
||||
list->list = gpr_realloc( |
||||
list->list, (list->num_factories + 1) * sizeof(grpc_handshaker_factory*)); |
||||
if (at_start) { |
||||
memmove(list->list + 1, list->list, |
||||
sizeof(grpc_handshaker_factory*) * list->num_factories); |
||||
list->list[0] = factory; |
||||
} else { |
||||
list->list[list->num_factories] = factory; |
||||
} |
||||
++list->num_factories; |
||||
} |
||||
|
||||
static void grpc_handshaker_factory_list_add_handshakers( |
||||
grpc_exec_ctx* exec_ctx, grpc_handshaker_factory_list* list, |
||||
const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { |
||||
for (size_t i = 0; i < list->num_factories; ++i) { |
||||
grpc_handshaker_factory_add_handshakers(exec_ctx, list->list[i], args, |
||||
handshake_mgr); |
||||
} |
||||
} |
||||
|
||||
static void grpc_handshaker_factory_list_destroy( |
||||
grpc_exec_ctx* exec_ctx, grpc_handshaker_factory_list* list) { |
||||
for (size_t i = 0; i < list->num_factories; ++i) { |
||||
grpc_handshaker_factory_destroy(exec_ctx, list->list[i]); |
||||
} |
||||
gpr_free(list->list); |
||||
} |
||||
|
||||
//
|
||||
// plugin
|
||||
//
|
||||
|
||||
static grpc_handshaker_factory_list |
||||
g_handshaker_factory_lists[NUM_HANDSHAKER_TYPES]; |
||||
|
||||
void grpc_handshaker_factory_registry_init() { |
||||
memset(g_handshaker_factory_lists, 0, sizeof(g_handshaker_factory_lists)); |
||||
} |
||||
|
||||
void grpc_handshaker_factory_registry_shutdown(grpc_exec_ctx* exec_ctx) { |
||||
for (size_t i = 0; i < NUM_HANDSHAKER_TYPES; ++i) { |
||||
grpc_handshaker_factory_list_destroy(exec_ctx, |
||||
&g_handshaker_factory_lists[i]); |
||||
} |
||||
} |
||||
|
||||
void grpc_handshaker_factory_register(bool at_start, |
||||
grpc_handshaker_type handshaker_type, |
||||
grpc_handshaker_factory* factory) { |
||||
grpc_handshaker_factory_list_register( |
||||
&g_handshaker_factory_lists[handshaker_type], at_start, factory); |
||||
} |
||||
|
||||
void grpc_handshakers_add(grpc_exec_ctx* exec_ctx, |
||||
grpc_handshaker_type handshaker_type, |
||||
const grpc_channel_args* args, |
||||
grpc_handshake_manager* handshake_mgr) { |
||||
grpc_handshaker_factory_list_add_handshakers( |
||||
exec_ctx, &g_handshaker_factory_lists[handshaker_type], args, |
||||
handshake_mgr); |
||||
} |
@ -0,0 +1,63 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPC_CORE_LIB_CHANNEL_HANDSHAKER_REGISTRY_H |
||||
#define GRPC_CORE_LIB_CHANNEL_HANDSHAKER_REGISTRY_H |
||||
|
||||
#include <grpc/impl/codegen/grpc_types.h> |
||||
|
||||
#include "src/core/lib/channel/handshaker_factory.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
|
||||
typedef enum { |
||||
HANDSHAKER_CLIENT = 0, |
||||
HANDSHAKER_SERVER, |
||||
NUM_HANDSHAKER_TYPES, // Must be last.
|
||||
} grpc_handshaker_type; |
||||
|
||||
void grpc_handshaker_factory_registry_init(); |
||||
void grpc_handshaker_factory_registry_shutdown(grpc_exec_ctx* exec_ctx); |
||||
|
||||
/// Registers a new handshaker factory. Takes ownership.
|
||||
/// If \a at_start is true, the new handshaker will be at the beginning of
|
||||
/// the list. Otherwise, it will be added to the end.
|
||||
void grpc_handshaker_factory_register(bool at_start, |
||||
grpc_handshaker_type handshaker_type, |
||||
grpc_handshaker_factory* factory); |
||||
|
||||
void grpc_handshakers_add(grpc_exec_ctx* exec_ctx, |
||||
grpc_handshaker_type handshaker_type, |
||||
const grpc_channel_args* args, |
||||
grpc_handshake_manager* handshake_mgr); |
||||
|
||||
#endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_REGISTRY_H */ |
@ -0,0 +1,6 @@ |
||||
# iomgr |
||||
|
||||
Platform abstractions for I/O (mostly network). |
||||
|
||||
Provides abstractions over TCP/UDP I/O, file loading, polling, and concurrency |
||||
management for various operating systems. |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue