修改pods

This commit is contained in:
2025-09-20 17:13:38 +08:00
parent 7787b3ee30
commit 28ff2b0264
5251 changed files with 345029 additions and 285168 deletions

View File

@@ -21,8 +21,6 @@
#ifndef GRPCPP_ALARM_H
#define GRPCPP_ALARM_H
#include <functional>
#include <grpc/event_engine/event_engine.h>
#include <grpc/grpc.h>
#include <grpcpp/completion_queue.h>
@@ -30,6 +28,8 @@
#include <grpcpp/impl/grpc_library.h>
#include <grpcpp/support/time.h>
#include <functional>
namespace grpc {
/// Trigger a \a CompletionQueue event, or asynchronous callback execution,

View File

@@ -19,8 +19,6 @@
#ifndef GRPCPP_CHANNEL_H
#define GRPCPP_CHANNEL_H
#include <memory>
#include <grpc/grpc.h>
#include <grpcpp/completion_queue.h>
#include <grpcpp/impl/call.h>
@@ -30,6 +28,8 @@
#include <grpcpp/support/client_interceptor.h>
#include <grpcpp/support/config.h>
#include <memory>
struct grpc_channel;
namespace grpc {

View File

@@ -34,13 +34,8 @@
#ifndef GRPCPP_CLIENT_CONTEXT_H
#define GRPCPP_CLIENT_CONTEXT_H
#include <map>
#include <memory>
#include <string>
#include <grpc/impl/compression_types.h>
#include <grpc/impl/propagation_bits.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/create_auth_context.h>
#include <grpcpp/impl/metadata_map.h>
#include <grpcpp/impl/rpc_method.h>
@@ -53,6 +48,12 @@
#include <grpcpp/support/string_ref.h>
#include <grpcpp/support/time.h>
#include <map>
#include <memory>
#include <string>
#include "absl/log/absl_check.h"
struct census_context;
struct grpc_call;
@@ -246,7 +247,7 @@ class ClientContext {
/// \return A multimap of initial metadata key-value pairs from the server.
const std::multimap<grpc::string_ref, grpc::string_ref>&
GetServerInitialMetadata() const {
GPR_ASSERT(initial_metadata_received_);
ABSL_CHECK(initial_metadata_received_);
return *recv_initial_metadata_.map();
}

View File

@@ -32,11 +32,8 @@
#ifndef GRPCPP_COMPLETION_QUEUE_H
#define GRPCPP_COMPLETION_QUEUE_H
#include <list>
#include <grpc/grpc.h>
#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include <grpcpp/impl/codegen/rpc_service_method.h>
#include <grpcpp/impl/codegen/status.h>
@@ -46,6 +43,10 @@
#include <grpcpp/impl/grpc_library.h>
#include <grpcpp/impl/sync.h>
#include <list>
#include "absl/log/absl_check.h"
struct grpc_completion_queue;
namespace grpc {
@@ -323,7 +324,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
bool ok = ev.success != 0;
void* ignored = tag;
if (tag->FinalizeResult(&ignored, &ok)) {
GPR_ASSERT(ignored == tag);
ABSL_CHECK(ignored == tag);
return ok;
}
}
@@ -344,7 +345,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
bool ok = ev.success != 0;
void* ignored = tag;
// the tag must be swallowed if using TryPluck
GPR_ASSERT(!tag->FinalizeResult(&ignored, &ok));
ABSL_CHECK(!tag->FinalizeResult(&ignored, &ok));
}
/// Performs a single polling pluck on \a tag. Calls tag->FinalizeResult if
@@ -361,7 +362,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
bool ok = ev.success != 0;
void* ignored = tag;
GPR_ASSERT(!tag->FinalizeResult(&ignored, &ok));
ABSL_CHECK(!tag->FinalizeResult(&ignored, &ok));
}
/// Manage state of avalanching operations : completion queue tags that

View File

@@ -19,14 +19,14 @@
#ifndef GRPCPP_CREATE_CHANNEL_H
#define GRPCPP_CREATE_CHANNEL_H
#include <memory>
#include <grpcpp/channel.h>
#include <grpcpp/security/credentials.h>
#include <grpcpp/support/channel_arguments.h>
#include <grpcpp/support/client_interceptor.h>
#include <grpcpp/support/config.h>
#include <memory>
namespace grpc {
/// Create a new \a Channel pointing to \a target.
///

View File

@@ -1,126 +0,0 @@
// Copyright 2021 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_CREATE_CHANNEL_BINDER_H
#define GRPCPP_CREATE_CHANNEL_BINDER_H
#include <grpc/support/port_platform.h>
#ifdef GPR_ANDROID
#include <jni.h>
#include <memory>
#include "absl/strings/string_view.h"
#include <grpcpp/channel.h>
#include <grpcpp/security/binder_security_policy.h>
#include <grpcpp/support/channel_arguments.h>
namespace grpc {
namespace experimental {
/// EXPERIMENTAL Create a new \a Channel based on binder transport. The package
/// name and class name will be used identify the specific application component
/// to connect to.
///
/// \param jni_env_void Pointer to a JNIEnv structure
/// \param context The context that we will use to invoke \a bindService See
/// https://developer.android.com/reference/android/content/Context#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int)
/// for detail.
/// \param package_name Package name of the component to be connected to
/// \param class_name Class name of the component to be connected to
/// \param security_policy Used for checking if remote component is allowed to
/// connect
std::shared_ptr<grpc::Channel> CreateBinderChannel(
void* jni_env_void, jobject context, absl::string_view package_name,
absl::string_view class_name,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
security_policy);
/// EXPERIMENTAL Create a new \a Channel based on binder transport. The package
/// name and class name will be used identify the specific application component
/// to connect to.
///
/// \param jni_env_void Pointer to a JNIEnv structure
/// \param context The context that we will use to invoke \a bindService See
/// https://developer.android.com/reference/android/content/Context#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int)
/// for detail.
/// \param package_name Package name of the component to be connected to
/// \param class_name Class name of the component to be connected to
/// \param security_policy Used for checking if remote component is allowed to
/// connect
/// \param args Options for channel creation.
std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
void* jni_env_void, jobject context, absl::string_view package_name,
absl::string_view class_name,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy> security_policy,
const ChannelArguments& args);
/// EXPERIMENTAL Create a new \a Channel based on binder transport.
///
/// \param jni_env_void Pointer to a JNIEnv structure
/// \param context The context that we will use to invoke \a bindService See
/// https://developer.android.com/reference/android/content/Context#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int)
/// for detail.
/// \param uri An URI that can be parsed as an `Intent` with
/// https://developer.android.com/reference/android/content/Intent#parseUri(java.lang.String,%20int)
/// \param security_policy Used for checking if remote component is allowed to
/// connect
std::shared_ptr<grpc::Channel> CreateBinderChannel(
void* jni_env_void, jobject context, absl::string_view uri,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
security_policy);
/// EXPERIMENTAL Create a new \a Channel based on binder transport.
///
/// \param jni_env_void Pointer to a JNIEnv structure
/// \param context The context that we will use to invoke \a bindService See
/// https://developer.android.com/reference/android/content/Context#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int)
/// for detail.
/// \param uri An URI that can be parsed as an `Intent` with
/// https://developer.android.com/reference/android/content/Intent#parseUri(java.lang.String,%20int)
/// \param security_policy Used for checking if remote component is allowed to
/// connect
/// \param args Options for channel creation.
std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
void* jni_env_void, jobject context, absl::string_view uri,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy> security_policy,
const ChannelArguments& args);
/// EXPERIMENTAL Finds internal binder transport Java code. To create channels
/// in threads created in native code, it is required to call this function
/// once beforehand in a thread that is not created in native code.
/// See
/// https://developer.android.com/training/articles/perf-jni#faq:-why-didnt-findclass-find-my-class
/// for details of this limitation.
/// Returns true when the initialization is successful.
bool InitializeBinderChannelJavaClass(void* jni_env_void);
/// EXPERIMENTAL Alternative version of `InitializeBinderChannelJavaClass(void*
/// jni_env_void)`. This version used a user-specified function to find the
/// required internal Java class. When a class is found, the `class_finder`
/// function should return a local reference to the class (jclass type). The
/// returned jclass will then be used to create global reference for gRPC to use
/// it later. After that, gRPC will DeleteLocalRef the returned local reference.
bool InitializeBinderChannelJavaClass(
void* jni_env_void, std::function<void*(std::string)> class_finder);
} // namespace experimental
} // namespace grpc
#endif
#endif // GRPCPP_CREATE_CHANNEL_BINDER_H

View File

@@ -20,12 +20,11 @@
#define GRPCPP_CREATE_CHANNEL_POSIX_H
#include <grpc/support/port_platform.h>
#include <memory>
#include <grpcpp/channel.h>
#include <grpcpp/support/channel_arguments.h>
#include <memory>
namespace grpc {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD

View File

@@ -19,21 +19,21 @@
#ifndef GRPCPP_EXT_CALL_METRIC_RECORDER_H
#define GRPCPP_EXT_CALL_METRIC_RECORDER_H
#include <grpcpp/impl/sync.h>
#include <grpcpp/support/slice.h>
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include <grpcpp/impl/sync.h>
#include <grpcpp/support/slice.h>
namespace grpc {
namespace experimental {
/// Records call metrics for the purpose of load balancing.
/// During an RPC, call \a ServerContext::ExperimentalGetCallMetricRecorder()
/// method to retrive the recorder for the current call.
/// method to retrieve the recorder for the current call.
class CallMetricRecorder {
public:
virtual ~CallMetricRecorder() = default;

View File

@@ -19,12 +19,12 @@
#ifndef GRPCPP_EXT_HEALTH_CHECK_SERVICE_SERVER_BUILDER_OPTION_H
#define GRPCPP_EXT_HEALTH_CHECK_SERVICE_SERVER_BUILDER_OPTION_H
#include <memory>
#include <grpcpp/health_check_service_interface.h>
#include <grpcpp/impl/server_builder_option.h>
#include <grpcpp/support/config.h>
#include <memory>
namespace grpc {
class HealthCheckServiceServerBuilderOption : public ServerBuilderOption {

View File

@@ -19,13 +19,13 @@
#ifndef GRPCPP_EXT_SERVER_METRIC_RECORDER_H
#define GRPCPP_EXT_SERVER_METRIC_RECORDER_H
#include <grpcpp/impl/sync.h>
#include <grpcpp/support/string_ref.h>
#include <functional>
#include <map>
#include <memory>
#include <grpcpp/impl/sync.h>
#include <grpcpp/support/string_ref.h>
namespace grpc_core {
struct BackendMetricData;
} // namespace grpc_core

View File

@@ -20,11 +20,9 @@
#define GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H
#include <grpc/support/port_platform.h>
#include <grpcpp/impl/server_callback_handlers.h>
#include <grpcpp/generic/callback_generic_service.h>
#include <grpcpp/support/async_stream.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/server_callback.h>
struct grpc_server;
@@ -79,57 +77,6 @@ class AsyncGenericService final {
grpc::Server* server_;
};
/// \a ServerGenericBidiReactor is the reactor class for bidi streaming RPCs
/// invoked on a CallbackGenericService. It is just a ServerBidi reactor with
/// ByteBuffer arguments.
using ServerGenericBidiReactor = ServerBidiReactor<ByteBuffer, ByteBuffer>;
class GenericCallbackServerContext final : public grpc::CallbackServerContext {
public:
const std::string& method() const { return method_; }
const std::string& host() const { return host_; }
private:
friend class grpc::Server;
std::string method_;
std::string host_;
};
/// \a CallbackGenericService is the base class for generic services implemented
/// using the callback API and registered through the ServerBuilder using
/// RegisterCallbackGenericService.
class CallbackGenericService {
public:
CallbackGenericService() {}
virtual ~CallbackGenericService() {}
/// The "method handler" for the generic API. This function should be
/// overridden to provide a ServerGenericBidiReactor that implements the
/// application-level interface for this RPC. Unimplemented by default.
virtual ServerGenericBidiReactor* CreateReactor(
GenericCallbackServerContext* /*ctx*/) {
class Reactor : public ServerGenericBidiReactor {
public:
Reactor() { this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); }
void OnDone() override { delete this; }
};
return new Reactor;
}
private:
friend class grpc::Server;
internal::CallbackBidiHandler<ByteBuffer, ByteBuffer>* Handler() {
return new internal::CallbackBidiHandler<ByteBuffer, ByteBuffer>(
[this](grpc::CallbackServerContext* ctx) {
return CreateReactor(static_cast<GenericCallbackServerContext*>(ctx));
});
}
grpc::Server* server_{nullptr};
};
} // namespace grpc
#endif // GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H

View File

@@ -0,0 +1,84 @@
//
//
// Copyright 2024 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_GENERIC_CALLBACK_GENERIC_SERVICE_H
#define GRPCPP_GENERIC_CALLBACK_GENERIC_SERVICE_H
#include <grpc/support/port_platform.h>
#include <grpcpp/impl/server_callback_handlers.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/server_callback.h>
struct grpc_server;
namespace grpc {
/// \a ServerGenericBidiReactor is the reactor class for bidi streaming RPCs
/// invoked on a CallbackGenericService. It is just a ServerBidi reactor with
/// ByteBuffer arguments.
using ServerGenericBidiReactor = ServerBidiReactor<ByteBuffer, ByteBuffer>;
class GenericCallbackServerContext final : public grpc::CallbackServerContext {
public:
const std::string& method() const { return method_; }
const std::string& host() const { return host_; }
private:
friend class grpc::Server;
std::string method_;
std::string host_;
};
/// \a CallbackGenericService is the base class for generic services implemented
/// using the callback API and registered through the ServerBuilder using
/// RegisterCallbackGenericService.
class CallbackGenericService {
public:
CallbackGenericService() {}
virtual ~CallbackGenericService() {}
/// The "method handler" for the generic API. This function should be
/// overridden to provide a ServerGenericBidiReactor that implements the
/// application-level interface for this RPC. Unimplemented by default.
virtual ServerGenericBidiReactor* CreateReactor(
GenericCallbackServerContext* /*ctx*/) {
class Reactor : public ServerGenericBidiReactor {
public:
Reactor() { this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); }
void OnDone() override { delete this; }
};
return new Reactor;
}
private:
friend class grpc::Server;
internal::CallbackBidiHandler<ByteBuffer, ByteBuffer>* Handler() {
return new internal::CallbackBidiHandler<ByteBuffer, ByteBuffer>(
[this](grpc::CallbackServerContext* ctx) {
return CreateReactor(static_cast<GenericCallbackServerContext*>(ctx));
});
}
grpc::Server* server_{nullptr};
};
} // namespace grpc
#endif // GRPCPP_GENERIC_CALLBACK_GENERIC_SERVICE_H

View File

@@ -19,15 +19,12 @@
#ifndef GRPCPP_GENERIC_GENERIC_STUB_H
#define GRPCPP_GENERIC_GENERIC_STUB_H
#include <functional>
#include <grpcpp/client_context.h>
#include <grpcpp/impl/generic_stub_internal.h>
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/async_stream.h>
#include <grpcpp/support/async_unary_call.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/client_callback.h>
#include <grpcpp/support/status.h>
#include <grpcpp/support/stub_options.h>
namespace grpc {
@@ -42,10 +39,12 @@ typedef ClientAsyncResponseReader<ByteBuffer> GenericClientAsyncResponseReader;
/// by name. In practice, the Request and Response types should be basic
/// types like grpc::ByteBuffer or proto::MessageLite (the base protobuf).
template <class RequestType, class ResponseType>
class TemplatedGenericStub final {
class TemplatedGenericStub final
: public internal::TemplatedGenericStubCallbackInternal<RequestType,
ResponseType> {
public:
explicit TemplatedGenericStub(std::shared_ptr<grpc::ChannelInterface> channel)
: channel_(channel) {}
using internal::TemplatedGenericStubCallbackInternal<
RequestType, ResponseType>::TemplatedGenericStubCallbackInternal;
/// Setup a call to a named method \a method using \a context, but don't
/// start it. Let it be started explicitly with StartCall and a tag.
@@ -74,6 +73,9 @@ class TemplatedGenericStub final {
context, request));
}
using internal::TemplatedGenericStubCallbackInternal<
RequestType, ResponseType>::PrepareUnaryCall;
/// DEPRECATED for multi-threaded use
/// Begin a call to a named method \a method using \a context.
/// A tag \a tag will be delivered to \a cq when the call has been started
@@ -87,72 +89,9 @@ class TemplatedGenericStub final {
true, tag);
}
/// Setup and start a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
void UnaryCall(ClientContext* context, const std::string& method,
StubOptions options, const RequestType* request,
ResponseType* response,
std::function<void(grpc::Status)> on_completion) {
UnaryCallInternal(context, method, options, request, response,
std::move(on_completion));
}
/// Setup a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
/// Like any other reactor-based RPC, it will not be activated until
/// StartCall is invoked on its reactor.
void PrepareUnaryCall(ClientContext* context, const std::string& method,
StubOptions options, const RequestType* request,
ResponseType* response, ClientUnaryReactor* reactor) {
PrepareUnaryCallInternal(context, method, options, request, response,
reactor);
}
/// Setup a call to a named method \a method using \a context and tied to
/// \a reactor . Like any other bidi streaming RPC, it will not be activated
/// until StartCall is invoked on its reactor.
void PrepareBidiStreamingCall(
ClientContext* context, const std::string& method, StubOptions options,
ClientBidiReactor<RequestType, ResponseType>* reactor) {
PrepareBidiStreamingCallInternal(context, method, options, reactor);
}
private:
std::shared_ptr<grpc::ChannelInterface> channel_;
void UnaryCallInternal(ClientContext* context, const std::string& method,
StubOptions options, const RequestType* request,
ResponseType* response,
std::function<void(grpc::Status)> on_completion) {
internal::CallbackUnaryCall(
channel_.get(),
grpc::internal::RpcMethod(method.c_str(), options.suffix_for_stats(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, response, std::move(on_completion));
}
void PrepareUnaryCallInternal(ClientContext* context,
const std::string& method, StubOptions options,
const RequestType* request,
ResponseType* response,
ClientUnaryReactor* reactor) {
internal::ClientCallbackUnaryFactory::Create<RequestType, ResponseType>(
channel_.get(),
grpc::internal::RpcMethod(method.c_str(), options.suffix_for_stats(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, response, reactor);
}
void PrepareBidiStreamingCallInternal(
ClientContext* context, const std::string& method, StubOptions options,
ClientBidiReactor<RequestType, ResponseType>* reactor) {
internal::ClientCallbackReaderWriterFactory<RequestType, ResponseType>::
Create(channel_.get(),
grpc::internal::RpcMethod(
method.c_str(), options.suffix_for_stats(),
grpc::internal::RpcMethod::BIDI_STREAMING),
context, reactor);
}
using internal::TemplatedGenericStubCallbackInternal<RequestType,
ResponseType>::channel_;
std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
CallInternal(grpc::ChannelInterface* channel, ClientContext* context,

View File

@@ -0,0 +1,44 @@
//
//
// Copyright 2024 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_GENERIC_GENERIC_STUB_CALLBACK_H
#define GRPCPP_GENERIC_GENERIC_STUB_CALLBACK_H
#include <grpcpp/impl/generic_stub_internal.h>
#include <grpcpp/support/byte_buffer.h>
namespace grpc {
/// Generic stubs provide a type-unaware interface to call gRPC methods
/// by name. In practice, the Request and Response types should be basic
/// types like grpc::ByteBuffer or proto::MessageLite (the base protobuf).
template <class RequestType, class ResponseType>
class TemplatedGenericStubCallback final
: public internal::TemplatedGenericStubCallbackInternal<RequestType,
ResponseType> {
public:
using internal::TemplatedGenericStubCallbackInternal<
RequestType, ResponseType>::TemplatedGenericStubCallbackInternal;
};
typedef TemplatedGenericStubCallback<grpc::ByteBuffer, grpc::ByteBuffer>
GenericStubCallback;
} // namespace grpc
#endif // GRPCPP_GENERIC_GENERIC_STUB_CALLBACK_H

View File

@@ -19,16 +19,11 @@
#ifndef GRPCPP_IMPL_CALL_OP_SET_H
#define GRPCPP_IMPL_CALL_OP_SET_H
#include <cstring>
#include <map>
#include <memory>
#include <grpc/grpc.h>
#include <grpc/impl/compression_types.h>
#include <grpc/impl/grpc_types.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpcpp/client_context.h>
#include <grpcpp/completion_queue.h>
#include <grpcpp/impl/call.h>
@@ -43,6 +38,13 @@
#include <grpcpp/support/slice.h>
#include <grpcpp/support/string_ref.h>
#include <cstring>
#include <map>
#include <memory>
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
namespace grpc {
namespace internal {
@@ -316,7 +318,7 @@ class CallOpSendMessage {
return;
}
if (msg_ != nullptr) {
GPR_ASSERT(serializer_(msg_).ok());
ABSL_CHECK(serializer_(msg_).ok());
}
serializer_ = nullptr;
grpc_op* op = &ops[(*nops)++];
@@ -769,7 +771,9 @@ class CallOpRecvInitialMetadata {
class CallOpClientRecvStatus {
public:
CallOpClientRecvStatus()
: recv_status_(nullptr), debug_error_string_(nullptr) {}
: metadata_map_(nullptr),
recv_status_(nullptr),
debug_error_string_(nullptr) {}
void ClientRecvStatus(grpc::ClientContext* context, Status* status) {
client_context_ = context;
@@ -795,7 +799,7 @@ class CallOpClientRecvStatus {
if (recv_status_ == nullptr || hijacked_) return;
if (static_cast<StatusCode>(status_code_) == StatusCode::OK) {
*recv_status_ = Status();
GPR_DEBUG_ASSERT(debug_error_string_ == nullptr);
ABSL_DCHECK_EQ(debug_error_string_, nullptr);
} else {
*recv_status_ =
Status(static_cast<StatusCode>(status_code_),
@@ -972,9 +976,9 @@ class CallOpSet : public CallOpSetInterface,
// A failure here indicates an API misuse; for example, doing a Write
// while another Write is already pending on the same RPC or invoking
// WritesDone multiple times
gpr_log(GPR_ERROR, "API misuse of type %s observed",
grpc_call_error_to_string(err));
GPR_ASSERT(false);
ABSL_LOG(ERROR) << "API misuse of type " << grpc_call_error_to_string(err)
<< " observed";
ABSL_CHECK(false);
}
}
@@ -984,7 +988,7 @@ class CallOpSet : public CallOpSetInterface,
done_intercepting_ = true;
// The following call_start_batch is internally-generated so no need for an
// explanatory log on failure.
GPR_ASSERT(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag(),
ABSL_CHECK(grpc_call_start_batch(call_.call(), nullptr, 0, core_cq_tag(),
nullptr) == GRPC_CALL_OK);
}

View File

@@ -19,12 +19,12 @@
#ifndef GRPCPP_IMPL_CHANNEL_ARGUMENT_OPTION_H
#define GRPCPP_IMPL_CHANNEL_ARGUMENT_OPTION_H
#include <map>
#include <memory>
#include <grpcpp/impl/server_builder_option.h>
#include <grpcpp/support/channel_arguments.h>
#include <map>
#include <memory>
namespace grpc {
std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption(

View File

@@ -19,11 +19,11 @@
#ifndef GRPCPP_IMPL_CREATE_AUTH_CONTEXT_H
#define GRPCPP_IMPL_CREATE_AUTH_CONTEXT_H
#include <memory>
#include <grpc/impl/grpc_types.h>
#include <grpcpp/security/auth_context.h>
#include <memory>
namespace grpc {
/// TODO(ctiller): not sure we want to make this a permanent thing

View File

@@ -19,10 +19,10 @@
#ifndef GRPCPP_IMPL_DELEGATING_CHANNEL_H
#define GRPCPP_IMPL_DELEGATING_CHANNEL_H
#include <memory>
#include <grpcpp/impl/channel_interface.h>
#include <memory>
namespace grpc {
namespace experimental {

View File

@@ -0,0 +1,93 @@
// Copyright 2024 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_GENERIC_SERIALIZE_H
#define GRPCPP_IMPL_GENERIC_SERIALIZE_H
#include <grpc/byte_buffer_reader.h>
#include <grpc/impl/grpc_types.h>
#include <grpc/slice.h>
#include <grpcpp/impl/codegen/config_protobuf.h>
#include <grpcpp/impl/serialization_traits.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/proto_buffer_reader.h>
#include <grpcpp/support/proto_buffer_writer.h>
#include <grpcpp/support/slice.h>
#include <grpcpp/support/status.h>
#include <type_traits>
#include "absl/log/absl_check.h"
/// This header provides serialization and deserialization between gRPC
/// messages serialized using protobuf and the C++ objects they represent.
namespace grpc {
// ProtoBufferWriter must be a subclass of ::protobuf::io::ZeroCopyOutputStream.
template <class ProtoBufferWriter, class T>
Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb,
bool* own_buffer) {
static_assert(std::is_base_of<protobuf::io::ZeroCopyOutputStream,
ProtoBufferWriter>::value,
"ProtoBufferWriter must be a subclass of "
"::protobuf::io::ZeroCopyOutputStream");
*own_buffer = true;
int byte_size = static_cast<int>(msg.ByteSizeLong());
if (static_cast<size_t>(byte_size) <= GRPC_SLICE_INLINED_SIZE) {
Slice slice(byte_size);
// We serialize directly into the allocated slices memory
ABSL_CHECK(slice.end() == msg.SerializeWithCachedSizesToArray(
const_cast<uint8_t*>(slice.begin())));
ByteBuffer tmp(&slice, 1);
bb->Swap(&tmp);
return grpc::Status::OK;
}
ProtoBufferWriter writer(bb, kProtoBufferWriterMaxBufferLength, byte_size);
protobuf::io::CodedOutputStream cs(&writer);
msg.SerializeWithCachedSizes(&cs);
return !cs.HadError()
? grpc::Status::OK
: Status(StatusCode::INTERNAL, "Failed to serialize message");
}
// BufferReader must be a subclass of ::protobuf::io::ZeroCopyInputStream.
template <class ProtoBufferReader, class T>
Status GenericDeserialize(ByteBuffer* buffer,
grpc::protobuf::MessageLite* msg) {
static_assert(std::is_base_of<protobuf::io::ZeroCopyInputStream,
ProtoBufferReader>::value,
"ProtoBufferReader must be a subclass of "
"::protobuf::io::ZeroCopyInputStream");
if (buffer == nullptr) {
return Status(StatusCode::INTERNAL, "No payload");
}
Status result = grpc::Status::OK;
{
ProtoBufferReader reader(buffer);
if (!reader.status().ok()) {
return reader.status();
}
if (!msg->ParseFromZeroCopyStream(&reader)) {
result = Status(StatusCode::INTERNAL, msg->InitializationErrorString());
}
}
buffer->Clear();
return result;
}
} // namespace grpc
#endif // GRPCPP_IMPL_GENERIC_SERIALIZE_H

View File

@@ -0,0 +1,125 @@
//
//
// Copyright 2024 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_GENERIC_STUB_INTERNAL_H
#define GRPCPP_IMPL_GENERIC_STUB_INTERNAL_H
#include <grpcpp/client_context.h>
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/client_callback.h>
#include <grpcpp/support/status.h>
#include <grpcpp/support/stub_options.h>
#include <functional>
namespace grpc {
template <class RequestType, class ResponseType>
class TemplatedGenericStub;
template <class RequestType, class ResponseType>
class TemplatedGenericStubCallback;
namespace internal {
/// Generic stubs provide a type-unaware interface to call gRPC methods
/// by name. In practice, the Request and Response types should be basic
/// types like grpc::ByteBuffer or proto::MessageLite (the base protobuf).
template <class RequestType, class ResponseType>
class TemplatedGenericStubCallbackInternal {
public:
explicit TemplatedGenericStubCallbackInternal(
std::shared_ptr<grpc::ChannelInterface> channel)
: channel_(channel) {}
/// Setup and start a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
void UnaryCall(ClientContext* context, const std::string& method,
StubOptions options, const RequestType* request,
ResponseType* response,
std::function<void(grpc::Status)> on_completion) {
UnaryCallInternal(context, method, options, request, response,
std::move(on_completion));
}
/// Setup a unary call to a named method \a method using
/// \a context and specifying the \a request and \a response buffers.
/// Like any other reactor-based RPC, it will not be activated until
/// StartCall is invoked on its reactor.
void PrepareUnaryCall(ClientContext* context, const std::string& method,
StubOptions options, const RequestType* request,
ResponseType* response, ClientUnaryReactor* reactor) {
PrepareUnaryCallInternal(context, method, options, request, response,
reactor);
}
/// Setup a call to a named method \a method using \a context and tied to
/// \a reactor . Like any other bidi streaming RPC, it will not be activated
/// until StartCall is invoked on its reactor.
void PrepareBidiStreamingCall(
ClientContext* context, const std::string& method, StubOptions options,
ClientBidiReactor<RequestType, ResponseType>* reactor) {
PrepareBidiStreamingCallInternal(context, method, options, reactor);
}
private:
template <class Req, class Resp>
friend class grpc::TemplatedGenericStub;
template <class Req, class Resp>
friend class grpc::TemplatedGenericStubCallback;
std::shared_ptr<grpc::ChannelInterface> channel_;
void UnaryCallInternal(ClientContext* context, const std::string& method,
StubOptions options, const RequestType* request,
ResponseType* response,
std::function<void(grpc::Status)> on_completion) {
internal::CallbackUnaryCall(
channel_.get(),
grpc::internal::RpcMethod(method.c_str(), options.suffix_for_stats(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, response, std::move(on_completion));
}
void PrepareUnaryCallInternal(ClientContext* context,
const std::string& method, StubOptions options,
const RequestType* request,
ResponseType* response,
ClientUnaryReactor* reactor) {
internal::ClientCallbackUnaryFactory::Create<RequestType, ResponseType>(
channel_.get(),
grpc::internal::RpcMethod(method.c_str(), options.suffix_for_stats(),
grpc::internal::RpcMethod::NORMAL_RPC),
context, request, response, reactor);
}
void PrepareBidiStreamingCallInternal(
ClientContext* context, const std::string& method, StubOptions options,
ClientBidiReactor<RequestType, ResponseType>* reactor) {
internal::ClientCallbackReaderWriterFactory<RequestType, ResponseType>::
Create(channel_.get(),
grpc::internal::RpcMethod(
method.c_str(), options.suffix_for_stats(),
grpc::internal::RpcMethod::BIDI_STREAMING),
context, reactor);
}
};
} // namespace internal
} // namespace grpc
#endif // GRPCPP_IMPL_GENERIC_STUB_INTERNAL_H

View File

@@ -19,11 +19,11 @@
#ifndef GRPCPP_IMPL_GRPC_LIBRARY_H
#define GRPCPP_IMPL_GRPC_LIBRARY_H
#include <iostream>
#include <grpc/grpc.h>
#include <grpcpp/impl/codegen/config.h>
#include <iostream>
namespace grpc {
namespace internal {

View File

@@ -19,17 +19,18 @@
#ifndef GRPCPP_IMPL_INTERCEPTOR_COMMON_H
#define GRPCPP_IMPL_INTERCEPTOR_COMMON_H
#include <array>
#include <functional>
#include <grpc/impl/grpc_types.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/call_op_set_interface.h>
#include <grpcpp/impl/intercepted_channel.h>
#include <grpcpp/support/client_interceptor.h>
#include <grpcpp/support/server_interceptor.h>
#include <array>
#include <functional>
#include "absl/log/absl_check.h"
namespace grpc {
namespace internal {
@@ -56,16 +57,16 @@ class InterceptorBatchMethodsImpl
if (call_->client_rpc_info() != nullptr) {
return ProceedClient();
}
GPR_ASSERT(call_->server_rpc_info() != nullptr);
ABSL_CHECK_NE(call_->server_rpc_info(), nullptr);
ProceedServer();
}
void Hijack() override {
// Only the client can hijack when sending down initial metadata
GPR_ASSERT(!reverse_ && ops_ != nullptr &&
ABSL_CHECK(!reverse_ && ops_ != nullptr &&
call_->client_rpc_info() != nullptr);
// It is illegal to call Hijack twice
GPR_ASSERT(!ran_hijacking_interceptor_);
ABSL_CHECK(!ran_hijacking_interceptor_);
auto* rpc_info = call_->client_rpc_info();
rpc_info->hijacked_ = true;
rpc_info->hijacked_interceptor_ = current_interceptor_index_;
@@ -80,21 +81,21 @@ class InterceptorBatchMethodsImpl
}
ByteBuffer* GetSerializedSendMessage() override {
GPR_ASSERT(orig_send_message_ != nullptr);
ABSL_CHECK_NE(orig_send_message_, nullptr);
if (*orig_send_message_ != nullptr) {
GPR_ASSERT(serializer_(*orig_send_message_).ok());
ABSL_CHECK(serializer_(*orig_send_message_).ok());
*orig_send_message_ = nullptr;
}
return send_message_;
}
const void* GetSendMessage() override {
GPR_ASSERT(orig_send_message_ != nullptr);
ABSL_CHECK_NE(orig_send_message_, nullptr);
return *orig_send_message_;
}
void ModifySendMessage(const void* message) override {
GPR_ASSERT(orig_send_message_ != nullptr);
ABSL_CHECK_NE(orig_send_message_, nullptr);
*orig_send_message_ = message;
}
@@ -129,7 +130,7 @@ class InterceptorBatchMethodsImpl
Status* GetRecvStatus() override { return recv_status_; }
void FailHijackedSendMessage() override {
GPR_ASSERT(hooks_[static_cast<size_t>(
ABSL_CHECK(hooks_[static_cast<size_t>(
experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)]);
*fail_send_message_ = true;
}
@@ -192,7 +193,7 @@ class InterceptorBatchMethodsImpl
}
void FailHijackedRecvMessage() override {
GPR_ASSERT(hooks_[static_cast<size_t>(
ABSL_CHECK(hooks_[static_cast<size_t>(
experimental::InterceptionHookPoints::PRE_RECV_MESSAGE)]);
*hijacked_recv_message_failed_ = true;
}
@@ -236,7 +237,7 @@ class InterceptorBatchMethodsImpl
// ContinueFinalizeOpsAfterInterception will be called. Note that neither of
// them is invoked if there were no interceptors registered.
bool RunInterceptors() {
GPR_ASSERT(ops_);
ABSL_CHECK(ops_);
auto* client_rpc_info = call_->client_rpc_info();
if (client_rpc_info != nullptr) {
if (client_rpc_info->interceptors_.empty()) {
@@ -261,8 +262,8 @@ class InterceptorBatchMethodsImpl
// SyncRequest.
bool RunInterceptors(std::function<void(void)> f) {
// This is used only by the server for initial call request
GPR_ASSERT(reverse_ == true);
GPR_ASSERT(call_->client_rpc_info() == nullptr);
ABSL_CHECK_EQ(reverse_, true);
ABSL_CHECK_EQ(call_->client_rpc_info(), nullptr);
auto* server_rpc_info = call_->server_rpc_info();
if (server_rpc_info == nullptr || server_rpc_info->interceptors_.empty()) {
return true;
@@ -356,7 +357,7 @@ class InterceptorBatchMethodsImpl
return ops_->ContinueFinalizeResultAfterInterception();
}
}
GPR_ASSERT(callback_);
ABSL_CHECK(callback_);
callback_();
}
@@ -422,112 +423,103 @@ class CancelInterceptorBatchMethods
void Hijack() override {
// Only the client can hijack when sending down initial metadata
GPR_ASSERT(false &&
"It is illegal to call Hijack on a method which has a "
"Cancel notification");
ABSL_CHECK(false) << "It is illegal to call Hijack on a method which has a "
"Cancel notification";
}
ByteBuffer* GetSerializedSendMessage() override {
GPR_ASSERT(false &&
"It is illegal to call GetSendMessage on a method which "
"has a Cancel notification");
ABSL_CHECK(false)
<< "It is illegal to call GetSendMessage on a method which "
"has a Cancel notification";
return nullptr;
}
bool GetSendMessageStatus() override {
GPR_ASSERT(false &&
"It is illegal to call GetSendMessageStatus on a method which "
"has a Cancel notification");
ABSL_CHECK(false)
<< "It is illegal to call GetSendMessageStatus on a method which "
"has a Cancel notification";
return false;
}
const void* GetSendMessage() override {
GPR_ASSERT(false &&
"It is illegal to call GetOriginalSendMessage on a method which "
"has a Cancel notification");
ABSL_CHECK(false)
<< "It is illegal to call GetOriginalSendMessage on a method which "
"has a Cancel notification";
return nullptr;
}
void ModifySendMessage(const void* /*message*/) override {
GPR_ASSERT(false &&
"It is illegal to call ModifySendMessage on a method which "
"has a Cancel notification");
ABSL_CHECK(false)
<< "It is illegal to call ModifySendMessage on a method which "
"has a Cancel notification";
}
std::multimap<std::string, std::string>* GetSendInitialMetadata() override {
GPR_ASSERT(false &&
"It is illegal to call GetSendInitialMetadata on a "
"method which has a Cancel notification");
ABSL_CHECK(false) << "It is illegal to call GetSendInitialMetadata on a "
"method which has a Cancel notification";
return nullptr;
}
Status GetSendStatus() override {
GPR_ASSERT(false &&
"It is illegal to call GetSendStatus on a method which "
"has a Cancel notification");
ABSL_CHECK(false)
<< "It is illegal to call GetSendStatus on a method which "
"has a Cancel notification";
return Status();
}
void ModifySendStatus(const Status& /*status*/) override {
GPR_ASSERT(false &&
"It is illegal to call ModifySendStatus on a method "
"which has a Cancel notification");
ABSL_CHECK(false) << "It is illegal to call ModifySendStatus on a method "
"which has a Cancel notification";
}
std::multimap<std::string, std::string>* GetSendTrailingMetadata() override {
GPR_ASSERT(false &&
"It is illegal to call GetSendTrailingMetadata on a "
"method which has a Cancel notification");
ABSL_CHECK(false) << "It is illegal to call GetSendTrailingMetadata on a "
"method which has a Cancel notification";
return nullptr;
}
void* GetRecvMessage() override {
GPR_ASSERT(false &&
"It is illegal to call GetRecvMessage on a method which "
"has a Cancel notification");
ABSL_CHECK(false)
<< "It is illegal to call GetRecvMessage on a method which "
"has a Cancel notification";
return nullptr;
}
std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata()
override {
GPR_ASSERT(false &&
"It is illegal to call GetRecvInitialMetadata on a "
"method which has a Cancel notification");
ABSL_CHECK(false) << "It is illegal to call GetRecvInitialMetadata on a "
"method which has a Cancel notification";
return nullptr;
}
Status* GetRecvStatus() override {
GPR_ASSERT(false &&
"It is illegal to call GetRecvStatus on a method which "
"has a Cancel notification");
ABSL_CHECK(false)
<< "It is illegal to call GetRecvStatus on a method which "
"has a Cancel notification";
return nullptr;
}
std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata()
override {
GPR_ASSERT(false &&
"It is illegal to call GetRecvTrailingMetadata on a "
"method which has a Cancel notification");
ABSL_CHECK(false) << "It is illegal to call GetRecvTrailingMetadata on a "
"method which has a Cancel notification";
return nullptr;
}
std::unique_ptr<ChannelInterface> GetInterceptedChannel() override {
GPR_ASSERT(false &&
"It is illegal to call GetInterceptedChannel on a "
"method which has a Cancel notification");
ABSL_CHECK(false) << "It is illegal to call GetInterceptedChannel on a "
"method which has a Cancel notification";
return std::unique_ptr<ChannelInterface>(nullptr);
}
void FailHijackedRecvMessage() override {
GPR_ASSERT(false &&
"It is illegal to call FailHijackedRecvMessage on a "
"method which has a Cancel notification");
ABSL_CHECK(false) << "It is illegal to call FailHijackedRecvMessage on a "
"method which has a Cancel notification";
}
void FailHijackedSendMessage() override {
GPR_ASSERT(false &&
"It is illegal to call FailHijackedSendMessage on a "
"method which has a Cancel notification");
ABSL_CHECK(false) << "It is illegal to call FailHijackedSendMessage on a "
"method which has a Cancel notification";
}
};
} // namespace internal

View File

@@ -19,12 +19,11 @@
#ifndef GRPCPP_IMPL_METADATA_MAP_H
#define GRPCPP_IMPL_METADATA_MAP_H
#include <map>
#include <grpc/grpc.h>
#include <grpc/support/log.h>
#include <grpcpp/support/slice.h>
#include <map>
namespace grpc {
namespace internal {

View File

@@ -19,13 +19,11 @@
#ifndef GRPCPP_IMPL_PROTO_UTILS_H
#define GRPCPP_IMPL_PROTO_UTILS_H
#include <type_traits>
#include <grpc/byte_buffer_reader.h>
#include <grpc/impl/grpc_types.h>
#include <grpc/slice.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/codegen/config_protobuf.h>
#include <grpcpp/impl/generic_serialize.h>
#include <grpcpp/impl/serialization_traits.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/proto_buffer_reader.h>
@@ -33,65 +31,13 @@
#include <grpcpp/support/slice.h>
#include <grpcpp/support/status.h>
#include <type_traits>
/// This header provides serialization and deserialization between gRPC
/// messages serialized using protobuf and the C++ objects they represent.
namespace grpc {
// ProtoBufferWriter must be a subclass of ::protobuf::io::ZeroCopyOutputStream.
template <class ProtoBufferWriter, class T>
Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb,
bool* own_buffer) {
static_assert(std::is_base_of<protobuf::io::ZeroCopyOutputStream,
ProtoBufferWriter>::value,
"ProtoBufferWriter must be a subclass of "
"::protobuf::io::ZeroCopyOutputStream");
*own_buffer = true;
int byte_size = static_cast<int>(msg.ByteSizeLong());
if (static_cast<size_t>(byte_size) <= GRPC_SLICE_INLINED_SIZE) {
Slice slice(byte_size);
// We serialize directly into the allocated slices memory
GPR_ASSERT(slice.end() == msg.SerializeWithCachedSizesToArray(
const_cast<uint8_t*>(slice.begin())));
ByteBuffer tmp(&slice, 1);
bb->Swap(&tmp);
return grpc::Status::OK;
}
ProtoBufferWriter writer(bb, kProtoBufferWriterMaxBufferLength, byte_size);
return msg.SerializeToZeroCopyStream(&writer)
? grpc::Status::OK
: Status(StatusCode::INTERNAL, "Failed to serialize message");
}
// BufferReader must be a subclass of ::protobuf::io::ZeroCopyInputStream.
template <class ProtoBufferReader, class T>
Status GenericDeserialize(ByteBuffer* buffer,
grpc::protobuf::MessageLite* msg) {
static_assert(std::is_base_of<protobuf::io::ZeroCopyInputStream,
ProtoBufferReader>::value,
"ProtoBufferReader must be a subclass of "
"::protobuf::io::ZeroCopyInputStream");
if (buffer == nullptr) {
return Status(StatusCode::INTERNAL, "No payload");
}
Status result = grpc::Status::OK;
{
ProtoBufferReader reader(buffer);
if (!reader.status().ok()) {
return reader.status();
}
if (!msg->ParseFromZeroCopyStream(&reader)) {
result = Status(StatusCode::INTERNAL, msg->InitializationErrorString());
}
}
buffer->Clear();
return result;
}
// this is needed so the following class does not conflict with protobuf
// serializers that utilize internal-only tools.
#ifdef GRPC_OPEN_SOURCE_PROTO
// This class provides a protobuf serializer. It translates between protobuf
// objects and grpc_byte_buffers. More information about SerializationTraits can
// be found in include/grpcpp/impl/codegen/serialization_traits.h.
@@ -110,7 +56,6 @@ class SerializationTraits<
return GenericDeserialize<ProtoBufferReader, T>(buffer, msg);
}
};
#endif
} // namespace grpc

View File

@@ -19,10 +19,10 @@
#ifndef GRPCPP_IMPL_RPC_METHOD_H
#define GRPCPP_IMPL_RPC_METHOD_H
#include <memory>
#include <grpcpp/impl/codegen/channel_interface.h>
#include <memory>
namespace grpc {
namespace internal {
/// Descriptor of an RPC method

View File

@@ -19,17 +19,19 @@
#ifndef GRPCPP_IMPL_RPC_SERVICE_METHOD_H
#define GRPCPP_IMPL_RPC_SERVICE_METHOD_H
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/status.h>
#include <climits>
#include <functional>
#include <map>
#include <memory>
#include <vector>
#include <grpc/support/log.h>
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/status.h>
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
namespace grpc {
class ServerContextBase;
@@ -75,7 +77,7 @@ class MethodHandler {
// retained by the handler. Returns nullptr if deserialization failed.
virtual void* Deserialize(grpc_call* /*call*/, grpc_byte_buffer* req,
Status* /*status*/, void** /*handler_data*/) {
GPR_ASSERT(req == nullptr);
ABSL_CHECK_EQ(req, nullptr);
return nullptr;
}
};
@@ -114,12 +116,12 @@ class RpcServiceMethod : public RpcMethod {
// this is not an error condition, as it allows users to declare a server
// like WithRawMethod_foo<AsyncService>. However since it
// overwrites behavior, it should be logged.
gpr_log(
GPR_INFO,
"You are marking method %s as '%s', even though it was "
"previously marked '%s'. This behavior will overwrite the original "
"behavior. If you expected this then ignore this message.",
name(), TypeToString(api_type_), TypeToString(type));
ABSL_LOG(INFO)
<< "You are marking method " << name() << " as '"
<< TypeToString(api_type_)
<< "', even though it was previously marked '" << TypeToString(type)
<< "'. This behavior will overwrite the original behavior. If "
"you expected this then ignore this message.";
}
api_type_ = type;
}

View File

@@ -19,12 +19,12 @@
#ifndef GRPCPP_IMPL_SERVER_BUILDER_OPTION_H
#define GRPCPP_IMPL_SERVER_BUILDER_OPTION_H
#include <map>
#include <memory>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/support/channel_arguments.h>
#include <map>
#include <memory>
namespace grpc {
/// Interface to pass an option to a \a ServerBuilder.

View File

@@ -19,11 +19,11 @@
#ifndef GRPCPP_IMPL_SERVER_BUILDER_PLUGIN_H
#define GRPCPP_IMPL_SERVER_BUILDER_PLUGIN_H
#include <memory>
#include <grpcpp/support/channel_arguments.h>
#include <grpcpp/support/config.h>
#include <memory>
namespace grpc {
class ServerBuilder;

View File

@@ -19,13 +19,15 @@
#define GRPCPP_IMPL_SERVER_CALLBACK_HANDLERS_H
#include <grpc/grpc.h>
#include <grpc/support/log.h>
#include <grpc/impl/call.h>
#include <grpcpp/impl/rpc_service_method.h>
#include <grpcpp/server_context.h>
#include <grpcpp/support/message_allocator.h>
#include <grpcpp/support/server_callback.h>
#include <grpcpp/support/status.h>
#include "absl/log/absl_check.h"
namespace grpc {
namespace internal {
@@ -146,7 +148,7 @@ class CallbackUnaryHandler : public grpc::internal::MethodHandler {
}
void SendInitialMetadata() override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
this->Ref();
// The callback for this function should not be marked inline because it
// is directly invoking a user-controlled reaction
@@ -186,6 +188,8 @@ class CallbackUnaryHandler : public grpc::internal::MethodHandler {
ctx_->set_message_allocator_state(allocator_state);
}
grpc_call* call() override { return call_.call(); }
/// SetupReactor binds the reactor (which also releases any queued
/// operations), maybe calls OnCancel if possible/needed, and maybe marks
/// the completion of the RPC. This should be the last component of the
@@ -332,7 +336,7 @@ class CallbackClientStreamingHandler : public grpc::internal::MethodHandler {
}
void SendInitialMetadata() override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
this->Ref();
// The callback for this function should not be inlined because it invokes
// a user-controlled reaction, but any resulting OnDone can be inlined in
@@ -370,6 +374,8 @@ class CallbackClientStreamingHandler : public grpc::internal::MethodHandler {
std::function<void()> call_requester)
: ctx_(ctx), call_(*call), call_requester_(std::move(call_requester)) {}
grpc_call* call() override { return call_.call(); }
void SetupReactor(ServerReadReactor<RequestType>* reactor) {
reactor_.store(reactor, std::memory_order_relaxed);
// The callback for this function should not be inlined because it invokes
@@ -534,7 +540,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler {
}
void SendInitialMetadata() override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
this->Ref();
// The callback for this function should not be inlined because it invokes
// a user-controlled reaction, but any resulting OnDone can be inlined in
@@ -572,7 +578,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler {
ctx_->sent_initial_metadata_ = true;
}
// TODO(vjpai): don't assert
GPR_ASSERT(write_ops_.SendMessagePtr(resp, options).ok());
ABSL_CHECK(write_ops_.SendMessagePtr(resp, options).ok());
call_.PerformOps(&write_ops_);
}
@@ -580,7 +586,7 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler {
grpc::Status s) override {
// This combines the write into the finish callback
// TODO(vjpai): don't assert
GPR_ASSERT(finish_ops_.SendMessagePtr(resp, options).ok());
ABSL_CHECK(finish_ops_.SendMessagePtr(resp, options).ok());
Finish(std::move(s));
}
@@ -595,6 +601,8 @@ class CallbackServerStreamingHandler : public grpc::internal::MethodHandler {
req_(req),
call_requester_(std::move(call_requester)) {}
grpc_call* call() override { return call_.call(); }
void SetupReactor(ServerWriteReactor<ResponseType>* reactor) {
reactor_.store(reactor, std::memory_order_relaxed);
// The callback for this function should not be inlined because it invokes
@@ -744,7 +752,7 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler {
}
void SendInitialMetadata() override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
this->Ref();
// The callback for this function should not be inlined because it invokes
// a user-controlled reaction, but any resulting OnDone can be inlined in
@@ -782,14 +790,14 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler {
ctx_->sent_initial_metadata_ = true;
}
// TODO(vjpai): don't assert
GPR_ASSERT(write_ops_.SendMessagePtr(resp, options).ok());
ABSL_CHECK(write_ops_.SendMessagePtr(resp, options).ok());
call_.PerformOps(&write_ops_);
}
void WriteAndFinish(const ResponseType* resp, grpc::WriteOptions options,
grpc::Status s) override {
// TODO(vjpai): don't assert
GPR_ASSERT(finish_ops_.SendMessagePtr(resp, options).ok());
ABSL_CHECK(finish_ops_.SendMessagePtr(resp, options).ok());
Finish(std::move(s));
}
@@ -807,6 +815,8 @@ class CallbackBidiHandler : public grpc::internal::MethodHandler {
std::function<void()> call_requester)
: ctx_(ctx), call_(*call), call_requester_(std::move(call_requester)) {}
grpc_call* call() override { return call_.call(); }
void SetupReactor(ServerBidiReactor<RequestType, ResponseType>* reactor) {
reactor_.store(reactor, std::memory_order_relaxed);
// The callbacks for these functions should not be inlined because they

View File

@@ -19,11 +19,11 @@
#ifndef GRPCPP_IMPL_SERVER_INITIALIZER_H
#define GRPCPP_IMPL_SERVER_INITIALIZER_H
#include <grpcpp/server.h>
#include <memory>
#include <vector>
#include <grpcpp/server.h>
namespace grpc {
class Server;
class Service;

View File

@@ -19,13 +19,14 @@
#ifndef GRPCPP_IMPL_SERVICE_TYPE_H
#define GRPCPP_IMPL_SERVICE_TYPE_H
#include <grpc/support/log.h>
#include <grpcpp/impl/rpc_service_method.h>
#include <grpcpp/impl/serialization_traits.h>
#include <grpcpp/server_interface.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/status.h>
#include "absl/log/absl_check.h"
namespace grpc {
class CompletionQueue;
@@ -150,9 +151,9 @@ class Service {
// This does not have to be a hard error, however no one has approached us
// with a use case yet. Please file an issue if you believe you have one.
size_t idx = static_cast<size_t>(index);
GPR_ASSERT(methods_[idx].get() != nullptr &&
"Cannot mark the method as 'async' because it has already been "
"marked as 'generic'.");
ABSL_CHECK_NE(methods_[idx].get(), nullptr)
<< "Cannot mark the method as 'async' because it has already been "
"marked as 'generic'.";
methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC);
}
@@ -160,9 +161,9 @@ class Service {
// This does not have to be a hard error, however no one has approached us
// with a use case yet. Please file an issue if you believe you have one.
size_t idx = static_cast<size_t>(index);
GPR_ASSERT(methods_[idx].get() != nullptr &&
"Cannot mark the method as 'raw' because it has already "
"been marked as 'generic'.");
ABSL_CHECK_NE(methods_[idx].get(), nullptr)
<< "Cannot mark the method as 'raw' because it has already "
"been marked as 'generic'.";
methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW);
}
@@ -170,10 +171,9 @@ class Service {
// This does not have to be a hard error, however no one has approached us
// with a use case yet. Please file an issue if you believe you have one.
size_t idx = static_cast<size_t>(index);
GPR_ASSERT(
methods_[idx]->handler() != nullptr &&
"Cannot mark the method as 'generic' because it has already been "
"marked as 'async' or 'raw'.");
ABSL_CHECK_NE(methods_[idx]->handler(), nullptr)
<< "Cannot mark the method as 'generic' because it has already been "
"marked as 'async' or 'raw'.";
methods_[idx].reset();
}
@@ -181,8 +181,8 @@ class Service {
// This does not have to be a hard error, however no one has approached us
// with a use case yet. Please file an issue if you believe you have one.
size_t idx = static_cast<size_t>(index);
GPR_ASSERT(methods_[idx] && methods_[idx]->handler() &&
"Cannot mark an async or generic method Streamed");
ABSL_CHECK(methods_[idx] && methods_[idx]->handler())
<< "Cannot mark an async or generic method Streamed";
methods_[idx]->SetHandler(streamed_method);
// From the server's point of view, streamed unary is a special
@@ -196,10 +196,9 @@ class Service {
// This does not have to be a hard error, however no one has approached us
// with a use case yet. Please file an issue if you believe you have one.
size_t idx = static_cast<size_t>(index);
GPR_ASSERT(
methods_[idx].get() != nullptr &&
"Cannot mark the method as 'callback' because it has already been "
"marked as 'generic'.");
ABSL_CHECK_NE(methods_[idx].get(), nullptr)
<< "Cannot mark the method as 'callback' because it has already been "
"marked as 'generic'.";
methods_[idx]->SetHandler(handler);
methods_[idx]->SetServerApiType(
internal::RpcServiceMethod::ApiType::CALL_BACK);
@@ -209,10 +208,9 @@ class Service {
// This does not have to be a hard error, however no one has approached us
// with a use case yet. Please file an issue if you believe you have one.
size_t idx = static_cast<size_t>(index);
GPR_ASSERT(
methods_[idx].get() != nullptr &&
"Cannot mark the method as 'raw callback' because it has already "
"been marked as 'generic'.");
ABSL_CHECK_NE(methods_[idx].get(), nullptr)
<< "Cannot mark the method as 'raw callback' because it has already "
"been marked as 'generic'.";
methods_[idx]->SetHandler(handler);
methods_[idx]->SetServerApiType(
internal::RpcServiceMethod::ApiType::RAW_CALL_BACK);

View File

@@ -21,9 +21,8 @@
// IWYU pragma: private, include <grpcpp/support/status.h>
#include <grpc/support/port_platform.h>
#include <grpc/status.h>
#include <grpc/support/port_platform.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/status_code_enum.h>

View File

@@ -25,20 +25,20 @@
#include <pthread.h>
#endif
#include <mutex>
#include "absl/synchronization/mutex.h"
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include <mutex>
#include "absl/log/absl_check.h"
#include "absl/synchronization/mutex.h"
// The core library is not accessible in C++ codegen headers, and vice versa.
// Thus, we need to have duplicate headers with similar functionality.
// Make sure any change to this file is also reflected in
// src/core/lib/gprpp/sync.h too.
// src/core/util/sync.h too.
//
// Whenever possible, prefer "src/core/lib/gprpp/sync.h" over this file,
// Whenever possible, prefer "src/core/util/sync.h" over this file,
// since in core we do not rely on g_core_codegen_interface and hence do not
// pay the costs of virtual function calls.
@@ -105,7 +105,7 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock {
ReleasableMutexLock& operator=(const ReleasableMutexLock&) = delete;
void Release() ABSL_UNLOCK_FUNCTION() {
GPR_DEBUG_ASSERT(!released_);
ABSL_DCHECK(!released_);
released_ = true;
mu_->Unlock();
}

View File

@@ -0,0 +1,27 @@
// Copyright 2024 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.
#ifndef GRPCPP_PASSIVE_LISTENER_H
#define GRPCPP_PASSIVE_LISTENER_H
#include <grpc/passive_listener.h>
namespace grpc {
namespace experimental {
using grpc_core::experimental::PassiveListener;
} // namespace experimental
} // namespace grpc
#endif // GRPCPP_PASSIVE_LISTENER_H

View File

@@ -19,15 +19,15 @@
#ifndef GRPCPP_SECURITY_AUDIT_LOGGING_H
#define GRPCPP_SECURITY_AUDIT_LOGGING_H
#include <grpc/grpc_audit_logging.h>
#include <grpcpp/support/string_ref.h>
#include <memory>
#include <string>
#include <utility>
#include "absl/status/statusor.h"
#include <grpc/grpc_audit_logging.h>
#include <grpcpp/support/string_ref.h>
namespace grpc {
namespace experimental {

View File

@@ -19,12 +19,12 @@
#ifndef GRPCPP_SECURITY_AUTH_CONTEXT_H
#define GRPCPP_SECURITY_AUTH_CONTEXT_H
#include <iterator>
#include <vector>
#include <grpcpp/support/config.h>
#include <grpcpp/support/string_ref.h>
#include <iterator>
#include <vector>
struct grpc_auth_context;
struct grpc_auth_property;
struct grpc_auth_property_iterator;

View File

@@ -19,12 +19,12 @@
#ifndef GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_H
#define GRPCPP_SECURITY_AUTH_METADATA_PROCESSOR_H
#include <map>
#include <grpcpp/security/auth_context.h>
#include <grpcpp/support/status.h>
#include <grpcpp/support/string_ref.h>
#include <map>
namespace grpc {
/// Interface allowing custom server-side authorization based on credentials

View File

@@ -15,12 +15,12 @@
#ifndef GRPCPP_SECURITY_AUTHORIZATION_POLICY_PROVIDER_H
#define GRPCPP_SECURITY_AUTHORIZATION_POLICY_PROVIDER_H
#include <memory>
#include <grpc/grpc_security.h>
#include <grpc/status.h>
#include <grpcpp/impl/codegen/status.h>
#include <memory>
namespace grpc {
namespace experimental {

View File

@@ -1,43 +0,0 @@
// Copyright 2021 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_SECURITY_BINDER_CREDENTIALS_H
#define GRPCPP_SECURITY_BINDER_CREDENTIALS_H
#include <memory>
#include <grpcpp/security/binder_security_policy.h>
#include <grpcpp/security/server_credentials.h>
namespace grpc {
class ChannelCredentials;
namespace experimental {
/// EXPERIMENTAL Builds Binder ServerCredentials.
///
/// This should be used along with `binder:` URI scheme. The path in the URI can
/// later be used to access the server's endpoint binder.
/// Note that calling \a ServerBuilder::AddListeningPort() with Binder
/// ServerCredentials in a non-supported environment will make the subsequent
/// call to \a ServerBuilder::BuildAndStart() return a null pointer.
std::shared_ptr<grpc::ServerCredentials> BinderServerCredentials(
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
security_policy);
} // namespace experimental
} // namespace grpc
#endif // GRPCPP_SECURITY_BINDER_CREDENTIALS_H

View File

@@ -1,82 +0,0 @@
// Copyright 2021 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_SECURITY_BINDER_SECURITY_POLICY_H
#define GRPCPP_SECURITY_BINDER_SECURITY_POLICY_H
#include <memory>
#ifdef GPR_ANDROID
#include <jni.h>
#endif
namespace grpc {
namespace experimental {
namespace binder {
// EXPERIMENTAL Determinines if a connection is allowed to be
// established on Android. See https://source.android.com/security/app-sandbox
// for more info about UID.
class SecurityPolicy {
public:
virtual ~SecurityPolicy() = default;
// Returns true if the UID is authorized to connect.
// Must return the same value for the same inputs so callers can safely cache
// the result.
virtual bool IsAuthorized(int uid) = 0;
};
// EXPERIMENTAL Allows all connection. Anything on the Android device will be
// able to connect, use with caution!
class UntrustedSecurityPolicy : public SecurityPolicy {
public:
UntrustedSecurityPolicy();
~UntrustedSecurityPolicy() override;
bool IsAuthorized(int uid) override;
};
// EXPERIMENTAL Only allows the connections from processes with the same UID. In
// most cases this means "from the same APK".
class InternalOnlySecurityPolicy : public SecurityPolicy {
public:
InternalOnlySecurityPolicy();
~InternalOnlySecurityPolicy() override;
bool IsAuthorized(int uid) override;
};
#ifdef GPR_ANDROID
// EXPERIMENTAL Only allows the connections from the APK that have the same
// signature.
class SameSignatureSecurityPolicy : public SecurityPolicy {
public:
// `context` is required for getting PackageManager Java class
SameSignatureSecurityPolicy(JavaVM* jvm, jobject context);
~SameSignatureSecurityPolicy() override;
bool IsAuthorized(int uid) override;
private:
JavaVM* jvm_;
jobject context_;
};
#endif
} // namespace binder
} // namespace experimental
} // namespace grpc
#endif // GRPCPP_SECURITY_BINDER_SECURITY_POLICY_H

View File

@@ -19,10 +19,6 @@
#ifndef GRPCPP_SECURITY_CREDENTIALS_H
#define GRPCPP_SECURITY_CREDENTIALS_H
#include <map>
#include <memory>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpcpp/channel.h>
#include <grpcpp/impl/grpc_library.h>
@@ -33,13 +29,18 @@
#include <grpcpp/support/status.h>
#include <grpcpp/support/string_ref.h>
#include <map>
#include <memory>
#include <vector>
struct grpc_call;
namespace grpc {
class CallCredentials;
class SecureCallCredentials;
class SecureChannelCredentials;
class ChannelCredentials;
namespace testing {
std::string GetOauth2AccessToken();
}
std::shared_ptr<Channel> CreateCustomChannel(
const grpc::string& target,
@@ -68,26 +69,18 @@ std::shared_ptr<ChannelCredentials> XdsCredentials(
/// \see https://grpc.io/docs/guides/auth.html
class ChannelCredentials : private grpc::internal::GrpcLibrary {
public:
~ChannelCredentials() override;
protected:
friend std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
const std::shared_ptr<ChannelCredentials>& channel_creds,
const std::shared_ptr<CallCredentials>& call_creds);
explicit ChannelCredentials(grpc_channel_credentials* creds);
// TODO(yashykt): We need this friend declaration mainly for access to
// AsSecureCredentials(). Once we are able to remove insecure builds from gRPC
// (and also internal dependencies on the indirect method of creating a
// channel through credentials), we would be able to remove this.
friend std::shared_ptr<ChannelCredentials> grpc::XdsCredentials(
const std::shared_ptr<ChannelCredentials>& fallback_creds);
virtual SecureChannelCredentials* AsSecureCredentials() = 0;
grpc_channel_credentials* c_creds() { return c_creds_; }
private:
friend std::shared_ptr<grpc::Channel> CreateCustomChannel(
const grpc::string& target,
const std::shared_ptr<grpc::ChannelCredentials>& creds,
const grpc::ChannelArguments& args);
friend std::shared_ptr<grpc::Channel>
grpc::experimental::CreateCustomChannelWithInterceptors(
const grpc::string& target,
@@ -96,24 +89,23 @@ class ChannelCredentials : private grpc::internal::GrpcLibrary {
std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
friend std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
const std::shared_ptr<ChannelCredentials>& channel_creds,
const std::shared_ptr<CallCredentials>& call_creds);
friend class XdsChannelCredentialsImpl;
virtual std::shared_ptr<Channel> CreateChannelImpl(
const grpc::string& target, const ChannelArguments& args) = 0;
// This function should have been a pure virtual function, but it is
// implemented as a virtual function so that it does not break API.
virtual std::shared_ptr<Channel> CreateChannelWithInterceptors(
const grpc::string& /*target*/, const ChannelArguments& /*args*/,
std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>
/*interceptor_creators*/) {
return nullptr;
const grpc::string& target, const ChannelArguments& args) {
return CreateChannelWithInterceptors(target, args, {});
}
// TODO(yashkt): This is a hack that is needed since InsecureCredentials can
// not use grpc_channel_credentials internally and should be removed after
// insecure builds are removed from gRPC.
virtual bool IsInsecure() const { return false; }
virtual std::shared_ptr<Channel> CreateChannelWithInterceptors(
const grpc::string& target, const ChannelArguments& args,
std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
grpc_channel_credentials* const c_creds_;
};
/// A call credentials object encapsulates the state needed by a client to
@@ -122,22 +114,24 @@ class ChannelCredentials : private grpc::internal::GrpcLibrary {
/// \see https://grpc.io/docs/guides/auth.html
class CallCredentials : private grpc::internal::GrpcLibrary {
public:
~CallCredentials() override;
/// Apply this instance's credentials to \a call.
virtual bool ApplyToCall(grpc_call* call) = 0;
virtual grpc::string DebugString() {
return "CallCredentials did not provide a debug string";
}
bool ApplyToCall(grpc_call* call);
grpc::string DebugString();
protected:
explicit CallCredentials(grpc_call_credentials* creds);
private:
friend std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
const std::shared_ptr<ChannelCredentials>& channel_creds,
const std::shared_ptr<CallCredentials>& call_creds);
friend class CompositeCallCredentialsImpl;
friend std::string grpc::testing::GetOauth2AccessToken();
friend std::shared_ptr<CallCredentials> CompositeCallCredentials(
const std::shared_ptr<CallCredentials>& creds1,
const std::shared_ptr<CallCredentials>& creds2);
virtual SecureCallCredentials* AsSecureCredentials() = 0;
grpc_call_credentials* c_creds_ = nullptr;
};
/// Options used to build SslCredentials.
@@ -253,7 +247,7 @@ class MetadataCredentialsPlugin {
/// Type of credentials this plugin is implementing.
virtual const char* GetType() const { return ""; }
/// Gets the auth metatada produced by this plugin.
/// Gets the auth metadata produced by this plugin.
/// The fully qualified method name is:
/// service_url + "/" + method_name.
/// The channel_auth_context contains (among other things), the identity of
@@ -301,7 +295,7 @@ grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string,
/// Creates STS credentials options from the $STS_CREDENTIALS environment
/// variable. This environment variable points to the path of a JSON file
/// comforming to the schema described above.
/// conforming to the schema described above.
grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options);
std::shared_ptr<CallCredentials> StsCredentials(

View File

@@ -19,22 +19,22 @@
#ifndef GRPCPP_SECURITY_SERVER_CREDENTIALS_H
#define GRPCPP_SECURITY_SERVER_CREDENTIALS_H
#include <memory>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpcpp/impl/grpc_library.h>
#include <grpcpp/security/auth_metadata_processor.h>
#include <grpcpp/security/tls_credentials_options.h>
#include <grpcpp/support/config.h>
#include <memory>
#include <vector>
struct grpc_server;
namespace grpc {
class Server;
class ServerCredentials;
class SecureServerCredentials;
/// Options to create ServerCredentials with SSL
struct SslServerCredentialsOptions {
/// \warning Deprecated
@@ -68,17 +68,23 @@ std::shared_ptr<ServerCredentials> XdsServerCredentials(
/// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
class ServerCredentials : private grpc::internal::GrpcLibrary {
public:
~ServerCredentials() override;
/// This method is not thread-safe and has to be called before the server is
/// started. The last call to this function wins.
virtual void SetAuthMetadataProcessor(
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) = 0;
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor);
protected:
explicit ServerCredentials(grpc_server_credentials* creds);
grpc_server_credentials* c_creds() const { return c_creds_; }
private:
// Needed for access to AddPortToServer.
friend class Server;
// We need this friend declaration for access to Insecure() and
// AsSecureServerCredentials(). When these two functions are no longer
// necessary, this friend declaration can be removed too.
// Needed for access to c_creds_.
friend class ServerBuilder;
friend std::shared_ptr<ServerCredentials> grpc::XdsServerCredentials(
const std::shared_ptr<ServerCredentials>& fallback_credentials);
@@ -87,18 +93,9 @@ class ServerCredentials : private grpc::internal::GrpcLibrary {
///
/// \return bound port number on success, 0 on failure.
// TODO(dgq): the "port" part seems to be a misnomer.
virtual int AddPortToServer(const std::string& addr, grpc_server* server) = 0;
virtual int AddPortToServer(const std::string& addr, grpc_server* server);
// TODO(yashykt): This is a hack since InsecureServerCredentials() cannot use
// grpc_insecure_server_credentials_create() and should be removed after
// insecure builds are removed from gRPC.
virtual bool IsInsecure() const { return false; }
// TODO(yashkt): This is a hack that should be removed once we remove insecure
// builds and the indirect method of adding ports to a server.
virtual SecureServerCredentials* AsSecureServerCredentials() {
return nullptr;
}
grpc_server_credentials* c_creds_;
};
/// Builds SSL ServerCredentials given SSL specific options
@@ -119,9 +116,6 @@ std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
/// Builds Local ServerCredentials.
std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
std::shared_ptr<ServerCredentials> LocalServerCredentials(
grpc_local_connect_type type);

View File

@@ -17,15 +17,19 @@
#ifndef GRPCPP_SECURITY_TLS_CERTIFICATE_PROVIDER_H
#define GRPCPP_SECURITY_TLS_CERTIFICATE_PROVIDER_H
#include <memory>
#include <vector>
#include <grpc/credentials.h>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpcpp/support/config.h>
#include <memory>
#include <string>
#include <vector>
#include "absl/status/statusor.h"
namespace grpc {
namespace experimental {
@@ -67,6 +71,12 @@ class GRPCXX_DLL StaticDataCertificateProvider
grpc_tls_certificate_provider* c_provider() override { return c_provider_; }
// Returns an OK status if the following conditions hold:
// - the root certificates consist of one or more valid PEM blocks, and
// - every identity key-cert pair has a certificate chain that consists of
// valid PEM blocks and has a private key is a valid PEM block.
absl::Status ValidateCredentials() const;
private:
grpc_tls_certificate_provider* c_provider_ = nullptr;
};
@@ -117,6 +127,14 @@ class GRPCXX_DLL FileWatcherCertificateProvider final
grpc_tls_certificate_provider* c_provider() override { return c_provider_; }
// Returns an OK status if the following conditions hold:
// - the currently-loaded root certificates, if any, consist of one or more
// valid PEM blocks, and
// - every currently-loaded identity key-cert pair, if any, has a certificate
// chain that consists of valid PEM blocks and has a private key is a valid
// PEM block.
absl::Status ValidateCredentials() const;
private:
grpc_tls_certificate_provider* c_provider_ = nullptr;
};

View File

@@ -17,21 +17,20 @@
#ifndef GRPCPP_SECURITY_TLS_CERTIFICATE_VERIFIER_H
#define GRPCPP_SECURITY_TLS_CERTIFICATE_VERIFIER_H
#include <functional>
#include <map>
#include <memory>
#include <utility>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/grpc_library.h>
#include <grpcpp/impl/sync.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/status.h>
#include <grpcpp/support/string_ref.h>
#include <functional>
#include <map>
#include <memory>
#include <utility>
#include <vector>
// TODO(yihuazhang): remove the forward declaration here and include
// <grpc/grpc_security.h> directly once the insecure builds are cleaned up.
typedef struct grpc_tls_custom_verification_check_request

View File

@@ -19,18 +19,17 @@
#ifndef GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H
#define GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H
#include <memory>
#include <vector>
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include <grpcpp/security/tls_certificate_provider.h>
#include <grpcpp/security/tls_certificate_verifier.h>
#include <grpcpp/security/tls_crl_provider.h>
#include <grpcpp/support/config.h>
#include <memory>
#include <vector>
namespace grpc {
namespace experimental {
@@ -103,6 +102,8 @@ class TlsCredentialsOptions {
// call is covered by the cert that the peer presented.
// We will perform such checks by default. This should be disabled if
// verifiers other than the host name verifier is used.
// Deprecated: This function will be removed in the 1.66 release. This will be
// replaced by and handled within the custom verifier settings.
void set_check_call_host(bool check_call_host);
// Deprecated in favor of set_crl_provider. The
@@ -111,6 +112,8 @@ class TlsCredentialsOptions {
// If set, gRPC will read all hashed x.509 CRL files in the directory and
// enforce the CRL files on all TLS handshakes. Only supported for OpenSSL
// version > 1.1.
// Deprecated: This function will be removed in the 1.66 release. Use the
// set_crl_provider function instead.
void set_crl_directory(const std::string& path);
void set_crl_provider(std::shared_ptr<CrlProvider> crl_provider);
@@ -184,6 +187,7 @@ class TlsServerCredentialsOptions final : public TlsCredentialsOptions {
// WARNING: This API is extremely dangerous and should not be used. If the
// server's trust bundle is too large, then the TLS server will be unable to
// form a ServerHello, and hence will be unusable.
// Deprecated: This function will be removed in the 1.66 release.
void set_send_client_ca_list(bool send_client_ca_list);
private:

View File

@@ -19,14 +19,9 @@
#ifndef GRPCPP_SERVER_H
#define GRPCPP_SERVER_H
#include <grpc/support/port_platform.h>
#include <list>
#include <memory>
#include <vector>
#include <grpc/compression.h>
#include <grpc/support/atm.h>
#include <grpc/support/port_platform.h>
#include <grpcpp/channel.h>
#include <grpcpp/completion_queue.h>
#include <grpcpp/health_check_service_interface.h>
@@ -40,6 +35,10 @@
#include <grpcpp/support/config.h>
#include <grpcpp/support/status.h>
#include <list>
#include <memory>
#include <vector>
struct grpc_server;
namespace grpc {

View File

@@ -19,24 +19,27 @@
#ifndef GRPCPP_SERVER_BUILDER_H
#define GRPCPP_SERVER_BUILDER_H
#include <grpc/compression.h>
#include <grpc/event_engine/event_engine.h>
#include <grpc/passive_listener.h>
#include <grpc/support/cpu.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/workaround_list.h>
#include <grpcpp/impl/channel_argument_option.h>
#include <grpcpp/impl/server_builder_option.h>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/passive_listener.h>
#include <grpcpp/security/authorization_policy_provider.h>
#include <grpcpp/security/server_credentials.h>
#include <grpcpp/server.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/server_interceptor.h>
#include <climits>
#include <map>
#include <memory>
#include <vector>
#include <grpc/compression.h>
#include <grpc/support/cpu.h>
#include <grpc/support/workaround_list.h>
#include <grpcpp/impl/channel_argument_option.h>
#include <grpcpp/impl/server_builder_option.h>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/security/authorization_policy_provider.h>
#include <grpcpp/server.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/server_interceptor.h>
struct grpc_resource_quota;
namespace grpc {
@@ -292,6 +295,18 @@ class ServerBuilder {
void EnableCallMetricRecording(
experimental::ServerMetricRecorder* server_metric_recorder = nullptr);
// Creates a passive listener for Server Endpoint injection.
///
/// \a PassiveListener lets applications provide pre-established connections
/// to gRPC Servers. The server will behave as if it accepted the connection
/// itself on its own listening addresses.
///
/// This can be called multiple times to create passive listeners with
/// different server credentials.
ServerBuilder& AddPassiveListener(
std::shared_ptr<grpc::ServerCredentials> creds,
std::unique_ptr<grpc::experimental::PassiveListener>& passive_listener);
private:
ServerBuilder* builder_;
};
@@ -365,6 +380,17 @@ class ServerBuilder {
private:
friend class grpc::testing::ServerBuilderPluginTest;
struct UnstartedPassiveListener {
std::weak_ptr<grpc_core::experimental::PassiveListenerImpl>
passive_listener;
std::shared_ptr<grpc::ServerCredentials> credentials;
UnstartedPassiveListener(
std::weak_ptr<grpc_core::experimental::PassiveListenerImpl> listener,
std::shared_ptr<grpc::ServerCredentials> creds)
: passive_listener(std::move(listener)),
credentials(std::move(creds)) {}
};
struct SyncServerSettings {
SyncServerSettings()
: num_cqs(1), min_pollers(1), max_pollers(2), cq_timeout_msec(10000) {}
@@ -389,6 +415,7 @@ class ServerBuilder {
std::vector<std::unique_ptr<grpc::ServerBuilderOption>> options_;
std::vector<std::unique_ptr<NamedService>> services_;
std::vector<Port> ports_;
std::vector<UnstartedPassiveListener> unstarted_passive_listeners_;
SyncServerSettings sync_server_settings_;

View File

@@ -19,17 +19,10 @@
#ifndef GRPCPP_SERVER_CONTEXT_H
#define GRPCPP_SERVER_CONTEXT_H
#include <grpc/support/port_platform.h>
#include <atomic>
#include <cassert>
#include <map>
#include <memory>
#include <type_traits>
#include <vector>
#include <grpc/grpc.h>
#include <grpc/impl/call.h>
#include <grpc/impl/compression_types.h>
#include <grpc/support/port_platform.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/call_op_set.h>
#include <grpcpp/impl/codegen/create_auth_context.h>
@@ -47,6 +40,13 @@
#include <grpcpp/support/string_ref.h>
#include <grpcpp/support/time.h>
#include <atomic>
#include <cassert>
#include <map>
#include <memory>
#include <type_traits>
#include <vector>
struct grpc_metadata;
struct grpc_call;
struct census_context;
@@ -520,7 +520,9 @@ class ServerContextBase {
public:
TestServerCallbackUnary(ServerContextBase* ctx,
std::function<void(grpc::Status)> func)
: reactor_(ctx->DefaultReactor()), func_(std::move(func)) {
: reactor_(ctx->DefaultReactor()),
func_(std::move(func)),
call_(ctx->c_call()) {
this->BindReactor(reactor_);
}
void Finish(grpc::Status s) override {
@@ -537,12 +539,16 @@ class ServerContextBase {
private:
void CallOnDone() override {}
grpc_call* call() override { return call_; }
grpc::internal::ServerReactor* reactor() override { return reactor_; }
grpc::ServerUnaryReactor* const reactor_;
std::atomic_bool status_set_{false};
grpc::Status status_;
const std::function<void(grpc::Status s)> func_;
grpc_call* call_;
};
alignas(Reactor) char default_reactor_[sizeof(Reactor)];

View File

@@ -19,11 +19,9 @@
#ifndef GRPCPP_SERVER_INTERFACE_H
#define GRPCPP_SERVER_INTERFACE_H
#include <grpc/support/port_platform.h>
#include <grpc/grpc.h>
#include <grpc/impl/grpc_types.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/time.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/call_hook.h>
@@ -33,6 +31,8 @@
#include <grpcpp/server_context.h>
#include <grpcpp/support/byte_buffer.h>
#include "absl/log/absl_check.h"
namespace grpc {
class AsyncGenericService;
@@ -319,7 +319,7 @@ class ServerInterface : public internal::CallHook {
grpc::CompletionQueue* call_cq,
grpc::ServerCompletionQueue* notification_cq, void* tag,
Message* message) {
GPR_ASSERT(method);
ABSL_CHECK(method);
new PayloadAsyncRequest<Message>(method, this, context, stream, call_cq,
notification_cq, tag, message);
}
@@ -330,7 +330,7 @@ class ServerInterface : public internal::CallHook {
grpc::CompletionQueue* call_cq,
grpc::ServerCompletionQueue* notification_cq,
void* tag) {
GPR_ASSERT(method);
ABSL_CHECK(method);
new NoPayloadAsyncRequest(method, this, context, stream, call_cq,
notification_cq, tag);
}

View File

@@ -20,11 +20,10 @@
#define GRPCPP_SERVER_POSIX_H
#include <grpc/support/port_platform.h>
#include <grpcpp/server.h>
#include <memory>
#include <grpcpp/server.h>
namespace grpc {
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD

View File

@@ -20,13 +20,14 @@
#define GRPCPP_SUPPORT_ASYNC_STREAM_H
#include <grpc/grpc.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/channel_interface.h>
#include <grpcpp/impl/service_type.h>
#include <grpcpp/server_context.h>
#include <grpcpp/support/status.h>
#include "absl/log/absl_check.h"
namespace grpc {
namespace internal {
@@ -37,7 +38,11 @@ class ClientAsyncStreamingInterface {
/// Start the call that was set up by the constructor, but only if the
/// constructor was invoked through the "Prepare" API which doesn't actually
/// start the call
/// start the call.
///
/// It is illegal to start a write-type operation (eg. Write(), WriteLast(),
/// WritesDone()) while the `StartCall()` operation has not finished
/// (determined by the returning of \a tag).
virtual void StartCall(void* tag) = 0;
/// Request notification of the reading of the initial metadata. Completion
@@ -200,7 +205,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(ClientAsyncReader));
ABSL_CHECK_EQ(size, sizeof(ClientAsyncReader));
}
// This operator should never be called as the memory should be freed as part
@@ -208,10 +213,10 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
void StartCall(void* tag) override {
GPR_ASSERT(!started_);
ABSL_CHECK(!started_);
started_ = true;
StartCallInternal(tag);
}
@@ -225,8 +230,8 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
/// calling code can access the received metadata through the
/// \a ClientContext.
void ReadInitialMetadata(void* tag) override {
GPR_ASSERT(started_);
GPR_ASSERT(!context_->initial_metadata_received_);
ABSL_CHECK(started_);
ABSL_CHECK(!context_->initial_metadata_received_);
meta_ops_.set_output_tag(tag);
meta_ops_.RecvInitialMetadata(context_);
@@ -234,7 +239,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
}
void Read(R* msg, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
read_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
read_ops_.RecvInitialMetadata(context_);
@@ -249,7 +254,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
/// - the \a ClientContext associated with this call is updated with
/// possible initial and trailing metadata received from the server.
void Finish(grpc::Status* status, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
finish_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
finish_ops_.RecvInitialMetadata(context_);
@@ -265,12 +270,12 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
const W& request, bool start, void* tag)
: context_(context), call_(call), started_(start) {
// TODO(ctiller): don't assert
GPR_ASSERT(init_ops_.SendMessage(request).ok());
ABSL_CHECK(init_ops_.SendMessage(request).ok());
init_ops_.ClientSendClose();
if (start) {
StartCallInternal(tag);
} else {
GPR_ASSERT(tag == nullptr);
ABSL_CHECK(tag == nullptr);
}
}
@@ -348,7 +353,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(ClientAsyncWriter));
ABSL_CHECK_EQ(size, sizeof(ClientAsyncWriter));
}
// This operator should never be called as the memory should be freed as part
@@ -356,10 +361,10 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
void StartCall(void* tag) override {
GPR_ASSERT(!started_);
ABSL_CHECK(!started_);
started_ = true;
StartCallInternal(tag);
}
@@ -372,8 +377,8 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
/// associated with this call is updated, and the calling code can access
/// the received metadata through the \a ClientContext.
void ReadInitialMetadata(void* tag) override {
GPR_ASSERT(started_);
GPR_ASSERT(!context_->initial_metadata_received_);
ABSL_CHECK(started_);
ABSL_CHECK(!context_->initial_metadata_received_);
meta_ops_.set_output_tag(tag);
meta_ops_.RecvInitialMetadata(context_);
@@ -381,27 +386,27 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
}
void Write(const W& msg, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
write_ops_.set_output_tag(tag);
// TODO(ctiller): don't assert
GPR_ASSERT(write_ops_.SendMessage(msg).ok());
ABSL_CHECK(write_ops_.SendMessage(msg).ok());
call_.PerformOps(&write_ops_);
}
void Write(const W& msg, grpc::WriteOptions options, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
write_ops_.set_output_tag(tag);
if (options.is_last_message()) {
options.set_buffer_hint();
write_ops_.ClientSendClose();
}
// TODO(ctiller): don't assert
GPR_ASSERT(write_ops_.SendMessage(msg, options).ok());
ABSL_CHECK(write_ops_.SendMessage(msg, options).ok());
call_.PerformOps(&write_ops_);
}
void WritesDone(void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
write_ops_.set_output_tag(tag);
write_ops_.ClientSendClose();
call_.PerformOps(&write_ops_);
@@ -415,7 +420,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
/// - attempts to fill in the \a response parameter passed to this class's
/// constructor with the server's response message.
void Finish(grpc::Status* status, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
finish_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
finish_ops_.RecvInitialMetadata(context_);
@@ -435,7 +440,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
if (start) {
StartCallInternal(tag);
} else {
GPR_ASSERT(tag == nullptr);
ABSL_CHECK(tag == nullptr);
}
}
@@ -515,7 +520,7 @@ class ClientAsyncReaderWriter final
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(ClientAsyncReaderWriter));
ABSL_CHECK_EQ(size, sizeof(ClientAsyncReaderWriter));
}
// This operator should never be called as the memory should be freed as part
@@ -523,10 +528,10 @@ class ClientAsyncReaderWriter final
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
void StartCall(void* tag) override {
GPR_ASSERT(!started_);
ABSL_CHECK(!started_);
started_ = true;
StartCallInternal(tag);
}
@@ -539,8 +544,8 @@ class ClientAsyncReaderWriter final
/// is updated with it, and then the receiving initial metadata can
/// be accessed through this \a ClientContext.
void ReadInitialMetadata(void* tag) override {
GPR_ASSERT(started_);
GPR_ASSERT(!context_->initial_metadata_received_);
ABSL_CHECK(started_);
ABSL_CHECK(!context_->initial_metadata_received_);
meta_ops_.set_output_tag(tag);
meta_ops_.RecvInitialMetadata(context_);
@@ -548,7 +553,7 @@ class ClientAsyncReaderWriter final
}
void Read(R* msg, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
read_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
read_ops_.RecvInitialMetadata(context_);
@@ -558,27 +563,27 @@ class ClientAsyncReaderWriter final
}
void Write(const W& msg, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
write_ops_.set_output_tag(tag);
// TODO(ctiller): don't assert
GPR_ASSERT(write_ops_.SendMessage(msg).ok());
ABSL_CHECK(write_ops_.SendMessage(msg).ok());
call_.PerformOps(&write_ops_);
}
void Write(const W& msg, grpc::WriteOptions options, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
write_ops_.set_output_tag(tag);
if (options.is_last_message()) {
options.set_buffer_hint();
write_ops_.ClientSendClose();
}
// TODO(ctiller): don't assert
GPR_ASSERT(write_ops_.SendMessage(msg, options).ok());
ABSL_CHECK(write_ops_.SendMessage(msg, options).ok());
call_.PerformOps(&write_ops_);
}
void WritesDone(void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
write_ops_.set_output_tag(tag);
write_ops_.ClientSendClose();
call_.PerformOps(&write_ops_);
@@ -589,7 +594,7 @@ class ClientAsyncReaderWriter final
/// - the \a ClientContext associated with this call is updated with
/// possible initial and trailing metadata sent from the server.
void Finish(grpc::Status* status, void* tag) override {
GPR_ASSERT(started_);
ABSL_CHECK(started_);
finish_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
finish_ops_.RecvInitialMetadata(context_);
@@ -606,7 +611,7 @@ class ClientAsyncReaderWriter final
if (start) {
StartCallInternal(tag);
} else {
GPR_ASSERT(tag == nullptr);
ABSL_CHECK(tag == nullptr);
}
}
@@ -706,7 +711,7 @@ class ServerAsyncReader final : public ServerAsyncReaderInterface<W, R> {
/// - The initial metadata that will be sent to the client from this op will
/// be taken from the \a ServerContext associated with the call.
void SendInitialMetadata(void* tag) override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
meta_ops_.set_output_tag(tag);
meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_,
@@ -765,7 +770,7 @@ class ServerAsyncReader final : public ServerAsyncReaderInterface<W, R> {
/// gRPC doesn't take ownership or a reference to \a status, so it is safe to
/// to deallocate once FinishWithError returns.
void FinishWithError(const grpc::Status& status, void* tag) override {
GPR_ASSERT(!status.ok());
ABSL_CHECK(!status.ok());
finish_ops_.set_output_tag(tag);
if (!ctx_->sent_initial_metadata_) {
finish_ops_.SendInitialMetadata(&ctx_->initial_metadata_,
@@ -855,7 +860,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface<W> {
///
/// \param[in] tag Tag identifying this request.
void SendInitialMetadata(void* tag) override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
meta_ops_.set_output_tag(tag);
meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_,
@@ -871,7 +876,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface<W> {
write_ops_.set_output_tag(tag);
EnsureInitialMetadataSent(&write_ops_);
// TODO(ctiller): don't assert
GPR_ASSERT(write_ops_.SendMessage(msg).ok());
ABSL_CHECK(write_ops_.SendMessage(msg).ok());
call_.PerformOps(&write_ops_);
}
@@ -883,7 +888,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface<W> {
EnsureInitialMetadataSent(&write_ops_);
// TODO(ctiller): don't assert
GPR_ASSERT(write_ops_.SendMessage(msg, options).ok());
ABSL_CHECK(write_ops_.SendMessage(msg, options).ok());
call_.PerformOps(&write_ops_);
}
@@ -902,7 +907,7 @@ class ServerAsyncWriter final : public ServerAsyncWriterInterface<W> {
write_ops_.set_output_tag(tag);
EnsureInitialMetadataSent(&write_ops_);
options.set_buffer_hint();
GPR_ASSERT(write_ops_.SendMessage(msg, options).ok());
ABSL_CHECK(write_ops_.SendMessage(msg, options).ok());
write_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status);
call_.PerformOps(&write_ops_);
}
@@ -1021,7 +1026,7 @@ class ServerAsyncReaderWriter final
///
/// \param[in] tag Tag identifying this request.
void SendInitialMetadata(void* tag) override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
meta_ops_.set_output_tag(tag);
meta_ops_.SendInitialMetadata(&ctx_->initial_metadata_,
@@ -1043,7 +1048,7 @@ class ServerAsyncReaderWriter final
write_ops_.set_output_tag(tag);
EnsureInitialMetadataSent(&write_ops_);
// TODO(ctiller): don't assert
GPR_ASSERT(write_ops_.SendMessage(msg).ok());
ABSL_CHECK(write_ops_.SendMessage(msg).ok());
call_.PerformOps(&write_ops_);
}
@@ -1053,7 +1058,7 @@ class ServerAsyncReaderWriter final
options.set_buffer_hint();
}
EnsureInitialMetadataSent(&write_ops_);
GPR_ASSERT(write_ops_.SendMessage(msg, options).ok());
ABSL_CHECK(write_ops_.SendMessage(msg, options).ok());
call_.PerformOps(&write_ops_);
}
@@ -1073,7 +1078,7 @@ class ServerAsyncReaderWriter final
write_ops_.set_output_tag(tag);
EnsureInitialMetadataSent(&write_ops_);
options.set_buffer_hint();
GPR_ASSERT(write_ops_.SendMessage(msg, options).ok());
ABSL_CHECK(write_ops_.SendMessage(msg, options).ok());
write_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status);
call_.PerformOps(&write_ops_);
}

View File

@@ -20,7 +20,6 @@
#define GRPCPP_SUPPORT_ASYNC_UNARY_CALL_H
#include <grpc/grpc.h>
#include <grpc/support/log.h>
#include <grpcpp/client_context.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/call_op_set.h>
@@ -30,6 +29,8 @@
#include <grpcpp/server_context.h>
#include <grpcpp/support/status.h>
#include "absl/log/absl_check.h"
namespace grpc {
// Forward declaration for use in Helper class
@@ -130,7 +131,7 @@ class ClientAsyncResponseReaderHelper {
new (grpc_call_arena_alloc(call, sizeof(SingleBufType))) SingleBufType;
*single_buf_ptr = single_buf;
// TODO(ctiller): don't assert
GPR_ASSERT(single_buf->SendMessage(request).ok());
ABSL_CHECK(single_buf->SendMessage(request).ok());
single_buf->ClientSendClose();
// The purpose of the following functions is to type-erase the actual
@@ -220,7 +221,7 @@ class ClientAsyncResponseReader final
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(ClientAsyncResponseReader));
ABSL_CHECK_EQ(size, sizeof(ClientAsyncResponseReader));
}
// This operator should never be called as the memory should be freed as part
@@ -228,10 +229,10 @@ class ClientAsyncResponseReader final
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
void StartCall() override {
GPR_DEBUG_ASSERT(!started_);
ABSL_DCHECK(!started_);
started_ = true;
internal::ClientAsyncResponseReaderHelper::StartCall(context_, single_buf_);
}
@@ -243,8 +244,8 @@ class ClientAsyncResponseReader final
/// - the \a ClientContext associated with this call is updated with
/// possible initial and trailing metadata sent from the server.
void ReadInitialMetadata(void* tag) override {
GPR_DEBUG_ASSERT(started_);
GPR_DEBUG_ASSERT(!context_->initial_metadata_received_);
ABSL_DCHECK(started_);
ABSL_DCHECK(!context_->initial_metadata_received_);
read_initial_metadata_(context_, &call_, single_buf_, tag);
initial_metadata_read_ = true;
}
@@ -255,7 +256,7 @@ class ClientAsyncResponseReader final
/// - the \a ClientContext associated with this call is updated with
/// possible initial and trailing metadata sent from the server.
void Finish(R* msg, grpc::Status* status, void* tag) override {
GPR_DEBUG_ASSERT(started_);
ABSL_DCHECK(started_);
finish_(context_, &call_, initial_metadata_read_, single_buf_, &finish_buf_,
static_cast<void*>(msg), status, tag);
}
@@ -304,7 +305,7 @@ class ServerAsyncResponseWriter final
///
/// \param[in] tag Tag identifying this request.
void SendInitialMetadata(void* tag) override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
meta_buf_.set_output_tag(tag);
meta_buf_.SendInitialMetadata(&ctx_->initial_metadata_,
@@ -373,7 +374,7 @@ class ServerAsyncResponseWriter final
/// deallocate them once the Finish operation is complete (i.e. a result
/// arrives in the completion queue).
void FinishWithError(const grpc::Status& status, void* tag) {
GPR_ASSERT(!status.ok());
ABSL_CHECK(!status.ok());
finish_buf_.set_output_tag(tag);
if (!ctx_->sent_initial_metadata_) {
finish_buf_.SendInitialMetadata(&ctx_->initial_metadata_,

View File

@@ -19,16 +19,15 @@
#ifndef GRPCPP_SUPPORT_BYTE_BUFFER_H
#define GRPCPP_SUPPORT_BYTE_BUFFER_H
#include <vector>
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/serialization_traits.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/slice.h>
#include <grpcpp/support/status.h>
#include <vector>
namespace grpc {
class ServerInterface;
@@ -59,7 +58,7 @@ class GrpcByteBufferPeer;
/// A sequence of bytes.
class ByteBuffer final {
public:
/// Constuct an empty buffer.
/// Construct an empty buffer.
ByteBuffer() : buffer_(nullptr) {}
/// Construct buffer from \a slices, of which there are \a nslices.

View File

@@ -19,17 +19,19 @@
#ifndef GRPCPP_SUPPORT_CALLBACK_COMMON_H
#define GRPCPP_SUPPORT_CALLBACK_COMMON_H
#include <functional>
#include <grpc/grpc.h>
#include <grpc/impl/grpc_types.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/codegen/channel_interface.h>
#include <grpcpp/impl/completion_queue_tag.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/global_callback_hook.h>
#include <grpcpp/support/status.h>
#include <functional>
#include "absl/log/absl_check.h"
namespace grpc {
namespace internal {
@@ -71,7 +73,7 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor {
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(CallbackWithStatusTag));
ABSL_CHECK_EQ(size, sizeof(CallbackWithStatusTag));
}
// This operator should never be called as the memory should be freed as part
@@ -79,7 +81,7 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor {
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
CallbackWithStatusTag(grpc_call* call, std::function<void(Status)> f,
CompletionQueueTag* ops)
@@ -118,14 +120,25 @@ class CallbackWithStatusTag : public grpc_completion_queue_functor {
// The tag was swallowed
return;
}
GPR_ASSERT(ignored == ops_);
ABSL_CHECK(ignored == ops_);
// Last use of func_ or status_, so ok to move them out
auto func = std::move(func_);
auto status = std::move(status_);
func_ = nullptr; // reset to clear this out for sure
status_ = Status(); // reset to clear this out for sure
CatchingCallback(std::move(func), std::move(status));
GetGlobalCallbackHook()->RunCallback(
call_, [func = std::move(func), status = std::move(status)]() {
#if GRPC_ALLOW_EXCEPTIONS
try {
func(status);
} catch (...) {
// nothing to return or change here, just don't crash the library
}
#else // GRPC_ALLOW_EXCEPTIONS
func(status);
#endif // GRPC_ALLOW_EXCEPTIONS
});
grpc_call_unref(call_);
}
};
@@ -137,7 +150,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor {
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(CallbackWithSuccessTag));
ABSL_CHECK_EQ(size, sizeof(CallbackWithSuccessTag));
}
// This operator should never be called as the memory should be freed as part
@@ -145,7 +158,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor {
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
CallbackWithSuccessTag() : call_(nullptr) {}
@@ -162,7 +175,7 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor {
// callbacks.
void Set(grpc_call* call, std::function<void(bool)> f,
CompletionQueueTag* ops, bool can_inline) {
GPR_ASSERT(call_ == nullptr);
ABSL_CHECK_EQ(call_, nullptr);
grpc_call_ref(call);
call_ = call;
func_ = std::move(f);
@@ -207,10 +220,22 @@ class CallbackWithSuccessTag : public grpc_completion_queue_functor {
auto* ops = ops_;
#endif
bool do_callback = ops_->FinalizeResult(&ignored, &ok);
GPR_DEBUG_ASSERT(ignored == ops);
#ifndef NDEBUG
ABSL_DCHECK(ignored == ops);
#endif
if (do_callback) {
CatchingCallback(func_, ok);
GetGlobalCallbackHook()->RunCallback(call_, [this, ok]() {
#if GRPC_ALLOW_EXCEPTIONS
try {
func_(ok);
} catch (...) {
// nothing to return or change here, just don't crash the library
}
#else // GRPC_ALLOW_EXCEPTIONS
func_(ok);
#endif // GRPC_ALLOW_EXCEPTIONS
});
}
}
};

View File

@@ -19,16 +19,16 @@
#ifndef GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_H
#define GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_H
#include <list>
#include <vector>
#include <grpc/compression.h>
#include <grpc/grpc.h>
#include <grpcpp/resource_quota.h>
#include <grpcpp/support/config.h>
#include <list>
#include <vector>
namespace grpc {
class SecureChannelCredentials;
class ChannelCredentials;
namespace testing {
class ChannelArgumentsTest;
} // namespace testing
@@ -120,7 +120,7 @@ class ChannelArguments {
}
private:
friend class grpc::SecureChannelCredentials;
friend class grpc::ChannelCredentials;
friend class grpc::testing::ChannelArgumentsTest;
/// Default pointer argument operations.

View File

@@ -19,12 +19,8 @@
#ifndef GRPCPP_SUPPORT_CLIENT_CALLBACK_H
#define GRPCPP_SUPPORT_CLIENT_CALLBACK_H
#include <atomic>
#include <functional>
#include <grpc/grpc.h>
#include <grpc/impl/call.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/call_op_set.h>
#include <grpcpp/impl/sync.h>
@@ -32,6 +28,11 @@
#include <grpcpp/support/config.h>
#include <grpcpp/support/status.h>
#include <atomic>
#include <functional>
#include "absl/log/absl_check.h"
namespace grpc {
class Channel;
class ClientContext;
@@ -70,7 +71,7 @@ class CallbackUnaryCallImpl {
const InputMessage* request, OutputMessage* result,
std::function<void(grpc::Status)> on_completion) {
grpc::CompletionQueue* cq = channel->CallbackCQ();
GPR_ASSERT(cq != nullptr);
ABSL_CHECK_NE(cq, nullptr);
grpc::internal::Call call(channel->CreateCall(method, context, cq));
using FullCallOpSet = grpc::internal::CallOpSet<
@@ -304,7 +305,7 @@ class ClientBidiReactor : public internal::ClientReactor {
/// The argument to AddMultipleHolds must be positive.
void AddHold() { AddMultipleHolds(1); }
void AddMultipleHolds(int holds) {
GPR_DEBUG_ASSERT(holds > 0);
ABSL_DCHECK_GT(holds, 0);
stream_->AddHold(holds);
}
void RemoveHold() { stream_->RemoveHold(); }
@@ -324,21 +325,20 @@ class ClientBidiReactor : public internal::ClientReactor {
/// call of OnReadDone or OnDone.
///
/// \param[in] ok Was the initial metadata read successfully? If false, no
/// new read/write operation will succeed, and any further
/// Start* operations should not be called.
/// new read/write operation will succeed.
virtual void OnReadInitialMetadataDone(bool /*ok*/) {}
/// Notifies the application that a StartRead operation completed.
///
/// \param[in] ok Was it successful? If false, no new read/write operation
/// will succeed, and any further Start* should not be called.
/// will succeed.
virtual void OnReadDone(bool /*ok*/) {}
/// Notifies the application that a StartWrite or StartWriteLast operation
/// completed.
///
/// \param[in] ok Was it successful? If false, no new read/write operation
/// will succeed, and any further Start* should not be called.
/// will succeed.
virtual void OnWriteDone(bool /*ok*/) {}
/// Notifies the application that a StartWritesDone operation completed. Note
@@ -368,7 +368,7 @@ class ClientReadReactor : public internal::ClientReactor {
void AddHold() { AddMultipleHolds(1); }
void AddMultipleHolds(int holds) {
GPR_DEBUG_ASSERT(holds > 0);
ABSL_DCHECK_GT(holds, 0);
reader_->AddHold(holds);
}
void RemoveHold() { reader_->RemoveHold(); }
@@ -400,7 +400,7 @@ class ClientWriteReactor : public internal::ClientReactor {
void AddHold() { AddMultipleHolds(1); }
void AddMultipleHolds(int holds) {
GPR_DEBUG_ASSERT(holds > 0);
ABSL_DCHECK_GT(holds, 0);
writer_->AddHold(holds);
}
void RemoveHold() { writer_->RemoveHold(); }
@@ -461,7 +461,7 @@ class ClientCallbackReaderWriterImpl
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(ClientCallbackReaderWriterImpl));
ABSL_CHECK_EQ(size, sizeof(ClientCallbackReaderWriterImpl));
}
// This operator should never be called as the memory should be freed as part
@@ -469,7 +469,7 @@ class ClientCallbackReaderWriterImpl
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
void StartCall() ABSL_LOCKS_EXCLUDED(start_mu_) override {
// This call initiates two batches, plus any backlog, each with a callback
@@ -527,7 +527,7 @@ class ClientCallbackReaderWriterImpl
write_ops_.ClientSendClose();
}
// TODO(vjpai): don't assert
GPR_ASSERT(write_ops_.SendMessagePtr(msg, options).ok());
ABSL_CHECK(write_ops_.SendMessagePtr(msg, options).ok());
callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed);
if (GPR_UNLIKELY(corked_write_needed_)) {
write_ops_.SendInitialMetadata(&context_->send_initial_metadata_,
@@ -719,7 +719,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader<Response> {
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(ClientCallbackReaderImpl));
ABSL_CHECK_EQ(size, sizeof(ClientCallbackReaderImpl));
}
// This operator should never be called as the memory should be freed as part
@@ -727,7 +727,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader<Response> {
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
void StartCall() override {
// This call initiates two batches, plus any backlog, each with a callback
@@ -804,7 +804,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader<Response> {
: context_(context), call_(call), reactor_(reactor) {
this->BindReactor(reactor);
// TODO(vjpai): don't assert
GPR_ASSERT(start_ops_.SendMessagePtr(request).ok());
ABSL_CHECK(start_ops_.SendMessagePtr(request).ok());
start_ops_.ClientSendClose();
}
@@ -880,7 +880,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter<Request> {
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(ClientCallbackWriterImpl));
ABSL_CHECK_EQ(size, sizeof(ClientCallbackWriterImpl));
}
// This operator should never be called as the memory should be freed as part
@@ -888,7 +888,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter<Request> {
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
void StartCall() ABSL_LOCKS_EXCLUDED(start_mu_) override {
// This call initiates two batches, plus any backlog, each with a callback
@@ -929,7 +929,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter<Request> {
write_ops_.ClientSendClose();
}
// TODO(vjpai): don't assert
GPR_ASSERT(write_ops_.SendMessagePtr(msg, options).ok());
ABSL_CHECK(write_ops_.SendMessagePtr(msg, options).ok());
callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed);
if (GPR_UNLIKELY(corked_write_needed_)) {
@@ -1110,7 +1110,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary {
public:
// always allocated against a call arena, no memory free required
static void operator delete(void* /*ptr*/, std::size_t size) {
GPR_ASSERT(size == sizeof(ClientCallbackUnaryImpl));
ABSL_CHECK_EQ(size, sizeof(ClientCallbackUnaryImpl));
}
// This operator should never be called as the memory should be freed as part
@@ -1118,7 +1118,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary {
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
static void operator delete(void*, void*) { GPR_ASSERT(false); }
static void operator delete(void*, void*) { ABSL_CHECK(false); }
void StartCall() override {
// This call initiates two batches, each with a callback
@@ -1157,7 +1157,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary {
: context_(context), call_(call), reactor_(reactor) {
this->BindReactor(reactor);
// TODO(vjpai): don't assert
GPR_ASSERT(start_ops_.SendMessagePtr(request).ok());
ABSL_CHECK(start_ops_.SendMessagePtr(request).ok());
start_ops_.ClientSendClose();
finish_ops_.RecvMessage(response);
finish_ops_.AllowNoMessage();

View File

@@ -19,14 +19,15 @@
#ifndef GRPCPP_SUPPORT_CLIENT_INTERCEPTOR_H
#define GRPCPP_SUPPORT_CLIENT_INTERCEPTOR_H
#include <memory>
#include <vector>
#include <grpc/support/log.h>
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/interceptor.h>
#include <grpcpp/support/string_ref.h>
#include <memory>
#include <vector>
#include "absl/log/absl_check.h"
namespace grpc {
class Channel;
@@ -139,7 +140,7 @@ class ClientRpcInfo {
// Runs interceptor at pos \a pos.
void RunInterceptor(
experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) {
GPR_ASSERT(pos < interceptors_.size());
ABSL_CHECK_LT(pos, interceptors_.size());
interceptors_[pos]->Intercept(interceptor_methods);
}

View File

@@ -35,7 +35,7 @@ namespace grpc {
// Using grpc::string and grpc::to_string is discouraged in favor of
// std::string and std::to_string. This is only for legacy code using
// them explictly.
// them explicitly.
using std::string; // deprecated // NOLINT(misc-unused-using-decls)
using std::to_string; // deprecated // NOLINT(misc-unused-using-decls)

View File

@@ -0,0 +1,58 @@
// Copyright 2024 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_SUPPORT_GLOBAL_CALLBACK_HOOK_H
#define GRPCPP_SUPPORT_GLOBAL_CALLBACK_HOOK_H
#include "absl/functional/function_ref.h"
struct grpc_call;
namespace grpc {
class GlobalCallbackHook {
public:
virtual ~GlobalCallbackHook() = default;
virtual void RunCallback(grpc_call* call,
absl::FunctionRef<void()> callback) = 0;
protected:
// An exception-safe way of invoking a user-specified callback function.
template <class Func, class... Args>
void CatchingCallback(Func&& func, Args&&... args) {
#if GRPC_ALLOW_EXCEPTIONS
try {
func(std::forward<Args>(args)...);
} catch (...) {
// nothing to return or change here, just don't crash the library
}
#else // GRPC_ALLOW_EXCEPTIONS
func(std::forward<Args>(args)...);
#endif // GRPC_ALLOW_EXCEPTIONS
}
};
class DefaultGlobalCallbackHook final : public GlobalCallbackHook {
public:
void RunCallback(grpc_call* call,
absl::FunctionRef<void()> callback) override {
CatchingCallback(callback);
}
};
std::shared_ptr<GlobalCallbackHook> GetGlobalCallbackHook();
void SetGlobalCallbackHook(GlobalCallbackHook* hook);
} // namespace grpc
#endif // GRPCPP_SUPPORT_GLOBAL_CALLBACK_HOOK_H

View File

@@ -19,16 +19,16 @@
#ifndef GRPCPP_SUPPORT_INTERCEPTOR_H
#define GRPCPP_SUPPORT_INTERCEPTOR_H
#include <map>
#include <memory>
#include <string>
#include <grpc/impl/grpc_types.h>
#include <grpcpp/impl/metadata_map.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/config.h>
#include <grpcpp/support/string_ref.h>
#include <map>
#include <memory>
#include <string>
namespace grpc {
class ChannelInterface;
@@ -133,7 +133,7 @@ class InterceptorBatchMethods {
/// means that the payload would be available in the serialized form only
/// unless an interceptor replaces the payload with ModifySendMessage.
/// Returns a modifable ByteBuffer holding the serialized form of the message
/// Returns a modifiable ByteBuffer holding the serialized form of the message
/// that is going to be sent. Valid for PRE_SEND_MESSAGE interceptions.
/// A return value of nullptr indicates that this ByteBuffer is not valid.
virtual ByteBuffer* GetSerializedSendMessage() = 0;

View File

@@ -20,11 +20,12 @@
#define GRPCPP_SUPPORT_METHOD_HANDLER_H
#include <grpc/byte_buffer.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/rpc_service_method.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/sync_stream.h>
#include "absl/log/absl_check.h"
namespace grpc {
namespace internal {
@@ -57,7 +58,7 @@ template <class Callable>
template <class ResponseType>
void UnaryRunHandlerHelper(const MethodHandler::HandlerParameter& param,
ResponseType* rsp, grpc::Status& status) {
GPR_ASSERT(!param.server_context->sent_initial_metadata_);
ABSL_CHECK(!param.server_context->sent_initial_metadata_);
grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata,
grpc::internal::CallOpSendMessage,
grpc::internal::CallOpServerSendStatus>

View File

@@ -19,20 +19,20 @@
#ifndef GRPCPP_SUPPORT_PROTO_BUFFER_READER_H
#define GRPCPP_SUPPORT_PROTO_BUFFER_READER_H
#include <type_traits>
#include "absl/strings/cord.h"
#include <grpc/byte_buffer.h>
#include <grpc/byte_buffer_reader.h>
#include <grpc/impl/grpc_types.h>
#include <grpc/slice.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/codegen/config_protobuf.h>
#include <grpcpp/impl/serialization_traits.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/status.h>
#include <type_traits>
#include "absl/log/absl_check.h"
#include "absl/strings/cord.h"
/// This header provides an object that reads bytes directly from a
/// grpc::ByteBuffer, via the ZeroCopyInputStream interface
@@ -75,7 +75,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream {
if (backup_count_ > 0) {
*data = GRPC_SLICE_START_PTR(*slice_) + GRPC_SLICE_LENGTH(*slice_) -
backup_count_;
GPR_ASSERT(backup_count_ <= INT_MAX);
ABSL_CHECK_LE(backup_count_, INT_MAX);
*size = static_cast<int>(backup_count_);
backup_count_ = 0;
return true;
@@ -86,7 +86,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream {
}
*data = GRPC_SLICE_START_PTR(*slice_);
// On win x64, int is only 32bit
GPR_ASSERT(GRPC_SLICE_LENGTH(*slice_) <= INT_MAX);
ABSL_CHECK_LE(GRPC_SLICE_LENGTH(*slice_), static_cast<size_t>(INT_MAX));
byte_count_ += * size = static_cast<int>(GRPC_SLICE_LENGTH(*slice_));
return true;
}
@@ -98,7 +98,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream {
/// bytes that have already been returned by the last call of Next.
/// So do the backup and have that ready for a later Next.
void BackUp(int count) override {
GPR_ASSERT(count <= static_cast<int>(GRPC_SLICE_LENGTH(*slice_)));
ABSL_CHECK_LE(count, static_cast<int>(GRPC_SLICE_LENGTH(*slice_)));
backup_count_ = count;
}
@@ -174,7 +174,7 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream {
return true;
}
}
GPR_ASSERT(count == 0);
ABSL_CHECK_EQ(count, 0);
return true;
}
#endif // GRPC_PROTOBUF_CORD_SUPPORT_ENABLED

View File

@@ -19,20 +19,20 @@
#ifndef GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H
#define GRPCPP_SUPPORT_PROTO_BUFFER_WRITER_H
#include <type_traits>
#include "absl/strings/cord.h"
#include <grpc/byte_buffer.h>
#include <grpc/impl/grpc_types.h>
#include <grpc/slice.h>
#include <grpc/slice_buffer.h>
#include <grpc/support/log.h>
#include <grpcpp/impl/codegen/config_protobuf.h>
#include <grpcpp/impl/serialization_traits.h>
#include <grpcpp/support/byte_buffer.h>
#include <grpcpp/support/status.h>
#include <type_traits>
#include "absl/log/absl_check.h"
#include "absl/strings/cord.h"
/// This header provides an object that writes bytes directly into a
/// grpc::ByteBuffer, via the ZeroCopyOutputStream interface
@@ -64,7 +64,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream {
total_size_(total_size),
byte_count_(0),
have_backup_(false) {
GPR_ASSERT(!byte_buffer->Valid());
ABSL_CHECK(!byte_buffer->Valid());
/// Create an empty raw byte buffer and look at its underlying slice buffer
grpc_byte_buffer* bp = grpc_raw_byte_buffer_create(nullptr, 0);
byte_buffer->set_buffer(bp);
@@ -81,7 +81,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream {
/// safe for the caller to write from data[0, size - 1].
bool Next(void** data, int* size) override {
// Protobuf should not ask for more memory than total_size_.
GPR_ASSERT(byte_count_ < total_size_);
ABSL_CHECK_LT(byte_count_, total_size_);
// 1. Use the remaining backup slice if we have one
// 2. Otherwise allocate a slice, up to the remaining length needed
// or our maximum allocation size
@@ -106,7 +106,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream {
}
*data = GRPC_SLICE_START_PTR(slice_);
// On win x64, int is only 32bit
GPR_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX);
ABSL_CHECK(GRPC_SLICE_LENGTH(slice_) <= static_cast<size_t>(INT_MAX));
byte_count_ += * size = static_cast<int>(GRPC_SLICE_LENGTH(slice_));
// Using grpc_slice_buffer_add could modify slice_ and merge it with the
// previous slice. Therefore, use grpc_slice_buffer_add_indexed method to
@@ -131,7 +131,7 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream {
/// 2. Split it into the needed (if any) and unneeded part
/// 3. Add the needed part back to the slice buffer
/// 4. Mark that we still have the remaining part (for later use/unref)
GPR_ASSERT(count <= static_cast<int>(GRPC_SLICE_LENGTH(slice_)));
ABSL_CHECK_LE(count, static_cast<int>(GRPC_SLICE_LENGTH(slice_)));
grpc_slice_buffer_pop(slice_buffer_);
if (static_cast<size_t>(count) == GRPC_SLICE_LENGTH(slice_)) {
backup_slice_ = slice_;

View File

@@ -19,10 +19,7 @@
#ifndef GRPCPP_SUPPORT_SERVER_CALLBACK_H
#define GRPCPP_SUPPORT_SERVER_CALLBACK_H
#include <atomic>
#include <functional>
#include <type_traits>
#include <grpc/impl/call.h>
#include <grpcpp/impl/call.h>
#include <grpcpp/impl/call_op_set.h>
#include <grpcpp/impl/sync.h>
@@ -31,6 +28,12 @@
#include <grpcpp/support/message_allocator.h>
#include <grpcpp/support/status.h>
#include <atomic>
#include <functional>
#include <type_traits>
#include "absl/functional/any_invocable.h"
namespace grpc {
// Declare base class of all reactors as internal
@@ -127,6 +130,12 @@ class ServerCallbackCall {
private:
virtual ServerReactor* reactor() = 0;
virtual grpc_call* call() = 0;
virtual void RunAsync(absl::AnyInvocable<void()> cb) {
grpc_call_run_in_event_engine(call(), std::move(cb));
}
// CallOnDone performs the work required at completion of the RPC: invoking
// the OnDone function and doing all necessary cleanup. This function is only
// ever invoked on a fully-Unref'fed ServerCallbackCall.

View File

@@ -19,14 +19,15 @@
#ifndef GRPCPP_SUPPORT_SERVER_INTERCEPTOR_H
#define GRPCPP_SUPPORT_SERVER_INTERCEPTOR_H
#include <atomic>
#include <vector>
#include <grpc/support/log.h>
#include <grpcpp/impl/rpc_method.h>
#include <grpcpp/support/interceptor.h>
#include <grpcpp/support/string_ref.h>
#include <atomic>
#include <vector>
#include "absl/log/absl_check.h"
namespace grpc {
class ServerContextBase;
namespace internal {
@@ -100,7 +101,7 @@ class ServerRpcInfo {
// Runs interceptor at pos \a pos.
void RunInterceptor(
experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) {
GPR_ASSERT(pos < interceptors_.size());
ABSL_CHECK_LT(pos, interceptors_.size());
interceptors_[pos]->Intercept(interceptor_methods);
}

View File

@@ -19,6 +19,7 @@
#ifndef GRPCPP_SUPPORT_STRING_REF_H
#define GRPCPP_SUPPORT_STRING_REF_H
#include <grpcpp/support/config.h>
#include <string.h>
#include <algorithm>
@@ -26,8 +27,6 @@
#include <iostream>
#include <iterator>
#include <grpcpp/support/config.h>
namespace grpc {
/// This class is a non owning reference to a string.

View File

@@ -19,7 +19,6 @@
#ifndef GRPCPP_SUPPORT_SYNC_STREAM_H
#define GRPCPP_SUPPORT_SYNC_STREAM_H
#include <grpc/support/log.h>
#include <grpcpp/client_context.h>
#include <grpcpp/completion_queue.h>
#include <grpcpp/impl/call.h>
@@ -28,6 +27,8 @@
#include <grpcpp/server_context.h>
#include <grpcpp/support/status.h>
#include "absl/log/absl_check.h"
namespace grpc {
namespace internal {
@@ -184,7 +185,7 @@ class ClientReader final : public ClientReaderInterface<R> {
/// the server will be accessible through the \a ClientContext used to
/// construct this object.
void WaitForInitialMetadata() override {
GPR_ASSERT(!context_->initial_metadata_received_);
ABSL_CHECK(!context_->initial_metadata_received_);
grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata> ops;
ops.RecvInitialMetadata(context_);
@@ -230,7 +231,7 @@ class ClientReader final : public ClientReaderInterface<R> {
grpc::Status status;
ops.ClientRecvStatus(context_, &status);
call_.PerformOps(&ops);
GPR_ASSERT(cq_.Pluck(&ops));
ABSL_CHECK(cq_.Pluck(&ops));
return status;
}
@@ -259,7 +260,7 @@ class ClientReader final : public ClientReaderInterface<R> {
ops.SendInitialMetadata(&context->send_initial_metadata_,
context->initial_metadata_flags());
// TODO(ctiller): don't assert
GPR_ASSERT(ops.SendMessagePtr(&request).ok());
ABSL_CHECK(ops.SendMessagePtr(&request).ok());
ops.ClientSendClose();
call_.PerformOps(&ops);
cq_.Pluck(&ops);
@@ -306,7 +307,7 @@ class ClientWriter : public ClientWriterInterface<W> {
/// Once complete, the initial metadata read from the server will be
/// accessible through the \a ClientContext used to construct this object.
void WaitForInitialMetadata() {
GPR_ASSERT(!context_->initial_metadata_received_);
ABSL_CHECK(!context_->initial_metadata_received_);
grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata> ops;
ops.RecvInitialMetadata(context_);
@@ -364,7 +365,7 @@ class ClientWriter : public ClientWriterInterface<W> {
}
finish_ops_.ClientRecvStatus(context_, &status);
call_.PerformOps(&finish_ops_);
GPR_ASSERT(cq_.Pluck(&finish_ops_));
ABSL_CHECK(cq_.Pluck(&finish_ops_));
return status;
}
@@ -455,7 +456,7 @@ class ClientReaderWriter final : public ClientReaderWriterInterface<W, R> {
/// Once complete, the initial metadata read from the server will be
/// accessible through the \a ClientContext used to construct this object.
void WaitForInitialMetadata() override {
GPR_ASSERT(!context_->initial_metadata_received_);
ABSL_CHECK(!context_->initial_metadata_received_);
grpc::internal::CallOpSet<grpc::internal::CallOpRecvInitialMetadata> ops;
ops.RecvInitialMetadata(context_);
@@ -536,7 +537,7 @@ class ClientReaderWriter final : public ClientReaderWriterInterface<W, R> {
grpc::Status status;
ops.ClientRecvStatus(context_, &status);
call_.PerformOps(&ops);
GPR_ASSERT(cq_.Pluck(&ops));
ABSL_CHECK(cq_.Pluck(&ops));
return status;
}
@@ -583,7 +584,7 @@ class ServerReader final : public ServerReaderInterface<R> {
/// for semantics. Note that initial metadata will be affected by the
/// \a ServerContext associated with this call.
void SendInitialMetadata() override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata> ops;
ops.SendInitialMetadata(&ctx_->initial_metadata_,
@@ -640,7 +641,7 @@ class ServerWriter final : public ServerWriterInterface<W> {
/// Note that initial metadata will be affected by the
/// \a ServerContext associated with this call.
void SendInitialMetadata() override {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata> ops;
ops.SendInitialMetadata(&ctx_->initial_metadata_,
@@ -713,7 +714,7 @@ class ServerReaderWriterBody final {
: call_(call), ctx_(ctx) {}
void SendInitialMetadata() {
GPR_ASSERT(!ctx_->sent_initial_metadata_);
ABSL_CHECK(!ctx_->sent_initial_metadata_);
grpc::internal::CallOpSet<grpc::internal::CallOpSendInitialMetadata> ops;
ops.SendInitialMetadata(&ctx_->initial_metadata_,

View File

@@ -19,11 +19,11 @@
#ifndef GRPCPP_SUPPORT_TIME_H
#define GRPCPP_SUPPORT_TIME_H
#include <chrono>
#include <grpc/impl/grpc_types.h>
#include <grpcpp/support/config.h>
#include <chrono>
namespace grpc {
/// If you are trying to use CompletionQueue::AsyncNext with a time class that

View File

@@ -19,9 +19,9 @@
#define GRPCPP_VERSION_INFO_H
#define GRPC_CPP_VERSION_MAJOR 1
#define GRPC_CPP_VERSION_MINOR 62
#define GRPC_CPP_VERSION_PATCH 1
#define GRPC_CPP_VERSION_MINOR 69
#define GRPC_CPP_VERSION_PATCH 0
#define GRPC_CPP_VERSION_TAG ""
#define GRPC_CPP_VERSION_STRING "1.62.1"
#define GRPC_CPP_VERSION_STRING "1.69.0"
#endif // GRPCPP_VERSION_INFO_H

View File

@@ -20,7 +20,6 @@
#define GRPCPP_XDS_SERVER_BUILDER_H
#include <grpc/support/port_platform.h>
#include <grpcpp/server_builder.h>
namespace grpc {