|
|
|
@ -24,15 +24,16 @@ |
|
|
|
|
#include <string> |
|
|
|
|
#include <utility> |
|
|
|
|
|
|
|
|
|
#include "absl/status/status.h" |
|
|
|
|
#include "absl/status/statusor.h" |
|
|
|
|
|
|
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
|
#include <grpc/support/log.h> |
|
|
|
|
|
|
|
|
|
#include "src/core/lib/channel/channel_args.h" |
|
|
|
|
#include "src/core/lib/channel/channel_stack.h" |
|
|
|
|
#include "src/core/lib/channel/channel_stack_builder_impl.h" |
|
|
|
|
#include "src/core/lib/debug/trace.h" |
|
|
|
|
#include "src/core/lib/gpr/alloc.h" |
|
|
|
|
#include "src/core/lib/surface/channel_stack_type.h" |
|
|
|
|
#include "src/core/lib/surface/lame_client.h" |
|
|
|
|
|
|
|
|
|
// Conversion between call and call stack.
|
|
|
|
@ -63,8 +64,8 @@ DynamicFilters::Call::Call(Args args, grpc_error_handle* error) |
|
|
|
|
args.arena, /* arena */ |
|
|
|
|
args.call_combiner /* call_combiner */ |
|
|
|
|
}; |
|
|
|
|
*error = grpc_call_stack_init(channel_stack_->channel_stack_, 1, Destroy, |
|
|
|
|
this, &call_args); |
|
|
|
|
*error = grpc_call_stack_init(channel_stack_->channel_stack_.get(), 1, |
|
|
|
|
Destroy, this, &call_args); |
|
|
|
|
if (GPR_UNLIKELY(!GRPC_ERROR_IS_NONE(*error))) { |
|
|
|
|
gpr_log(GPR_ERROR, "error: %s", grpc_error_std_string(*error).c_str()); |
|
|
|
|
return; |
|
|
|
@ -136,58 +137,30 @@ void DynamicFilters::Call::IncrementRefCount(const DebugLocation& /*location*/, |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
void DestroyChannelStack(void* arg, grpc_error_handle /*error*/) { |
|
|
|
|
grpc_channel_stack* channel_stack = static_cast<grpc_channel_stack*>(arg); |
|
|
|
|
grpc_channel_stack_destroy(channel_stack); |
|
|
|
|
gpr_free(channel_stack); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::pair<grpc_channel_stack*, grpc_error_handle> CreateChannelStack( |
|
|
|
|
const grpc_channel_args* args, |
|
|
|
|
std::vector<const grpc_channel_filter*> filters) { |
|
|
|
|
// Allocate memory for channel stack.
|
|
|
|
|
const size_t channel_stack_size = |
|
|
|
|
grpc_channel_stack_size(filters.data(), filters.size()); |
|
|
|
|
grpc_channel_stack* channel_stack = |
|
|
|
|
reinterpret_cast<grpc_channel_stack*>(gpr_zalloc(channel_stack_size)); |
|
|
|
|
// Initialize stack.
|
|
|
|
|
grpc_error_handle error = grpc_channel_stack_init( |
|
|
|
|
/*initial_refs=*/1, DestroyChannelStack, channel_stack, filters.data(), |
|
|
|
|
filters.size(), args, "DynamicFilters", channel_stack); |
|
|
|
|
if (!GRPC_ERROR_IS_NONE(error)) { |
|
|
|
|
gpr_log(GPR_ERROR, "error initializing client internal stack: %s", |
|
|
|
|
grpc_error_std_string(error).c_str()); |
|
|
|
|
grpc_channel_stack_destroy(channel_stack); |
|
|
|
|
gpr_free(channel_stack); |
|
|
|
|
return {nullptr, error}; |
|
|
|
|
absl::StatusOr<RefCountedPtr<grpc_channel_stack>> CreateChannelStack( |
|
|
|
|
const ChannelArgs& args, std::vector<const grpc_channel_filter*> filters) { |
|
|
|
|
ChannelStackBuilderImpl builder("DynamicFilters", GRPC_CLIENT_DYNAMIC); |
|
|
|
|
builder.SetChannelArgs(args); |
|
|
|
|
for (auto filter : filters) { |
|
|
|
|
builder.AppendFilter(filter); |
|
|
|
|
} |
|
|
|
|
return {channel_stack, GRPC_ERROR_NONE}; |
|
|
|
|
return builder.Build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
RefCountedPtr<DynamicFilters> DynamicFilters::Create( |
|
|
|
|
const grpc_channel_args* args, |
|
|
|
|
std::vector<const grpc_channel_filter*> filters) { |
|
|
|
|
const ChannelArgs& args, std::vector<const grpc_channel_filter*> filters) { |
|
|
|
|
// Attempt to create channel stack from requested filters.
|
|
|
|
|
auto p = CreateChannelStack(args, std::move(filters)); |
|
|
|
|
if (!GRPC_ERROR_IS_NONE(p.second)) { |
|
|
|
|
if (!p.ok()) { |
|
|
|
|
// Channel stack creation failed with requested filters.
|
|
|
|
|
// Create with lame filter instead.
|
|
|
|
|
grpc_error_handle error = p.second; |
|
|
|
|
grpc_arg error_arg = MakeLameClientErrorArg(&error); |
|
|
|
|
grpc_channel_args* new_args = |
|
|
|
|
grpc_channel_args_copy_and_add(args, &error_arg, 1); |
|
|
|
|
GRPC_ERROR_UNREF(error); |
|
|
|
|
p = CreateChannelStack(new_args, {&LameClientFilter::kFilter}); |
|
|
|
|
GPR_ASSERT(GRPC_ERROR_IS_NONE(p.second)); |
|
|
|
|
grpc_channel_args_destroy(new_args); |
|
|
|
|
auto error = p.status(); |
|
|
|
|
p = CreateChannelStack(args.Set(MakeLameClientErrorArg(&error)), |
|
|
|
|
{&LameClientFilter::kFilter}); |
|
|
|
|
} |
|
|
|
|
return MakeRefCounted<DynamicFilters>(p.first); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DynamicFilters::~DynamicFilters() { |
|
|
|
|
GRPC_CHANNEL_STACK_UNREF(channel_stack_, "~DynamicFilters"); |
|
|
|
|
return MakeRefCounted<DynamicFilters>(std::move(p.value())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RefCountedPtr<DynamicFilters::Call> DynamicFilters::CreateCall( |
|
|
|
|