|
|
|
@ -58,23 +58,36 @@ |
|
|
|
|
#include "src/core/lib/surface/channel_init.h" |
|
|
|
|
#include "src/core/lib/surface/channel_stack_type.h" |
|
|
|
|
#include "src/core/lib/surface/init_internally.h" |
|
|
|
|
#include "src/core/lib/transport/call_factory.h" |
|
|
|
|
#include "src/core/lib/transport/transport.h" |
|
|
|
|
|
|
|
|
|
// IWYU pragma: no_include <type_traits>
|
|
|
|
|
|
|
|
|
|
namespace grpc_core { |
|
|
|
|
|
|
|
|
|
GrpcChannel::GrpcChannel(bool is_client, bool is_promising, std::string target, |
|
|
|
|
const ChannelArgs& channel_args, |
|
|
|
|
grpc_compression_options compression_options, |
|
|
|
|
RefCountedPtr<grpc_channel_stack> channel_stack) |
|
|
|
|
: Channel(channel_args), |
|
|
|
|
is_client_(is_client), |
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
class NotReallyACallFactory final : public CallFactory { |
|
|
|
|
public: |
|
|
|
|
using CallFactory::CallFactory; |
|
|
|
|
CallInitiator CreateCall(ClientMetadataHandle md, Arena* arena) { |
|
|
|
|
Crash("NotReallyACallFactory::CreateCall should never be called"); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
Channel::Channel(bool is_client, bool is_promising, std::string target, |
|
|
|
|
const ChannelArgs& channel_args, |
|
|
|
|
grpc_compression_options compression_options, |
|
|
|
|
RefCountedPtr<grpc_channel_stack> channel_stack) |
|
|
|
|
: is_client_(is_client), |
|
|
|
|
is_promising_(is_promising), |
|
|
|
|
compression_options_(compression_options), |
|
|
|
|
channelz_node_(channel_args.GetObjectRef<channelz::ChannelNode>()), |
|
|
|
|
target_(std::move(target)), |
|
|
|
|
channel_stack_(std::move(channel_stack)) { |
|
|
|
|
channel_stack_(std::move(channel_stack)), |
|
|
|
|
call_factory_(MakeRefCounted<NotReallyACallFactory>(channel_args)) { |
|
|
|
|
// We need to make sure that grpc_shutdown() does not shut things down
|
|
|
|
|
// until after the channel is destroyed. However, the channel may not
|
|
|
|
|
// actually be destroyed by the time grpc_channel_destroy() returns,
|
|
|
|
@ -103,7 +116,7 @@ GrpcChannel::GrpcChannel(bool is_client, bool is_promising, std::string target, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
absl::StatusOr<RefCountedPtr<GrpcChannel>> GrpcChannel::CreateWithBuilder( |
|
|
|
|
absl::StatusOr<RefCountedPtr<Channel>> Channel::CreateWithBuilder( |
|
|
|
|
ChannelStackBuilder* builder) { |
|
|
|
|
auto channel_args = builder->channel_args(); |
|
|
|
|
if (builder->channel_stack_type() == GRPC_SERVER_CHANNEL) { |
|
|
|
@ -147,7 +160,7 @@ absl::StatusOr<RefCountedPtr<GrpcChannel>> GrpcChannel::CreateWithBuilder( |
|
|
|
|
*enabled_algorithms_bitset | 1 /* always support no compression */; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return RefCountedPtr<GrpcChannel>(new GrpcChannel( |
|
|
|
|
return RefCountedPtr<Channel>(new Channel( |
|
|
|
|
grpc_channel_stack_type_is_client(builder->channel_stack_type()), |
|
|
|
|
builder->IsPromising(), std::string(builder->target()), channel_args, |
|
|
|
|
compression_options, std::move(*r))); |
|
|
|
@ -169,7 +182,7 @@ const grpc_arg_pointer_vtable channelz_node_arg_vtable = { |
|
|
|
|
channelz_node_copy, channelz_node_destroy, channelz_node_cmp}; |
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
absl::StatusOr<RefCountedPtr<GrpcChannel>> GrpcChannel::Create( |
|
|
|
|
absl::StatusOr<RefCountedPtr<Channel>> Channel::Create( |
|
|
|
|
const char* target, ChannelArgs args, |
|
|
|
|
grpc_channel_stack_type channel_stack_type, Transport* optional_transport) { |
|
|
|
|
if (!args.GetString(GRPC_ARG_DEFAULT_AUTHORITY).has_value()) { |
|
|
|
@ -230,7 +243,7 @@ absl::StatusOr<RefCountedPtr<GrpcChannel>> GrpcChannel::Create( |
|
|
|
|
|
|
|
|
|
char* grpc_channel_get_target(grpc_channel* channel) { |
|
|
|
|
GRPC_API_TRACE("grpc_channel_get_target(channel=%p)", 1, (channel)); |
|
|
|
|
auto target = grpc_core::GrpcChannel::FromC(channel)->target(); |
|
|
|
|
auto target = grpc_core::Channel::FromC(channel)->target(); |
|
|
|
|
char* buffer = static_cast<char*>(gpr_zalloc(target.size() + 1)); |
|
|
|
|
memcpy(buffer, target.data(), target.size()); |
|
|
|
|
return buffer; |
|
|
|
@ -241,7 +254,7 @@ void grpc_channel_get_info(grpc_channel* channel, |
|
|
|
|
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_channel_element* elem = grpc_channel_stack_element( |
|
|
|
|
grpc_core::GrpcChannel::FromC(channel)->channel_stack(), 0); |
|
|
|
|
grpc_core::Channel::FromC(channel)->channel_stack(), 0); |
|
|
|
|
elem->filter->get_channel_info(elem, channel_info); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -253,7 +266,7 @@ void grpc_channel_reset_connect_backoff(grpc_channel* channel) { |
|
|
|
|
grpc_transport_op* op = grpc_make_transport_op(nullptr); |
|
|
|
|
op->reset_connect_backoff = true; |
|
|
|
|
grpc_channel_element* elem = grpc_channel_stack_element( |
|
|
|
|
grpc_core::GrpcChannel::FromC(channel)->channel_stack(), 0); |
|
|
|
|
grpc_core::Channel::FromC(channel)->channel_stack(), 0); |
|
|
|
|
elem->filter->start_transport_op(elem, op); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -262,8 +275,8 @@ static grpc_call* grpc_channel_create_call_internal( |
|
|
|
|
grpc_completion_queue* cq, grpc_pollset_set* pollset_set_alternative, |
|
|
|
|
grpc_core::Slice path, absl::optional<grpc_core::Slice> authority, |
|
|
|
|
grpc_core::Timestamp deadline, bool registered_method) { |
|
|
|
|
auto channel = grpc_core::GrpcChannel::FromC(c_channel) |
|
|
|
|
->RefAsSubclass<grpc_core::GrpcChannel>(); |
|
|
|
|
auto channel = |
|
|
|
|
grpc_core::Channel::FromC(c_channel)->RefAsSubclass<grpc_core::Channel>(); |
|
|
|
|
GPR_ASSERT(channel->is_client()); |
|
|
|
|
GPR_ASSERT(!(cq != nullptr && pollset_set_alternative != nullptr)); |
|
|
|
|
|
|
|
|
@ -348,13 +361,12 @@ void* grpc_channel_register_call(grpc_channel* channel, const char* method, |
|
|
|
|
GPR_ASSERT(!reserved); |
|
|
|
|
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
return grpc_core::GrpcChannel::FromC(channel)->RegisterCall(method, host); |
|
|
|
|
return grpc_core::Channel::FromC(channel)->RegisterCall(method, host); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
namespace grpc_core { |
|
|
|
|
|
|
|
|
|
RegisteredCall* GrpcChannel::RegisterCall(const char* method, |
|
|
|
|
const char* host) { |
|
|
|
|
RegisteredCall* Channel::RegisterCall(const char* method, const char* host) { |
|
|
|
|
MutexLock lock(®istration_table_.mu); |
|
|
|
|
auto key = std::make_pair(std::string(host != nullptr ? host : ""), |
|
|
|
|
std::string(method != nullptr ? method : "")); |
|
|
|
@ -402,8 +414,8 @@ grpc_call* grpc_channel_create_registered_call( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_channel_destroy_internal(grpc_channel* c_channel) { |
|
|
|
|
grpc_core::RefCountedPtr<grpc_core::GrpcChannel> channel( |
|
|
|
|
grpc_core::GrpcChannel::FromC(c_channel)); |
|
|
|
|
grpc_core::RefCountedPtr<grpc_core::Channel> channel( |
|
|
|
|
grpc_core::Channel::FromC(c_channel)); |
|
|
|
|
grpc_transport_op* op = grpc_make_transport_op(nullptr); |
|
|
|
|
grpc_channel_element* elem; |
|
|
|
|
GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (c_channel)); |
|
|
|
|