mirror of https://github.com/grpc/grpc.git
commit
3fcb32b757
642 changed files with 32012 additions and 24081 deletions
@ -0,0 +1,40 @@ |
||||
# Copyright 2020 The gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
"""Hello World without using protoc. |
||||
|
||||
This example parses message and service schemas directly from a |
||||
.proto file on the filesystem. |
||||
|
||||
Several APIs used in this example are in an experimental state. |
||||
""" |
||||
|
||||
from __future__ import print_function |
||||
import logging |
||||
|
||||
import grpc |
||||
import grpc.experimental |
||||
|
||||
# NOTE: The path to the .proto file must be reachable from an entry |
||||
# on sys.path. Use sys.path.insert or set the $PYTHONPATH variable to |
||||
# import from files located elsewhere on the filesystem. |
||||
|
||||
protos = grpc.protos("helloworld.proto") |
||||
services = grpc.services("helloworld.proto") |
||||
|
||||
logging.basicConfig() |
||||
|
||||
response = services.Greeter.SayHello(protos.HelloRequest(name='you'), |
||||
'localhost:50051', |
||||
insecure=True) |
||||
print("Greeter client received: " + response.message) |
@ -0,0 +1,40 @@ |
||||
# Copyright 2020 The gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
"""The Python implementation of the GRPC helloworld.Greeter server.""" |
||||
|
||||
from concurrent import futures |
||||
import logging |
||||
|
||||
import grpc |
||||
|
||||
protos, services = grpc.protos_and_services("helloworld.proto") |
||||
|
||||
|
||||
class Greeter(services.GreeterServicer): |
||||
|
||||
def SayHello(self, request, context): |
||||
return protos.HelloReply(message='Hello, %s!' % request.name) |
||||
|
||||
|
||||
def serve(): |
||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) |
||||
services.add_GreeterServicer_to_server(Greeter(), server) |
||||
server.add_insecure_port('[::]:50051') |
||||
server.start() |
||||
server.wait_for_termination() |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
logging.basicConfig() |
||||
serve() |
@ -0,0 +1,38 @@ |
||||
// Copyright 2020 The gRPC authors. |
||||
// |
||||
// Licensed under the Apache License, Version 2.0 (the "License"); |
||||
// you may not use this file except in compliance with the License. |
||||
// You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
|
||||
syntax = "proto3"; |
||||
|
||||
option java_multiple_files = true; |
||||
option java_package = "io.grpc.examples.helloworld"; |
||||
option java_outer_classname = "HelloWorldProto"; |
||||
option objc_class_prefix = "HLW"; |
||||
|
||||
package helloworld; |
||||
|
||||
// The greeting service definition. |
||||
service Greeter { |
||||
// Sends a greeting |
||||
rpc SayHello (HelloRequest) returns (HelloReply) {} |
||||
} |
||||
|
||||
// The request message containing the user's name. |
||||
message HelloRequest { |
||||
string name = 1; |
||||
} |
||||
|
||||
// The response message containing the greetings |
||||
message HelloReply { |
||||
string message = 1; |
||||
} |
@ -0,0 +1,22 @@ |
||||
# Welcome to `include/grpc/impl/codegen` |
||||
|
||||
## Why is this directory here? |
||||
|
||||
This directory exists so that generated C++ code can include selected files upon |
||||
which it depends without having to depend on the entire gRPC C++ library. This |
||||
directory thus exists to support `include/grpcpp/impl/codegen`. This constraint |
||||
is particularly relevant for users of bazel, particularly if they use the |
||||
multi-lingual `proto_library` target type. Generated code that uses this target |
||||
only depends on the gRPC C++ targets associated with these header files, not the |
||||
entire gRPC C++ codebase since that would make the build time of these types of |
||||
targets excessively large (particularly when they are not even C++ specific). |
||||
|
||||
## What should user code do? |
||||
|
||||
User code should *not* include anything from this directory. Only generated code |
||||
and gRPC library code should include contents from this directory. C++ user code |
||||
should instead include contents from the main `grpcpp` directory or its |
||||
accessible subcomponents like `grpcpp/support`. It is possible that we may |
||||
remove this directory altogether if the motivations for its existence are no |
||||
longer strong enough (e.g., if the gRPC C++ library no longer has a need for an |
||||
`impl/codegen` directory of its own). |
@ -0,0 +1,21 @@ |
||||
# Welcome to `include/grpcpp/impl/codegen` |
||||
|
||||
## Why is this directory here? |
||||
|
||||
This directory exists so that generated code can include selected files upon |
||||
which it depends without having to depend on the entire gRPC C++ library. This |
||||
is particularly relevant for users of bazel, particularly if they use the |
||||
multi-lingual `proto_library` target type. Generated code that uses this target |
||||
only depends on the gRPC C++ targets associated with these header files, not the |
||||
entire gRPC C++ codebase since that would make the build time of these types of |
||||
targets excessively large (particularly when they are not even C++ specific). |
||||
|
||||
## What should user code do? |
||||
|
||||
User code should *not* include anything from this directory. Only generated code |
||||
and gRPC library code should include contents from this directory. User code |
||||
should instead include contents from the main `grpcpp` directory or its |
||||
accessible subcomponents like `grpcpp/support`. It is possible that we may |
||||
remove this directory altogether if the motivations for its existence are no |
||||
longer strong enough (e.g., if most users migrate away from the `proto_library` |
||||
target type or if the additional overhead of depending on gRPC C++ is not high). |
@ -1,517 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
/// A ClientContext allows the person implementing a service client to:
|
||||
///
|
||||
/// - Add custom metadata key-value pairs that will propagated to the server
|
||||
/// side.
|
||||
/// - Control call settings such as compression and authentication.
|
||||
/// - Initial and trailing metadata coming from the server.
|
||||
/// - Get performance metrics (ie, census).
|
||||
///
|
||||
/// Context settings are only relevant to the call they are invoked with, that
|
||||
/// is to say, they aren't sticky. Some of these settings, such as the
|
||||
/// compression options, can be made persistent at channel construction time
|
||||
/// (see \a grpc::CreateCustomChannel).
|
||||
///
|
||||
/// \warning ClientContext instances should \em not be reused across rpcs.
|
||||
|
||||
#ifndef GRPCPP_IMPL_CODEGEN_CLIENT_CONTEXT_IMPL_H |
||||
#define GRPCPP_IMPL_CODEGEN_CLIENT_CONTEXT_IMPL_H |
||||
|
||||
#include <map> |
||||
#include <memory> |
||||
#include <string> |
||||
|
||||
#include <grpc/impl/codegen/compression_types.h> |
||||
#include <grpc/impl/codegen/propagation_bits.h> |
||||
#include <grpcpp/impl/codegen/client_interceptor.h> |
||||
#include <grpcpp/impl/codegen/config.h> |
||||
#include <grpcpp/impl/codegen/core_codegen_interface.h> |
||||
#include <grpcpp/impl/codegen/create_auth_context.h> |
||||
#include <grpcpp/impl/codegen/metadata_map.h> |
||||
#include <grpcpp/impl/codegen/rpc_method.h> |
||||
#include <grpcpp/impl/codegen/security/auth_context.h> |
||||
#include <grpcpp/impl/codegen/slice.h> |
||||
#include <grpcpp/impl/codegen/status.h> |
||||
#include <grpcpp/impl/codegen/string_ref.h> |
||||
#include <grpcpp/impl/codegen/sync.h> |
||||
#include <grpcpp/impl/codegen/time.h> |
||||
|
||||
struct census_context; |
||||
struct grpc_call; |
||||
|
||||
namespace grpc { |
||||
|
||||
class CallCredentials; |
||||
class Channel; |
||||
class ChannelInterface; |
||||
class CompletionQueue; |
||||
|
||||
namespace internal { |
||||
class RpcMethod; |
||||
template <class InputMessage, class OutputMessage> |
||||
class BlockingUnaryCallImpl; |
||||
class CallOpClientRecvStatus; |
||||
class CallOpRecvInitialMetadata; |
||||
class ServerContextImpl; |
||||
} // namespace internal
|
||||
|
||||
namespace testing { |
||||
class InteropClientContextInspector; |
||||
} // namespace testing
|
||||
} // namespace grpc
|
||||
namespace grpc_impl { |
||||
|
||||
namespace internal { |
||||
template <class InputMessage, class OutputMessage> |
||||
class CallbackUnaryCallImpl; |
||||
template <class Request, class Response> |
||||
class ClientCallbackReaderWriterImpl; |
||||
template <class Response> |
||||
class ClientCallbackReaderImpl; |
||||
template <class Request> |
||||
class ClientCallbackWriterImpl; |
||||
class ClientCallbackUnaryImpl; |
||||
class ClientContextAccessor; |
||||
} // namespace internal
|
||||
|
||||
class ServerContext; |
||||
template <class R> |
||||
class ClientReader; |
||||
template <class W> |
||||
class ClientWriter; |
||||
template <class W, class R> |
||||
class ClientReaderWriter; |
||||
template <class R> |
||||
class ClientAsyncReader; |
||||
template <class W> |
||||
class ClientAsyncWriter; |
||||
template <class W, class R> |
||||
class ClientAsyncReaderWriter; |
||||
template <class R> |
||||
class ClientAsyncResponseReader; |
||||
|
||||
class ServerContextBase; |
||||
class CallbackServerContext; |
||||
|
||||
/// Options for \a ClientContext::FromServerContext specifying which traits from
|
||||
/// the \a ServerContext to propagate (copy) from it into a new \a
|
||||
/// ClientContext.
|
||||
///
|
||||
/// \see ClientContext::FromServerContext
|
||||
class PropagationOptions { |
||||
public: |
||||
PropagationOptions() : propagate_(GRPC_PROPAGATE_DEFAULTS) {} |
||||
|
||||
PropagationOptions& enable_deadline_propagation() { |
||||
propagate_ |= GRPC_PROPAGATE_DEADLINE; |
||||
return *this; |
||||
} |
||||
|
||||
PropagationOptions& disable_deadline_propagation() { |
||||
propagate_ &= ~GRPC_PROPAGATE_DEADLINE; |
||||
return *this; |
||||
} |
||||
|
||||
PropagationOptions& enable_census_stats_propagation() { |
||||
propagate_ |= GRPC_PROPAGATE_CENSUS_STATS_CONTEXT; |
||||
return *this; |
||||
} |
||||
|
||||
PropagationOptions& disable_census_stats_propagation() { |
||||
propagate_ &= ~GRPC_PROPAGATE_CENSUS_STATS_CONTEXT; |
||||
return *this; |
||||
} |
||||
|
||||
PropagationOptions& enable_census_tracing_propagation() { |
||||
propagate_ |= GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT; |
||||
return *this; |
||||
} |
||||
|
||||
PropagationOptions& disable_census_tracing_propagation() { |
||||
propagate_ &= ~GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT; |
||||
return *this; |
||||
} |
||||
|
||||
PropagationOptions& enable_cancellation_propagation() { |
||||
propagate_ |= GRPC_PROPAGATE_CANCELLATION; |
||||
return *this; |
||||
} |
||||
|
||||
PropagationOptions& disable_cancellation_propagation() { |
||||
propagate_ &= ~GRPC_PROPAGATE_CANCELLATION; |
||||
return *this; |
||||
} |
||||
|
||||
uint32_t c_bitmask() const { return propagate_; } |
||||
|
||||
private: |
||||
uint32_t propagate_; |
||||
}; |
||||
|
||||
/// A ClientContext allows the person implementing a service client to:
|
||||
///
|
||||
/// - Add custom metadata key-value pairs that will propagated to the server
|
||||
/// side.
|
||||
/// - Control call settings such as compression and authentication.
|
||||
/// - Initial and trailing metadata coming from the server.
|
||||
/// - Get performance metrics (ie, census).
|
||||
///
|
||||
/// Context settings are only relevant to the call they are invoked with, that
|
||||
/// is to say, they aren't sticky. Some of these settings, such as the
|
||||
/// compression options, can be made persistent at channel construction time
|
||||
/// (see \a grpc::CreateCustomChannel).
|
||||
///
|
||||
/// \warning ClientContext instances should \em not be reused across rpcs.
|
||||
/// \warning The ClientContext instance used for creating an rpc must remain
|
||||
/// alive and valid for the lifetime of the rpc.
|
||||
class ClientContext { |
||||
public: |
||||
ClientContext(); |
||||
~ClientContext(); |
||||
|
||||
/// Create a new \a ClientContext as a child of an incoming server call,
|
||||
/// according to \a options (\see PropagationOptions).
|
||||
///
|
||||
/// \param server_context The source server context to use as the basis for
|
||||
/// constructing the client context.
|
||||
/// \param options The options controlling what to copy from the \a
|
||||
/// server_context.
|
||||
///
|
||||
/// \return A newly constructed \a ClientContext instance based on \a
|
||||
/// server_context, with traits propagated (copied) according to \a options.
|
||||
static std::unique_ptr<ClientContext> FromServerContext( |
||||
const grpc_impl::ServerContext& server_context, |
||||
PropagationOptions options = PropagationOptions()); |
||||
static std::unique_ptr<ClientContext> FromCallbackServerContext( |
||||
const grpc_impl::CallbackServerContext& server_context, |
||||
PropagationOptions options = PropagationOptions()); |
||||
|
||||
/// Add the (\a meta_key, \a meta_value) pair to the metadata associated with
|
||||
/// a client call. These are made available at the server side by the \a
|
||||
/// grpc::ServerContext::client_metadata() method.
|
||||
///
|
||||
/// \warning This method should only be called before invoking the rpc.
|
||||
///
|
||||
/// \param meta_key The metadata key. If \a meta_value is binary data, it must
|
||||
/// end in "-bin".
|
||||
/// \param meta_value The metadata value. If its value is binary, the key name
|
||||
/// must end in "-bin".
|
||||
///
|
||||
/// Metadata must conform to the following format:
|
||||
/// Custom-Metadata -> Binary-Header / ASCII-Header
|
||||
/// Binary-Header -> {Header-Name "-bin" } {binary value}
|
||||
/// ASCII-Header -> Header-Name ASCII-Value
|
||||
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
|
||||
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
|
||||
void AddMetadata(const std::string& meta_key, const std::string& meta_value); |
||||
|
||||
/// Return a collection of initial metadata key-value pairs. Note that keys
|
||||
/// may happen more than once (ie, a \a std::multimap is returned).
|
||||
///
|
||||
/// \warning This method should only be called after initial metadata has been
|
||||
/// received. For streaming calls, see \a
|
||||
/// ClientReaderInterface::WaitForInitialMetadata().
|
||||
///
|
||||
/// \return A multimap of initial metadata key-value pairs from the server.
|
||||
const std::multimap<grpc::string_ref, grpc::string_ref>& |
||||
GetServerInitialMetadata() const { |
||||
GPR_CODEGEN_ASSERT(initial_metadata_received_); |
||||
return *recv_initial_metadata_.map(); |
||||
} |
||||
|
||||
/// Return a collection of trailing metadata key-value pairs. Note that keys
|
||||
/// may happen more than once (ie, a \a std::multimap is returned).
|
||||
///
|
||||
/// \warning This method is only callable once the stream has finished.
|
||||
///
|
||||
/// \return A multimap of metadata trailing key-value pairs from the server.
|
||||
const std::multimap<grpc::string_ref, grpc::string_ref>& |
||||
GetServerTrailingMetadata() const { |
||||
// TODO(yangg) check finished
|
||||
return *trailing_metadata_.map(); |
||||
} |
||||
|
||||
/// Set the deadline for the client call.
|
||||
///
|
||||
/// \warning This method should only be called before invoking the rpc.
|
||||
///
|
||||
/// \param deadline the deadline for the client call. Units are determined by
|
||||
/// the type used. The deadline is an absolute (not relative) time.
|
||||
template <typename T> |
||||
void set_deadline(const T& deadline) { |
||||
grpc::TimePoint<T> deadline_tp(deadline); |
||||
deadline_ = deadline_tp.raw_time(); |
||||
} |
||||
|
||||
/// EXPERIMENTAL: Indicate that this request is idempotent.
|
||||
/// By default, RPCs are assumed to <i>not</i> be idempotent.
|
||||
///
|
||||
/// If true, the gRPC library assumes that it's safe to initiate
|
||||
/// this RPC multiple times.
|
||||
void set_idempotent(bool idempotent) { idempotent_ = idempotent; } |
||||
|
||||
/// EXPERIMENTAL: Set this request to be cacheable.
|
||||
/// If set, grpc is free to use the HTTP GET verb for sending the request,
|
||||
/// with the possibility of receiving a cached response.
|
||||
void set_cacheable(bool cacheable) { cacheable_ = cacheable; } |
||||
|
||||
/// EXPERIMENTAL: Trigger wait-for-ready or not on this request.
|
||||
/// See https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md.
|
||||
/// If set, if an RPC is made when a channel's connectivity state is
|
||||
/// TRANSIENT_FAILURE or CONNECTING, the call will not "fail fast",
|
||||
/// and the channel will wait until the channel is READY before making the
|
||||
/// call.
|
||||
void set_wait_for_ready(bool wait_for_ready) { |
||||
wait_for_ready_ = wait_for_ready; |
||||
wait_for_ready_explicitly_set_ = true; |
||||
} |
||||
|
||||
/// DEPRECATED: Use set_wait_for_ready() instead.
|
||||
void set_fail_fast(bool fail_fast) { set_wait_for_ready(!fail_fast); } |
||||
|
||||
/// Return the deadline for the client call.
|
||||
std::chrono::system_clock::time_point deadline() const { |
||||
return grpc::Timespec2Timepoint(deadline_); |
||||
} |
||||
|
||||
/// Return a \a gpr_timespec representation of the client call's deadline.
|
||||
gpr_timespec raw_deadline() const { return deadline_; } |
||||
|
||||
/// Set the per call authority header (see
|
||||
/// https://tools.ietf.org/html/rfc7540#section-8.1.2.3).
|
||||
void set_authority(const std::string& authority) { authority_ = authority; } |
||||
|
||||
/// Return the authentication context for the associated client call.
|
||||
/// It is only valid to call this during the lifetime of the client call.
|
||||
///
|
||||
/// \see grpc::AuthContext.
|
||||
std::shared_ptr<const grpc::AuthContext> auth_context() const { |
||||
if (auth_context_.get() == nullptr) { |
||||
auth_context_ = grpc::CreateAuthContext(call_); |
||||
} |
||||
return auth_context_; |
||||
} |
||||
|
||||
/// Set credentials for the client call.
|
||||
///
|
||||
/// A credentials object encapsulates all the state needed by a client to
|
||||
/// authenticate with a server and make various assertions, e.g., about the
|
||||
/// client’s identity, role, or whether it is authorized to make a particular
|
||||
/// call.
|
||||
///
|
||||
/// It is legal to call this only before initial metadata is sent.
|
||||
///
|
||||
/// \see https://grpc.io/docs/guides/auth.html
|
||||
void set_credentials(const std::shared_ptr<grpc::CallCredentials>& creds); |
||||
|
||||
/// EXPERIMENTAL debugging API
|
||||
///
|
||||
/// Returns the credentials for the client call. This should be used only in
|
||||
/// tests and for diagnostic purposes, and should not be used by application
|
||||
/// logic.
|
||||
std::shared_ptr<grpc::CallCredentials> credentials() { return creds_; } |
||||
|
||||
/// Return the compression algorithm the client call will request be used.
|
||||
/// Note that the gRPC runtime may decide to ignore this request, for example,
|
||||
/// due to resource constraints.
|
||||
grpc_compression_algorithm compression_algorithm() const { |
||||
return compression_algorithm_; |
||||
} |
||||
|
||||
/// Set \a algorithm to be the compression algorithm used for the client call.
|
||||
///
|
||||
/// \param algorithm The compression algorithm used for the client call.
|
||||
void set_compression_algorithm(grpc_compression_algorithm algorithm); |
||||
|
||||
/// Flag whether the initial metadata should be \a corked
|
||||
///
|
||||
/// If \a corked is true, then the initial metadata will be coalesced with the
|
||||
/// write of first message in the stream. As a result, any tag set for the
|
||||
/// initial metadata operation (starting a client-streaming or bidi-streaming
|
||||
/// RPC) will not actually be sent to the completion queue or delivered
|
||||
/// via Next.
|
||||
///
|
||||
/// \param corked The flag indicating whether the initial metadata is to be
|
||||
/// corked or not.
|
||||
void set_initial_metadata_corked(bool corked) { |
||||
initial_metadata_corked_ = corked; |
||||
} |
||||
|
||||
/// Return the peer uri in a string.
|
||||
/// It is only valid to call this during the lifetime of the client call.
|
||||
///
|
||||
/// \warning This value is never authenticated or subject to any security
|
||||
/// related code. It must not be used for any authentication related
|
||||
/// functionality. Instead, use auth_context.
|
||||
///
|
||||
/// \return The call's peer URI.
|
||||
std::string peer() const; |
||||
|
||||
/// Sets the census context.
|
||||
/// It is only valid to call this before the client call is created. A common
|
||||
/// place of setting census context is from within the DefaultConstructor
|
||||
/// method of GlobalCallbacks.
|
||||
void set_census_context(struct census_context* ccp) { census_context_ = ccp; } |
||||
|
||||
/// Returns the census context that has been set, or nullptr if not set.
|
||||
struct census_context* census_context() const { |
||||
return census_context_; |
||||
} |
||||
|
||||
/// Send a best-effort out-of-band cancel on the call associated with
|
||||
/// this client context. The call could be in any stage; e.g., if it is
|
||||
/// already finished, it may still return success.
|
||||
///
|
||||
/// There is no guarantee the call will be cancelled.
|
||||
///
|
||||
/// Note that TryCancel() does not change any of the tags that are pending
|
||||
/// on the completion queue. All pending tags will still be delivered
|
||||
/// (though their ok result may reflect the effect of cancellation).
|
||||
void TryCancel(); |
||||
|
||||
/// Global Callbacks
|
||||
///
|
||||
/// Can be set exactly once per application to install hooks whenever
|
||||
/// a client context is constructed and destructed.
|
||||
class GlobalCallbacks { |
||||
public: |
||||
virtual ~GlobalCallbacks() {} |
||||
virtual void DefaultConstructor(ClientContext* context) = 0; |
||||
virtual void Destructor(ClientContext* context) = 0; |
||||
}; |
||||
static void SetGlobalCallbacks(GlobalCallbacks* callbacks); |
||||
|
||||
/// Should be used for framework-level extensions only.
|
||||
/// Applications never need to call this method.
|
||||
grpc_call* c_call() { return call_; } |
||||
|
||||
/// EXPERIMENTAL debugging API
|
||||
///
|
||||
/// if status is not ok() for an RPC, this will return a detailed string
|
||||
/// of the gRPC Core error that led to the failure. It should not be relied
|
||||
/// upon for anything other than gaining more debug data in failure cases.
|
||||
std::string debug_error_string() const { return debug_error_string_; } |
||||
|
||||
private: |
||||
// Disallow copy and assign.
|
||||
ClientContext(const ClientContext&); |
||||
ClientContext& operator=(const ClientContext&); |
||||
|
||||
friend class ::grpc::testing::InteropClientContextInspector; |
||||
friend class ::grpc::internal::CallOpClientRecvStatus; |
||||
friend class ::grpc::internal::CallOpRecvInitialMetadata; |
||||
friend class ::grpc::Channel; |
||||
template <class R> |
||||
friend class ::grpc_impl::ClientReader; |
||||
template <class W> |
||||
friend class ::grpc_impl::ClientWriter; |
||||
template <class W, class R> |
||||
friend class ::grpc_impl::ClientReaderWriter; |
||||
template <class R> |
||||
friend class ::grpc_impl::ClientAsyncReader; |
||||
template <class W> |
||||
friend class ::grpc_impl::ClientAsyncWriter; |
||||
template <class W, class R> |
||||
friend class ::grpc_impl::ClientAsyncReaderWriter; |
||||
template <class R> |
||||
friend class ::grpc_impl::ClientAsyncResponseReader; |
||||
template <class InputMessage, class OutputMessage> |
||||
friend class ::grpc::internal::BlockingUnaryCallImpl; |
||||
template <class InputMessage, class OutputMessage> |
||||
friend class ::grpc_impl::internal::CallbackUnaryCallImpl; |
||||
template <class Request, class Response> |
||||
friend class ::grpc_impl::internal::ClientCallbackReaderWriterImpl; |
||||
template <class Response> |
||||
friend class ::grpc_impl::internal::ClientCallbackReaderImpl; |
||||
template <class Request> |
||||
friend class ::grpc_impl::internal::ClientCallbackWriterImpl; |
||||
friend class ::grpc_impl::internal::ClientCallbackUnaryImpl; |
||||
friend class ::grpc_impl::internal::ClientContextAccessor; |
||||
|
||||
// Used by friend class CallOpClientRecvStatus
|
||||
void set_debug_error_string(const std::string& debug_error_string) { |
||||
debug_error_string_ = debug_error_string; |
||||
} |
||||
|
||||
grpc_call* call() const { return call_; } |
||||
void set_call(grpc_call* call, |
||||
const std::shared_ptr<::grpc::Channel>& channel); |
||||
|
||||
grpc::experimental::ClientRpcInfo* set_client_rpc_info( |
||||
const char* method, grpc::internal::RpcMethod::RpcType type, |
||||
grpc::ChannelInterface* channel, |
||||
const std::vector<std::unique_ptr< |
||||
grpc::experimental::ClientInterceptorFactoryInterface>>& creators, |
||||
size_t interceptor_pos) { |
||||
rpc_info_ = grpc::experimental::ClientRpcInfo(this, type, method, channel); |
||||
rpc_info_.RegisterInterceptors(creators, interceptor_pos); |
||||
return &rpc_info_; |
||||
} |
||||
|
||||
uint32_t initial_metadata_flags() const { |
||||
return (idempotent_ ? GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST : 0) | |
||||
(wait_for_ready_ ? GRPC_INITIAL_METADATA_WAIT_FOR_READY : 0) | |
||||
(cacheable_ ? GRPC_INITIAL_METADATA_CACHEABLE_REQUEST : 0) | |
||||
(wait_for_ready_explicitly_set_ |
||||
? GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET |
||||
: 0) | |
||||
(initial_metadata_corked_ ? GRPC_INITIAL_METADATA_CORKED : 0); |
||||
} |
||||
|
||||
std::string authority() { return authority_; } |
||||
|
||||
void SendCancelToInterceptors(); |
||||
|
||||
static std::unique_ptr<ClientContext> FromInternalServerContext( |
||||
const grpc_impl::ServerContextBase& server_context, |
||||
PropagationOptions options); |
||||
|
||||
bool initial_metadata_received_; |
||||
bool wait_for_ready_; |
||||
bool wait_for_ready_explicitly_set_; |
||||
bool idempotent_; |
||||
bool cacheable_; |
||||
std::shared_ptr<::grpc::Channel> channel_; |
||||
grpc::internal::Mutex mu_; |
||||
grpc_call* call_; |
||||
bool call_canceled_; |
||||
gpr_timespec deadline_; |
||||
grpc::string authority_; |
||||
std::shared_ptr<grpc::CallCredentials> creds_; |
||||
mutable std::shared_ptr<const grpc::AuthContext> auth_context_; |
||||
struct census_context* census_context_; |
||||
std::multimap<std::string, std::string> send_initial_metadata_; |
||||
mutable grpc::internal::MetadataMap recv_initial_metadata_; |
||||
mutable grpc::internal::MetadataMap trailing_metadata_; |
||||
|
||||
grpc_call* propagate_from_call_; |
||||
PropagationOptions propagation_options_; |
||||
|
||||
grpc_compression_algorithm compression_algorithm_; |
||||
bool initial_metadata_corked_; |
||||
|
||||
std::string debug_error_string_; |
||||
|
||||
grpc::experimental::ClientRpcInfo rpc_info_; |
||||
}; |
||||
|
||||
} // namespace grpc_impl
|
||||
|
||||
#endif // GRPCPP_IMPL_CODEGEN_CLIENT_CONTEXT_IMPL_H
|
@ -1,612 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H |
||||
#define GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H |
||||
|
||||
#include <atomic> |
||||
#include <cassert> |
||||
#include <map> |
||||
#include <memory> |
||||
#include <type_traits> |
||||
#include <vector> |
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
#include <grpc/impl/codegen/compression_types.h> |
||||
#include <grpcpp/impl/codegen/call.h> |
||||
#include <grpcpp/impl/codegen/call_op_set.h> |
||||
#include <grpcpp/impl/codegen/callback_common.h> |
||||
#include <grpcpp/impl/codegen/completion_queue_tag.h> |
||||
#include <grpcpp/impl/codegen/config.h> |
||||
#include <grpcpp/impl/codegen/create_auth_context.h> |
||||
#include <grpcpp/impl/codegen/message_allocator.h> |
||||
#include <grpcpp/impl/codegen/metadata_map.h> |
||||
#include <grpcpp/impl/codegen/security/auth_context.h> |
||||
#include <grpcpp/impl/codegen/server_callback_impl.h> |
||||
#include <grpcpp/impl/codegen/server_interceptor.h> |
||||
#include <grpcpp/impl/codegen/status.h> |
||||
#include <grpcpp/impl/codegen/string_ref.h> |
||||
#include <grpcpp/impl/codegen/time.h> |
||||
|
||||
struct grpc_metadata; |
||||
struct grpc_call; |
||||
struct census_context; |
||||
|
||||
namespace grpc_impl { |
||||
class ClientContext; |
||||
class Server; |
||||
template <class W, class R> |
||||
class ServerAsyncReader; |
||||
template <class W> |
||||
class ServerAsyncWriter; |
||||
template <class W> |
||||
class ServerAsyncResponseWriter; |
||||
template <class W, class R> |
||||
class ServerAsyncReaderWriter; |
||||
template <class R> |
||||
class ServerReader; |
||||
template <class W> |
||||
class ServerWriter; |
||||
|
||||
namespace internal { |
||||
template <class ServiceType, class RequestType, class ResponseType> |
||||
class BidiStreamingHandler; |
||||
template <class RequestType, class ResponseType> |
||||
class CallbackUnaryHandler; |
||||
template <class RequestType, class ResponseType> |
||||
class CallbackClientStreamingHandler; |
||||
template <class RequestType, class ResponseType> |
||||
class CallbackServerStreamingHandler; |
||||
template <class RequestType, class ResponseType> |
||||
class CallbackBidiHandler; |
||||
template <class ServiceType, class RequestType, class ResponseType> |
||||
class ClientStreamingHandler; |
||||
template <class ServiceType, class RequestType, class ResponseType> |
||||
class RpcMethodHandler; |
||||
template <class Base> |
||||
class FinishOnlyReactor; |
||||
template <class W, class R> |
||||
class ServerReaderWriterBody; |
||||
template <class ServiceType, class RequestType, class ResponseType> |
||||
class ServerStreamingHandler; |
||||
class ServerReactor; |
||||
template <class Streamer, bool WriteNeeded> |
||||
class TemplatedBidiStreamingHandler; |
||||
template <::grpc::StatusCode code> |
||||
class ErrorMethodHandler; |
||||
} // namespace internal
|
||||
|
||||
} // namespace grpc_impl
|
||||
namespace grpc { |
||||
class CompletionQueue; |
||||
class GenericServerContext; |
||||
class ServerInterface; |
||||
|
||||
#ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL |
||||
namespace experimental { |
||||
#endif |
||||
class GenericCallbackServerContext; |
||||
#ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL |
||||
} // namespace experimental
|
||||
#endif |
||||
namespace internal { |
||||
class Call; |
||||
} // namespace internal
|
||||
|
||||
namespace testing { |
||||
class InteropServerContextInspector; |
||||
class ServerContextTestSpouse; |
||||
class DefaultReactorTestPeer; |
||||
} // namespace testing
|
||||
|
||||
} // namespace grpc
|
||||
|
||||
namespace grpc_impl { |
||||
|
||||
/// Base class of ServerContext. Experimental until callback API is final.
|
||||
class ServerContextBase { |
||||
public: |
||||
virtual ~ServerContextBase(); |
||||
|
||||
/// Return the deadline for the server call.
|
||||
std::chrono::system_clock::time_point deadline() const { |
||||
return ::grpc::Timespec2Timepoint(deadline_); |
||||
} |
||||
|
||||
/// Return a \a gpr_timespec representation of the server call's deadline.
|
||||
gpr_timespec raw_deadline() const { return deadline_; } |
||||
|
||||
/// Add the (\a key, \a value) pair to the initial metadata
|
||||
/// associated with a server call. These are made available at the client side
|
||||
/// by the \a grpc::ClientContext::GetServerInitialMetadata() method.
|
||||
///
|
||||
/// \warning This method should only be called before sending initial metadata
|
||||
/// to the client (which can happen explicitly, or implicitly when sending a
|
||||
/// a response message or status to the client).
|
||||
///
|
||||
/// \param key The metadata key. If \a value is binary data, it must
|
||||
/// end in "-bin".
|
||||
/// \param value The metadata value. If its value is binary, the key name
|
||||
/// must end in "-bin".
|
||||
///
|
||||
/// Metadata must conform to the following format:
|
||||
/// Custom-Metadata -> Binary-Header / ASCII-Header
|
||||
/// Binary-Header -> {Header-Name "-bin" } {binary value}
|
||||
/// ASCII-Header -> Header-Name ASCII-Value
|
||||
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
|
||||
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
|
||||
void AddInitialMetadata(const std::string& key, const std::string& value); |
||||
|
||||
/// Add the (\a key, \a value) pair to the initial metadata
|
||||
/// associated with a server call. These are made available at the client
|
||||
/// side by the \a grpc::ClientContext::GetServerTrailingMetadata() method.
|
||||
///
|
||||
/// \warning This method should only be called before sending trailing
|
||||
/// metadata to the client (which happens when the call is finished and a
|
||||
/// status is sent to the client).
|
||||
///
|
||||
/// \param key The metadata key. If \a value is binary data,
|
||||
/// it must end in "-bin".
|
||||
/// \param value The metadata value. If its value is binary, the key name
|
||||
/// must end in "-bin".
|
||||
///
|
||||
/// Metadata must conform to the following format:
|
||||
/// Custom-Metadata -> Binary-Header / ASCII-Header
|
||||
/// Binary-Header -> {Header-Name "-bin" } {binary value}
|
||||
/// ASCII-Header -> Header-Name ASCII-Value
|
||||
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
|
||||
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
|
||||
void AddTrailingMetadata(const std::string& key, const std::string& value); |
||||
|
||||
/// Return whether this RPC failed before the server could provide its status
|
||||
/// back to the client. This could be because of explicit API cancellation
|
||||
/// from the client-side or server-side, because of deadline exceeded, network
|
||||
/// connection reset, HTTP/2 parameter configuration (e.g., max message size,
|
||||
/// max connection age), etc. It does NOT include failure due to a non-OK
|
||||
/// status return from the server application's request handler, including
|
||||
/// Status::CANCELLED.
|
||||
///
|
||||
/// IsCancelled is always safe to call when using sync or callback API.
|
||||
/// When using async API, it is only safe to call IsCancelled after
|
||||
/// the AsyncNotifyWhenDone tag has been delivered. Thread-safe.
|
||||
bool IsCancelled() const; |
||||
|
||||
/// Cancel the Call from the server. This is a best-effort API and
|
||||
/// depending on when it is called, the RPC may still appear successful to
|
||||
/// the client. For example, if TryCancel() is called on a separate thread, it
|
||||
/// might race with the server handler which might return success to the
|
||||
/// client before TryCancel() was even started by the thread.
|
||||
///
|
||||
/// It is the caller's responsibility to prevent such races and ensure that if
|
||||
/// TryCancel() is called, the serverhandler must return Status::CANCELLED.
|
||||
/// The only exception is that if the serverhandler is already returning an
|
||||
/// error status code, it is ok to not return Status::CANCELLED even if
|
||||
/// TryCancel() was called.
|
||||
///
|
||||
/// For reasons such as the above, it is generally preferred to explicitly
|
||||
/// finish an RPC by returning Status::CANCELLED rather than using TryCancel.
|
||||
///
|
||||
/// Note that TryCancel() does not change any of the tags that are pending
|
||||
/// on the completion queue. All pending tags will still be delivered
|
||||
/// (though their ok result may reflect the effect of cancellation).
|
||||
void TryCancel() const; |
||||
|
||||
/// Return a collection of initial metadata key-value pairs sent from the
|
||||
/// client. Note that keys may happen more than
|
||||
/// once (ie, a \a std::multimap is returned).
|
||||
///
|
||||
/// It is safe to use this method after initial metadata has been received,
|
||||
/// Calls always begin with the client sending initial metadata, so this is
|
||||
/// safe to access as soon as the call has begun on the server side.
|
||||
///
|
||||
/// \return A multimap of initial metadata key-value pairs from the server.
|
||||
const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata() |
||||
const { |
||||
return *client_metadata_.map(); |
||||
} |
||||
|
||||
/// Return the compression algorithm to be used by the server call.
|
||||
grpc_compression_level compression_level() const { |
||||
return compression_level_; |
||||
} |
||||
|
||||
/// Set \a level to be the compression level used for the server call.
|
||||
///
|
||||
/// \param level The compression level used for the server call.
|
||||
void set_compression_level(grpc_compression_level level) { |
||||
compression_level_set_ = true; |
||||
compression_level_ = level; |
||||
} |
||||
|
||||
/// Return a bool indicating whether the compression level for this call
|
||||
/// has been set (either implicitly or through a previous call to
|
||||
/// \a set_compression_level.
|
||||
bool compression_level_set() const { return compression_level_set_; } |
||||
|
||||
/// Return the compression algorithm the server call will request be used.
|
||||
/// Note that the gRPC runtime may decide to ignore this request, for example,
|
||||
/// due to resource constraints, or if the server is aware the client doesn't
|
||||
/// support the requested algorithm.
|
||||
grpc_compression_algorithm compression_algorithm() const { |
||||
return compression_algorithm_; |
||||
} |
||||
/// Set \a algorithm to be the compression algorithm used for the server call.
|
||||
///
|
||||
/// \param algorithm The compression algorithm used for the server call.
|
||||
void set_compression_algorithm(grpc_compression_algorithm algorithm); |
||||
|
||||
/// Set the serialized load reporting costs in \a cost_data for the call.
|
||||
void SetLoadReportingCosts(const std::vector<std::string>& cost_data); |
||||
|
||||
/// Return the authentication context for this server call.
|
||||
///
|
||||
/// \see grpc::AuthContext.
|
||||
std::shared_ptr<const ::grpc::AuthContext> auth_context() const { |
||||
if (auth_context_.get() == nullptr) { |
||||
auth_context_ = ::grpc::CreateAuthContext(call_); |
||||
} |
||||
return auth_context_; |
||||
} |
||||
|
||||
/// Return the peer uri in a string.
|
||||
/// WARNING: this value is never authenticated or subject to any security
|
||||
/// related code. It must not be used for any authentication related
|
||||
/// functionality. Instead, use auth_context.
|
||||
std::string peer() const; |
||||
|
||||
/// Get the census context associated with this server call.
|
||||
const struct census_context* census_context() const; |
||||
|
||||
/// Should be used for framework-level extensions only.
|
||||
/// Applications never need to call this method.
|
||||
grpc_call* c_call() { return call_; } |
||||
|
||||
protected: |
||||
/// Async only. Has to be called before the rpc starts.
|
||||
/// Returns the tag in completion queue when the rpc finishes.
|
||||
/// IsCancelled() can then be called to check whether the rpc was cancelled.
|
||||
/// TODO(vjpai): Fix this so that the tag is returned even if the call never
|
||||
/// starts (https://github.com/grpc/grpc/issues/10136).
|
||||
void AsyncNotifyWhenDone(void* tag) { |
||||
has_notify_when_done_tag_ = true; |
||||
async_notify_when_done_tag_ = tag; |
||||
} |
||||
|
||||
/// NOTE: This is an API for advanced users who need custom allocators.
|
||||
/// Get and maybe mutate the allocator state associated with the current RPC.
|
||||
/// Currently only applicable for callback unary RPC methods.
|
||||
/// WARNING: This is experimental API and could be changed or removed.
|
||||
::grpc::experimental::RpcAllocatorState* GetRpcAllocatorState() { |
||||
return message_allocator_state_; |
||||
} |
||||
|
||||
/// Get a library-owned default unary reactor for use in minimal reaction
|
||||
/// cases. This supports typical unary RPC usage of providing a response and
|
||||
/// status. It supports immediate Finish (finish from within the method
|
||||
/// handler) or delayed Finish (finish called after the method handler
|
||||
/// invocation). It does not support reacting to cancellation or completion,
|
||||
/// or early sending of initial metadata. Since this is a library-owned
|
||||
/// reactor, it should not be delete'd or freed in any way. This is more
|
||||
/// efficient than creating a user-owned reactor both because of avoiding an
|
||||
/// allocation and because its minimal reactions are optimized using a core
|
||||
/// surface flag that allows their reactions to run inline without any
|
||||
/// thread-hop.
|
||||
///
|
||||
/// This method should not be called more than once or called after return
|
||||
/// from the method handler.
|
||||
///
|
||||
/// WARNING: This is experimental API and could be changed or removed.
|
||||
::grpc_impl::ServerUnaryReactor* DefaultReactor() { |
||||
// Short-circuit the case where a default reactor was already set up by
|
||||
// the TestPeer.
|
||||
if (test_unary_ != nullptr) { |
||||
return reinterpret_cast<Reactor*>(&default_reactor_); |
||||
} |
||||
new (&default_reactor_) Reactor; |
||||
#ifndef NDEBUG |
||||
bool old = false; |
||||
assert(default_reactor_used_.compare_exchange_strong( |
||||
old, true, std::memory_order_relaxed)); |
||||
#else |
||||
default_reactor_used_.store(true, std::memory_order_relaxed); |
||||
#endif |
||||
return reinterpret_cast<Reactor*>(&default_reactor_); |
||||
} |
||||
|
||||
/// Constructors for use by derived classes
|
||||
ServerContextBase(); |
||||
ServerContextBase(gpr_timespec deadline, grpc_metadata_array* arr); |
||||
|
||||
private: |
||||
friend class ::grpc::testing::InteropServerContextInspector; |
||||
friend class ::grpc::testing::ServerContextTestSpouse; |
||||
friend class ::grpc::testing::DefaultReactorTestPeer; |
||||
friend class ::grpc::ServerInterface; |
||||
friend class ::grpc_impl::Server; |
||||
template <class W, class R> |
||||
friend class ::grpc_impl::ServerAsyncReader; |
||||
template <class W> |
||||
friend class ::grpc_impl::ServerAsyncWriter; |
||||
template <class W> |
||||
friend class ::grpc_impl::ServerAsyncResponseWriter; |
||||
template <class W, class R> |
||||
friend class ::grpc_impl::ServerAsyncReaderWriter; |
||||
template <class R> |
||||
friend class ::grpc_impl::ServerReader; |
||||
template <class W> |
||||
friend class ::grpc_impl::ServerWriter; |
||||
template <class W, class R> |
||||
friend class ::grpc_impl::internal::ServerReaderWriterBody; |
||||
template <class ServiceType, class RequestType, class ResponseType> |
||||
friend class ::grpc_impl::internal::RpcMethodHandler; |
||||
template <class ServiceType, class RequestType, class ResponseType> |
||||
friend class ::grpc_impl::internal::ClientStreamingHandler; |
||||
template <class ServiceType, class RequestType, class ResponseType> |
||||
friend class ::grpc_impl::internal::ServerStreamingHandler; |
||||
template <class Streamer, bool WriteNeeded> |
||||
friend class ::grpc_impl::internal::TemplatedBidiStreamingHandler; |
||||
template <class RequestType, class ResponseType> |
||||
friend class ::grpc_impl::internal::CallbackUnaryHandler; |
||||
template <class RequestType, class ResponseType> |
||||
friend class ::grpc_impl::internal::CallbackClientStreamingHandler; |
||||
template <class RequestType, class ResponseType> |
||||
friend class ::grpc_impl::internal::CallbackServerStreamingHandler; |
||||
template <class RequestType, class ResponseType> |
||||
friend class ::grpc_impl::internal::CallbackBidiHandler; |
||||
template <::grpc::StatusCode code> |
||||
friend class ::grpc_impl::internal::ErrorMethodHandler; |
||||
template <class Base> |
||||
friend class ::grpc_impl::internal::FinishOnlyReactor; |
||||
friend class ::grpc_impl::ClientContext; |
||||
friend class ::grpc::GenericServerContext; |
||||
#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL |
||||
friend class ::grpc::GenericCallbackServerContext; |
||||
#else |
||||
friend class ::grpc::experimental::GenericCallbackServerContext; |
||||
#endif |
||||
|
||||
/// Prevent copying.
|
||||
ServerContextBase(const ServerContextBase&); |
||||
ServerContextBase& operator=(const ServerContextBase&); |
||||
|
||||
class CompletionOp; |
||||
|
||||
void BeginCompletionOp( |
||||
::grpc::internal::Call* call, std::function<void(bool)> callback, |
||||
::grpc_impl::internal::ServerCallbackCall* callback_controller); |
||||
/// Return the tag queued by BeginCompletionOp()
|
||||
::grpc::internal::CompletionQueueTag* GetCompletionOpTag(); |
||||
|
||||
void set_call(grpc_call* call) { call_ = call; } |
||||
|
||||
void BindDeadlineAndMetadata(gpr_timespec deadline, grpc_metadata_array* arr); |
||||
|
||||
void Clear(); |
||||
|
||||
void Setup(gpr_timespec deadline); |
||||
|
||||
uint32_t initial_metadata_flags() const { return 0; } |
||||
|
||||
::grpc::experimental::ServerRpcInfo* set_server_rpc_info( |
||||
const char* method, ::grpc::internal::RpcMethod::RpcType type, |
||||
const std::vector<std::unique_ptr< |
||||
::grpc::experimental::ServerInterceptorFactoryInterface>>& creators) { |
||||
if (creators.size() != 0) { |
||||
rpc_info_ = new ::grpc::experimental::ServerRpcInfo(this, method, type); |
||||
rpc_info_->RegisterInterceptors(creators); |
||||
} |
||||
return rpc_info_; |
||||
} |
||||
|
||||
void set_message_allocator_state( |
||||
::grpc::experimental::RpcAllocatorState* allocator_state) { |
||||
message_allocator_state_ = allocator_state; |
||||
} |
||||
|
||||
CompletionOp* completion_op_; |
||||
bool has_notify_when_done_tag_; |
||||
void* async_notify_when_done_tag_; |
||||
::grpc::internal::CallbackWithSuccessTag completion_tag_; |
||||
|
||||
gpr_timespec deadline_; |
||||
grpc_call* call_; |
||||
::grpc::CompletionQueue* cq_; |
||||
bool sent_initial_metadata_; |
||||
mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_; |
||||
mutable ::grpc::internal::MetadataMap client_metadata_; |
||||
std::multimap<std::string, std::string> initial_metadata_; |
||||
std::multimap<std::string, std::string> trailing_metadata_; |
||||
|
||||
bool compression_level_set_; |
||||
grpc_compression_level compression_level_; |
||||
grpc_compression_algorithm compression_algorithm_; |
||||
|
||||
::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata, |
||||
::grpc::internal::CallOpSendMessage> |
||||
pending_ops_; |
||||
bool has_pending_ops_; |
||||
|
||||
::grpc::experimental::ServerRpcInfo* rpc_info_; |
||||
::grpc::experimental::RpcAllocatorState* message_allocator_state_ = nullptr; |
||||
|
||||
class Reactor : public ServerUnaryReactor { |
||||
public: |
||||
void OnCancel() override {} |
||||
void OnDone() override {} |
||||
// Override InternalInlineable for this class since its reactions are
|
||||
// trivial and thus do not need to be run from the executor (triggering a
|
||||
// thread hop). This should only be used by internal reactors (thus the
|
||||
// name) and not by user application code.
|
||||
bool InternalInlineable() override { return true; } |
||||
}; |
||||
|
||||
void SetupTestDefaultReactor(std::function<void(::grpc::Status)> func) { |
||||
test_unary_.reset(new TestServerCallbackUnary(this, std::move(func))); |
||||
} |
||||
bool test_status_set() const { |
||||
return (test_unary_ != nullptr) && test_unary_->status_set(); |
||||
} |
||||
::grpc::Status test_status() const { return test_unary_->status(); } |
||||
|
||||
class TestServerCallbackUnary : public ::grpc_impl::ServerCallbackUnary { |
||||
public: |
||||
TestServerCallbackUnary(ServerContextBase* ctx, |
||||
std::function<void(::grpc::Status)> func) |
||||
: reactor_(ctx->DefaultReactor()), func_(std::move(func)) { |
||||
this->BindReactor(reactor_); |
||||
} |
||||
void Finish(::grpc::Status s) override { |
||||
status_ = s; |
||||
func_(std::move(s)); |
||||
status_set_.store(true, std::memory_order_release); |
||||
} |
||||
void SendInitialMetadata() override {} |
||||
|
||||
bool status_set() const { |
||||
return status_set_.load(std::memory_order_acquire); |
||||
} |
||||
::grpc::Status status() const { return status_; } |
||||
|
||||
private: |
||||
void CallOnDone() override {} |
||||
::grpc_impl::internal::ServerReactor* reactor() override { |
||||
return reactor_; |
||||
} |
||||
|
||||
::grpc_impl::ServerUnaryReactor* const reactor_; |
||||
std::atomic_bool status_set_{false}; |
||||
::grpc::Status status_; |
||||
const std::function<void(::grpc::Status s)> func_; |
||||
}; |
||||
|
||||
typename std::aligned_storage<sizeof(Reactor), alignof(Reactor)>::type |
||||
default_reactor_; |
||||
std::atomic_bool default_reactor_used_{false}; |
||||
std::unique_ptr<TestServerCallbackUnary> test_unary_; |
||||
}; |
||||
|
||||
/// A ServerContext or CallbackServerContext allows the code implementing a
|
||||
/// service handler to:
|
||||
///
|
||||
/// - Add custom initial and trailing metadata key-value pairs that will
|
||||
/// propagated to the client side.
|
||||
/// - Control call settings such as compression and authentication.
|
||||
/// - Access metadata coming from the client.
|
||||
/// - Get performance metrics (ie, census).
|
||||
///
|
||||
/// Context settings are only relevant to the call handler they are supplied to,
|
||||
/// that is to say, they aren't sticky across multiple calls. Some of these
|
||||
/// settings, such as the compression options, can be made persistent at server
|
||||
/// construction time by specifying the appropriate \a ChannelArguments
|
||||
/// to a \a grpc::ServerBuilder, via \a ServerBuilder::AddChannelArgument.
|
||||
///
|
||||
/// \warning ServerContext instances should \em not be reused across rpcs.
|
||||
class ServerContext : public ServerContextBase { |
||||
public: |
||||
ServerContext() {} // for async calls
|
||||
|
||||
using ServerContextBase::AddInitialMetadata; |
||||
using ServerContextBase::AddTrailingMetadata; |
||||
using ServerContextBase::auth_context; |
||||
using ServerContextBase::c_call; |
||||
using ServerContextBase::census_context; |
||||
using ServerContextBase::client_metadata; |
||||
using ServerContextBase::compression_algorithm; |
||||
using ServerContextBase::compression_level; |
||||
using ServerContextBase::compression_level_set; |
||||
using ServerContextBase::deadline; |
||||
using ServerContextBase::IsCancelled; |
||||
using ServerContextBase::peer; |
||||
using ServerContextBase::raw_deadline; |
||||
using ServerContextBase::set_compression_algorithm; |
||||
using ServerContextBase::set_compression_level; |
||||
using ServerContextBase::SetLoadReportingCosts; |
||||
using ServerContextBase::TryCancel; |
||||
|
||||
// Sync/CQ-based Async ServerContext only
|
||||
using ServerContextBase::AsyncNotifyWhenDone; |
||||
|
||||
private: |
||||
// Constructor for internal use by server only
|
||||
friend class ::grpc_impl::Server; |
||||
ServerContext(gpr_timespec deadline, grpc_metadata_array* arr) |
||||
: ServerContextBase(deadline, arr) {} |
||||
|
||||
// CallbackServerContext only
|
||||
using ServerContextBase::DefaultReactor; |
||||
using ServerContextBase::GetRpcAllocatorState; |
||||
|
||||
/// Prevent copying.
|
||||
ServerContext(const ServerContext&) = delete; |
||||
ServerContext& operator=(const ServerContext&) = delete; |
||||
}; |
||||
|
||||
class CallbackServerContext : public ServerContextBase { |
||||
public: |
||||
/// Public constructors are for direct use only by mocking tests. In practice,
|
||||
/// these objects will be owned by the library.
|
||||
CallbackServerContext() {} |
||||
|
||||
using ServerContextBase::AddInitialMetadata; |
||||
using ServerContextBase::AddTrailingMetadata; |
||||
using ServerContextBase::auth_context; |
||||
using ServerContextBase::c_call; |
||||
using ServerContextBase::census_context; |
||||
using ServerContextBase::client_metadata; |
||||
using ServerContextBase::compression_algorithm; |
||||
using ServerContextBase::compression_level; |
||||
using ServerContextBase::compression_level_set; |
||||
using ServerContextBase::deadline; |
||||
using ServerContextBase::IsCancelled; |
||||
using ServerContextBase::peer; |
||||
using ServerContextBase::raw_deadline; |
||||
using ServerContextBase::set_compression_algorithm; |
||||
using ServerContextBase::set_compression_level; |
||||
using ServerContextBase::SetLoadReportingCosts; |
||||
using ServerContextBase::TryCancel; |
||||
|
||||
// CallbackServerContext only
|
||||
using ServerContextBase::DefaultReactor; |
||||
using ServerContextBase::GetRpcAllocatorState; |
||||
|
||||
private: |
||||
// Sync/CQ-based Async ServerContext only
|
||||
using ServerContextBase::AsyncNotifyWhenDone; |
||||
|
||||
/// Prevent copying.
|
||||
CallbackServerContext(const CallbackServerContext&) = delete; |
||||
CallbackServerContext& operator=(const CallbackServerContext&) = delete; |
||||
}; |
||||
|
||||
} // namespace grpc_impl
|
||||
|
||||
static_assert(std::is_base_of<::grpc_impl::ServerContextBase, |
||||
::grpc_impl::ServerContext>::value, |
||||
"improper base class"); |
||||
static_assert(std::is_base_of<::grpc_impl::ServerContextBase, |
||||
::grpc_impl::CallbackServerContext>::value, |
||||
"improper base class"); |
||||
static_assert(sizeof(::grpc_impl::ServerContextBase) == |
||||
sizeof(::grpc_impl::ServerContext), |
||||
"wrong size"); |
||||
static_assert(sizeof(::grpc_impl::ServerContextBase) == |
||||
sizeof(::grpc_impl::CallbackServerContext), |
||||
"wrong size"); |
||||
|
||||
#endif // GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H
|
@ -1,388 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCPP_SERVER_IMPL_H |
||||
#define GRPCPP_SERVER_IMPL_H |
||||
|
||||
#include <list> |
||||
#include <memory> |
||||
#include <vector> |
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
#include <grpc/compression.h> |
||||
#include <grpc/support/atm.h> |
||||
#include <grpcpp/channel.h> |
||||
#include <grpcpp/completion_queue.h> |
||||
#include <grpcpp/health_check_service_interface.h> |
||||
#include <grpcpp/impl/call.h> |
||||
#include <grpcpp/impl/codegen/client_interceptor.h> |
||||
#include <grpcpp/impl/codegen/completion_queue.h> |
||||
#include <grpcpp/impl/codegen/grpc_library.h> |
||||
#include <grpcpp/impl/codegen/server_interface.h> |
||||
#include <grpcpp/impl/rpc_service_method.h> |
||||
#include <grpcpp/security/server_credentials.h> |
||||
#include <grpcpp/support/channel_arguments.h> |
||||
#include <grpcpp/support/config.h> |
||||
#include <grpcpp/support/status.h> |
||||
|
||||
struct grpc_server; |
||||
|
||||
namespace grpc { |
||||
class AsyncGenericService; |
||||
|
||||
namespace internal { |
||||
class ExternalConnectionAcceptorImpl; |
||||
} // namespace internal
|
||||
|
||||
} // namespace grpc
|
||||
|
||||
namespace grpc_impl { |
||||
class HealthCheckServiceInterface; |
||||
class ServerContext; |
||||
class ServerInitializer; |
||||
|
||||
/// Represents a gRPC server.
|
||||
///
|
||||
/// Use a \a grpc::ServerBuilder to create, configure, and start
|
||||
/// \a Server instances.
|
||||
class Server : public grpc::ServerInterface, private grpc::GrpcLibraryCodegen { |
||||
public: |
||||
~Server(); |
||||
|
||||
/// Block until the server shuts down.
|
||||
///
|
||||
/// \warning The server must be either shutting down or some other thread must
|
||||
/// call \a Shutdown for this function to ever return.
|
||||
void Wait() override; |
||||
|
||||
/// Global callbacks are a set of hooks that are called when server
|
||||
/// events occur. \a SetGlobalCallbacks method is used to register
|
||||
/// the hooks with gRPC. Note that
|
||||
/// the \a GlobalCallbacks instance will be shared among all
|
||||
/// \a Server instances in an application and can be set exactly
|
||||
/// once per application.
|
||||
class GlobalCallbacks { |
||||
public: |
||||
virtual ~GlobalCallbacks() {} |
||||
/// Called before server is created.
|
||||
virtual void UpdateArguments(grpc::ChannelArguments* /*args*/) {} |
||||
/// Called before application callback for each synchronous server request
|
||||
virtual void PreSynchronousRequest(grpc_impl::ServerContext* context) = 0; |
||||
/// Called after application callback for each synchronous server request
|
||||
virtual void PostSynchronousRequest(grpc_impl::ServerContext* context) = 0; |
||||
/// Called before server is started.
|
||||
virtual void PreServerStart(Server* /*server*/) {} |
||||
/// Called after a server port is added.
|
||||
virtual void AddPort(Server* /*server*/, const std::string& /*addr*/, |
||||
grpc::ServerCredentials* /*creds*/, int /*port*/) {} |
||||
}; |
||||
/// Set the global callback object. Can only be called once per application.
|
||||
/// Does not take ownership of callbacks, and expects the pointed to object
|
||||
/// to be alive until all server objects in the process have been destroyed.
|
||||
/// The same \a GlobalCallbacks object will be used throughout the
|
||||
/// application and is shared among all \a Server objects.
|
||||
static void SetGlobalCallbacks(GlobalCallbacks* callbacks); |
||||
|
||||
/// Returns a \em raw pointer to the underlying \a grpc_server instance.
|
||||
/// EXPERIMENTAL: for internal/test use only
|
||||
grpc_server* c_server(); |
||||
|
||||
/// Returns the health check service.
|
||||
grpc::HealthCheckServiceInterface* GetHealthCheckService() const { |
||||
return health_check_service_.get(); |
||||
} |
||||
|
||||
/// Establish a channel for in-process communication
|
||||
std::shared_ptr<grpc::Channel> InProcessChannel( |
||||
const grpc::ChannelArguments& args); |
||||
|
||||
/// NOTE: class experimental_type is not part of the public API of this class.
|
||||
/// TODO(yashykt): Integrate into public API when this is no longer
|
||||
/// experimental.
|
||||
class experimental_type { |
||||
public: |
||||
explicit experimental_type(Server* server) : server_(server) {} |
||||
|
||||
/// Establish a channel for in-process communication with client
|
||||
/// interceptors
|
||||
std::shared_ptr<grpc::Channel> InProcessChannelWithInterceptors( |
||||
const grpc::ChannelArguments& args, |
||||
std::vector<std::unique_ptr< |
||||
grpc::experimental::ClientInterceptorFactoryInterface>> |
||||
interceptor_creators); |
||||
|
||||
private: |
||||
Server* server_; |
||||
}; |
||||
|
||||
/// NOTE: The function experimental() is not stable public API. It is a view
|
||||
/// to the experimental components of this class. It may be changed or removed
|
||||
/// at any time.
|
||||
experimental_type experimental() { return experimental_type(this); } |
||||
|
||||
protected: |
||||
/// Register a service. This call does not take ownership of the service.
|
||||
/// The service must exist for the lifetime of the Server instance.
|
||||
bool RegisterService(const std::string* host, |
||||
grpc::Service* service) override; |
||||
|
||||
/// Try binding the server to the given \a addr endpoint
|
||||
/// (port, and optionally including IP address to bind to).
|
||||
///
|
||||
/// It can be invoked multiple times. Should be used before
|
||||
/// starting the server.
|
||||
///
|
||||
/// \param addr The address to try to bind to the server (eg, localhost:1234,
|
||||
/// 192.168.1.1:31416, [::1]:27182, etc.).
|
||||
/// \param creds The credentials associated with the server.
|
||||
///
|
||||
/// \return bound port number on success, 0 on failure.
|
||||
///
|
||||
/// \warning It is an error to call this method on an already started server.
|
||||
int AddListeningPort(const std::string& addr, |
||||
grpc::ServerCredentials* creds) override; |
||||
|
||||
/// NOTE: This is *NOT* a public API. The server constructors are supposed to
|
||||
/// be used by \a ServerBuilder class only. The constructor will be made
|
||||
/// 'private' very soon.
|
||||
///
|
||||
/// Server constructors. To be used by \a ServerBuilder only.
|
||||
///
|
||||
/// \param args The channel args
|
||||
///
|
||||
/// \param sync_server_cqs The completion queues to use if the server is a
|
||||
/// synchronous server (or a hybrid server). The server polls for new RPCs on
|
||||
/// these queues
|
||||
///
|
||||
/// \param min_pollers The minimum number of polling threads per server
|
||||
/// completion queue (in param sync_server_cqs) to use for listening to
|
||||
/// incoming requests (used only in case of sync server)
|
||||
///
|
||||
/// \param max_pollers The maximum number of polling threads per server
|
||||
/// completion queue (in param sync_server_cqs) to use for listening to
|
||||
/// incoming requests (used only in case of sync server)
|
||||
///
|
||||
/// \param sync_cq_timeout_msec The timeout to use when calling AsyncNext() on
|
||||
/// server completion queues passed via sync_server_cqs param.
|
||||
Server( |
||||
grpc::ChannelArguments* args, |
||||
std::shared_ptr<std::vector<std::unique_ptr<grpc::ServerCompletionQueue>>> |
||||
sync_server_cqs, |
||||
int min_pollers, int max_pollers, int sync_cq_timeout_msec, |
||||
std::vector< |
||||
std::shared_ptr<grpc::internal::ExternalConnectionAcceptorImpl>> |
||||
acceptors, |
||||
grpc_resource_quota* server_rq = nullptr, |
||||
std::vector<std::unique_ptr< |
||||
grpc::experimental::ServerInterceptorFactoryInterface>> |
||||
interceptor_creators = std::vector<std::unique_ptr< |
||||
grpc::experimental::ServerInterceptorFactoryInterface>>()); |
||||
|
||||
/// Start the server.
|
||||
///
|
||||
/// \param cqs Completion queues for handling asynchronous services. The
|
||||
/// caller is required to keep all completion queues live until the server is
|
||||
/// destroyed.
|
||||
/// \param num_cqs How many completion queues does \a cqs hold.
|
||||
void Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) override; |
||||
|
||||
grpc_server* server() override { return server_; } |
||||
|
||||
protected: |
||||
/// NOTE: This method is not part of the public API for this class.
|
||||
void set_health_check_service( |
||||
std::unique_ptr<grpc::HealthCheckServiceInterface> service) { |
||||
health_check_service_ = std::move(service); |
||||
} |
||||
|
||||
/// NOTE: This method is not part of the public API for this class.
|
||||
bool health_check_service_disabled() const { |
||||
return health_check_service_disabled_; |
||||
} |
||||
|
||||
private: |
||||
std::vector< |
||||
std::unique_ptr<grpc::experimental::ServerInterceptorFactoryInterface>>* |
||||
interceptor_creators() override { |
||||
return &interceptor_creators_; |
||||
} |
||||
|
||||
friend class grpc::AsyncGenericService; |
||||
friend class grpc::ServerBuilder; |
||||
friend class grpc_impl::ServerInitializer; |
||||
|
||||
class SyncRequest; |
||||
class CallbackRequestBase; |
||||
template <class ServerContextType> |
||||
class CallbackRequest; |
||||
class UnimplementedAsyncRequest; |
||||
class UnimplementedAsyncResponse; |
||||
|
||||
/// SyncRequestThreadManager is an implementation of ThreadManager. This class
|
||||
/// is responsible for polling for incoming RPCs and calling the RPC handlers.
|
||||
/// This is only used in case of a Sync server (i.e a server exposing a sync
|
||||
/// interface)
|
||||
class SyncRequestThreadManager; |
||||
|
||||
/// Register a generic service. This call does not take ownership of the
|
||||
/// service. The service must exist for the lifetime of the Server instance.
|
||||
void RegisterAsyncGenericService(grpc::AsyncGenericService* service) override; |
||||
|
||||
#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL |
||||
/// Register a callback-based generic service. This call does not take
|
||||
/// ownership of theservice. The service must exist for the lifetime of the
|
||||
/// Server instance.
|
||||
void RegisterCallbackGenericService( |
||||
grpc::CallbackGenericService* service) override; |
||||
#else |
||||
/// NOTE: class experimental_registration_type is not part of the public API
|
||||
/// of this class
|
||||
/// TODO(vjpai): Move these contents to the public API of Server when
|
||||
/// they are no longer experimental
|
||||
class experimental_registration_type final |
||||
: public experimental_registration_interface { |
||||
public: |
||||
explicit experimental_registration_type(Server* server) : server_(server) {} |
||||
void RegisterCallbackGenericService( |
||||
grpc::experimental::CallbackGenericService* service) override { |
||||
server_->RegisterCallbackGenericService(service); |
||||
} |
||||
|
||||
private: |
||||
Server* server_; |
||||
}; |
||||
|
||||
/// TODO(vjpai): Mark this override when experimental type above is deleted
|
||||
void RegisterCallbackGenericService( |
||||
grpc::experimental::CallbackGenericService* service); |
||||
|
||||
/// NOTE: The function experimental_registration() is not stable public API.
|
||||
/// It is a view to the experimental components of this class. It may be
|
||||
/// changed or removed at any time.
|
||||
experimental_registration_interface* experimental_registration() override { |
||||
return &experimental_registration_; |
||||
} |
||||
#endif |
||||
|
||||
void PerformOpsOnCall(grpc::internal::CallOpSetInterface* ops, |
||||
grpc::internal::Call* call) override; |
||||
|
||||
void ShutdownInternal(gpr_timespec deadline) override; |
||||
|
||||
int max_receive_message_size() const override { |
||||
return max_receive_message_size_; |
||||
} |
||||
|
||||
grpc::CompletionQueue* CallbackCQ() override; |
||||
|
||||
grpc_impl::ServerInitializer* initializer(); |
||||
|
||||
// Functions to manage the server shutdown ref count. Things that increase
|
||||
// the ref count are the running state of the server (take a ref at start and
|
||||
// drop it at shutdown) and each running callback RPC.
|
||||
void Ref(); |
||||
void UnrefWithPossibleNotify() /* LOCKS_EXCLUDED(mu_) */; |
||||
void UnrefAndWaitLocked() /* EXCLUSIVE_LOCKS_REQUIRED(mu_) */; |
||||
|
||||
std::vector<std::shared_ptr<grpc::internal::ExternalConnectionAcceptorImpl>> |
||||
acceptors_; |
||||
|
||||
// A vector of interceptor factory objects.
|
||||
// This should be destroyed after health_check_service_ and this requirement
|
||||
// is satisfied by declaring interceptor_creators_ before
|
||||
// health_check_service_. (C++ mandates that member objects be destroyed in
|
||||
// the reverse order of initialization.)
|
||||
std::vector< |
||||
std::unique_ptr<grpc::experimental::ServerInterceptorFactoryInterface>> |
||||
interceptor_creators_; |
||||
|
||||
int max_receive_message_size_; |
||||
|
||||
/// The following completion queues are ONLY used in case of Sync API
|
||||
/// i.e. if the server has any services with sync methods. The server uses
|
||||
/// these completion queues to poll for new RPCs
|
||||
std::shared_ptr<std::vector<std::unique_ptr<grpc::ServerCompletionQueue>>> |
||||
sync_server_cqs_; |
||||
|
||||
/// List of \a ThreadManager instances (one for each cq in
|
||||
/// the \a sync_server_cqs)
|
||||
std::vector<std::unique_ptr<SyncRequestThreadManager>> sync_req_mgrs_; |
||||
|
||||
#ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL |
||||
// For registering experimental callback generic service; remove when that
|
||||
// method longer experimental
|
||||
experimental_registration_type experimental_registration_{this}; |
||||
#endif |
||||
|
||||
// Server status
|
||||
grpc::internal::Mutex mu_; |
||||
bool started_; |
||||
bool shutdown_; |
||||
bool shutdown_notified_; // Was notify called on the shutdown_cv_
|
||||
grpc::internal::CondVar shutdown_done_cv_; |
||||
bool shutdown_done_ = false; |
||||
std::atomic_int shutdown_refs_outstanding_{1}; |
||||
|
||||
grpc::internal::CondVar shutdown_cv_; |
||||
|
||||
std::shared_ptr<GlobalCallbacks> global_callbacks_; |
||||
|
||||
std::vector<std::string> services_; |
||||
bool has_async_generic_service_ = false; |
||||
bool has_callback_generic_service_ = false; |
||||
bool has_callback_methods_ = false; |
||||
|
||||
// Pointer to the wrapped grpc_server.
|
||||
grpc_server* server_; |
||||
|
||||
std::unique_ptr<grpc_impl::ServerInitializer> server_initializer_; |
||||
|
||||
std::unique_ptr<grpc::HealthCheckServiceInterface> health_check_service_; |
||||
bool health_check_service_disabled_; |
||||
|
||||
// When appropriate, use a default callback generic service to handle
|
||||
// unimplemented methods
|
||||
#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL |
||||
std::unique_ptr<grpc::CallbackGenericService> unimplemented_service_; |
||||
#else |
||||
std::unique_ptr<grpc::experimental::CallbackGenericService> |
||||
unimplemented_service_; |
||||
#endif |
||||
|
||||
// A special handler for resource exhausted in sync case
|
||||
std::unique_ptr<grpc::internal::MethodHandler> resource_exhausted_handler_; |
||||
|
||||
// Handler for callback generic service, if any
|
||||
std::unique_ptr<grpc::internal::MethodHandler> generic_handler_; |
||||
|
||||
// callback_cq_ references the callbackable completion queue associated
|
||||
// with this server (if any). It is set on the first call to CallbackCQ().
|
||||
// It is _not owned_ by the server; ownership belongs with its internal
|
||||
// shutdown callback tag (invoked when the CQ is fully shutdown).
|
||||
grpc::CompletionQueue* callback_cq_ /* GUARDED_BY(mu_) */ = nullptr; |
||||
|
||||
// List of CQs passed in by user that must be Shutdown only after Server is
|
||||
// Shutdown. Even though this is only used with NDEBUG, instantiate it in all
|
||||
// cases since otherwise the size will be inconsistent.
|
||||
std::vector<grpc::CompletionQueue*> cq_list_; |
||||
}; |
||||
|
||||
} // namespace grpc_impl
|
||||
|
||||
#endif // GRPCPP_SERVER_IMPL_H
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue