lame_client.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
22 
23 #include <memory>
24 #include <utility>
25 
26 #include "absl/memory/memory.h"
27 #include "absl/status/statusor.h"
28 
29 #include <grpc/grpc.h>
31 #include <grpc/status.h>
32 #include <grpc/support/log.h>
33 
52 
53 // Avoid some IWYU confusion:
54 // IWYU pragma: no_include "src/core/lib/gprpp/orphanable.h"
55 
56 #define GRPC_ARG_LAME_FILTER_ERROR "grpc.lame_filter_error"
57 
58 namespace grpc_core {
59 
62  kFilterIsLast>("lame-client");
63 
66  return LameClientFilter(
68 }
69 
72 
74  : state_tracker("lame_client", GRPC_CHANNEL_SHUTDOWN) {}
75 
79 }
80 
82 
84  {
85  MutexLock lock(&state_->mu);
86  if (op->start_connectivity_watch != nullptr) {
87  state_->state_tracker.AddWatcher(op->start_connectivity_watch_state,
88  std::move(op->start_connectivity_watch));
89  }
90  if (op->stop_connectivity_watch != nullptr) {
91  state_->state_tracker.RemoveWatcher(op->stop_connectivity_watch);
92  }
93  }
94  if (op->send_ping.on_initiate != nullptr) {
95  ExecCtx::Run(DEBUG_LOCATION, op->send_ping.on_initiate,
96  GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel"));
97  }
98  if (op->send_ping.on_ack != nullptr) {
99  ExecCtx::Run(DEBUG_LOCATION, op->send_ping.on_ack,
100  GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel"));
101  }
102  GRPC_ERROR_UNREF(op->disconnect_with_error);
103  if (op->on_consumed != nullptr) {
105  }
106  return true;
107 }
108 
109 namespace {
110 
111 // Channel arg vtable for a grpc_error_handle.
112 void* ErrorCopy(void* p) {
113  return new absl::Status(*static_cast<absl::Status*>(p));
114 }
115 void ErrorDestroy(void* p) { delete static_cast<absl::Status*>(p); }
116 int ErrorCompare(void* p, void* q) { return QsortCompare(p, q); }
117 
118 const grpc_arg_pointer_vtable kLameFilterErrorArgVtable = {
119  ErrorCopy, ErrorDestroy, ErrorCompare};
120 
121 } // namespace
122 
125  const_cast<char*>(GRPC_ARG_LAME_FILTER_ERROR), error,
126  &kLameFilterErrorArgVtable);
127 }
128 
129 } // namespace grpc_core
130 
132  grpc_status_code error_code,
133  const char* error_message) {
136  "grpc_lame_client_channel_create(target=%s, error_code=%d, "
137  "error_message=%s)",
138  3, (target, (int)error_code, error_message));
139  if (error_code == GRPC_STATUS_OK) error_code = GRPC_STATUS_UNKNOWN;
143  .PreconditionChannelArgs(nullptr)
146  new absl::Status(static_cast<absl::StatusCode>(error_code),
147  error_message),
148  &grpc_core::kLameFilterErrorArgVtable));
150  GRPC_CLIENT_LAME_CHANNEL, nullptr);
151  GPR_ASSERT(channel.ok());
152  return channel->release()->c_ptr();
153 }
grpc_arg
Definition: grpc_types.h:103
trace.h
GRPC_ERROR_NONE
#define GRPC_ERROR_NONE
Definition: error.h:234
log.h
core_configuration.h
lame_client.h
connectivity_state.h
grpc_core::LameClientFilter::kFilter
static const grpc_channel_filter kFilter
Definition: lame_client.h:49
grpc_core::LameClientFilter::GetChannelInfo
bool GetChannelInfo(const grpc_channel_info *) override
Definition: lame_client.cc:81
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
grpc_core::MakeLameClientErrorArg
grpc_arg MakeLameClientErrorArg(grpc_error_handle *error)
Definition: lame_client.cc:123
useful.h
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_status_code
grpc_status_code
Definition: include/grpc/impl/codegen/status.h:28
promise_based_filter.h
grpc_core::LameClientFilter::state_
std::unique_ptr< State > state_
Definition: lame_client.h:67
absl::make_unique
memory_internal::MakeUniqueResult< T >::scalar make_unique(Args &&... args)
Definition: third_party/abseil-cpp/absl/memory/memory.h:168
grpc_core::ServerMetadataHandle
MetadataHandle< ServerMetadata > ServerMetadataHandle
Definition: transport.h:141
grpc_core::LameClientFilter::error_
absl::Status error_
Definition: lame_client.h:61
grpc_arg_pointer_vtable
Definition: grpc_types.h:85
grpc_transport_op
Definition: transport.h:452
channel_args_preconditioning.h
status.h
DEBUG_LOCATION
#define DEBUG_LOCATION
Definition: debug_location.h:41
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::NextPromiseFactory
std::function< ArenaPromise< ServerMetadataHandle >(CallArgs)> NextPromiseFactory
Definition: transport.h:165
GRPC_STATUS_OK
@ GRPC_STATUS_OK
Definition: include/grpc/impl/codegen/status.h:30
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
GRPC_ARG_LAME_FILTER_ERROR
#define GRPC_ARG_LAME_FILTER_ERROR
Definition: lame_client.cc:56
grpc_core::CoreConfiguration::Get
static const CoreConfiguration & Get()
Definition: core_configuration.h:82
grpc_core::MakePromiseBasedFilter
absl::enable_if_t< std::is_base_of< ChannelFilter, F >::value, grpc_channel_filter > MakePromiseBasedFilter(const char *name)
Definition: promise_based_filter.h:487
channel_stack.h
grpc.h
connectivity_state.h
grpc_core::CallArgs
Definition: transport.h:159
grpc_core::LameClientFilter::State::State
State()
Definition: lame_client.cc:73
grpc_core::LameClientFilter::MakeCallPromise
ArenaPromise< ServerMetadataHandle > MakeCallPromise(CallArgs call_args, NextPromiseFactory next_promise_factory) override
Definition: lame_client.cc:76
grpc_core::FilterEndpoint::kClient
@ kClient
channel_stack_type.h
grpc_core::LameClientFilter::LameClientFilter
LameClientFilter(absl::Status error)
Definition: lame_client.cc:70
grpc_core::CoreConfiguration::channel_args_preconditioning
const ChannelArgsPreconditioning & channel_args_preconditioning() const
Definition: core_configuration.h:139
grpc_core::ExecCtx
Definition: exec_ctx.h:97
promise.h
grpc_channel_filter
Definition: channel_stack.h:111
GRPC_ERROR_CREATE_FROM_STATIC_STRING
#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc)
Definition: error.h:291
grpc_lame_client_channel_create
grpc_channel * grpc_lame_client_channel_create(const char *target, grpc_status_code error_code, const char *error_message)
Definition: lame_client.cc:131
grpc_core::ChannelArgs::Set
GRPC_MUST_USE_RESULT ChannelArgs Set(absl::string_view name, Value value) const
Definition: channel_args.cc:113
absl::Status
ABSL_NAMESPACE_BEGIN class ABSL_MUST_USE_RESULT Status
Definition: abseil-cpp/absl/status/internal/status_internal.h:36
grpc_core::kFilterIsLast
static constexpr uint8_t kFilterIsLast
Definition: promise_based_filter.h:115
grpc_core::LameClientFilter::StartTransportOp
bool StartTransportOp(grpc_transport_op *) override
Definition: lame_client.cc:83
debug_location.h
absl::StatusCode
StatusCode
Definition: third_party/abseil-cpp/absl/status/status.h:92
grpc_core::ArenaPromise
Definition: arena_promise.h:152
grpc_core::QsortCompare
int QsortCompare(const T &a, const T &b)
Definition: useful.h:95
grpc_core::ChannelArgs::Pointer
Definition: channel_args.h:113
exec_ctx
grpc_core::ExecCtx exec_ctx
Definition: end2end_binder_transport_test.cc:75
poll.h
absl::Status
Definition: third_party/abseil-cpp/absl/status/status.h:424
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
exec_ctx.h
GRPC_ERROR_UNREF
#define GRPC_ERROR_UNREF(err)
Definition: error.h:262
grpc_core::ChannelArgs
Definition: channel_args.h:111
grpc_core::ExecCtx::Run
static void Run(const DebugLocation &location, grpc_closure *closure, grpc_error_handle error)
Definition: exec_ctx.cc:98
ref_counted_ptr.h
state_
grpc_connectivity_state state_
Definition: channel_connectivity.cc:213
grpc_channel
struct grpc_channel grpc_channel
Definition: grpc_types.h:62
transport.h
channel_args.h
api_trace.h
grpc_core::Immediate
promise_detail::Immediate< T > Immediate(T value)
Definition: promise/promise.h:73
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
GRPC_CHANNEL_SHUTDOWN
@ GRPC_CHANNEL_SHUTDOWN
Definition: include/grpc/impl/codegen/connectivity_state.h:40
absl::StatusOr
Definition: abseil-cpp/absl/status/statusor.h:187
error_
grpc_error_handle error_
Definition: message_decompress_filter.cc:112
grpc_error
Definition: error_internal.h:42
grpc_core::LameClientFilter::Create
static absl::StatusOr< LameClientFilter > Create(ChannelArgs args, ChannelFilter::Args filter_args)
Definition: lame_client.cc:64
grpc_channel_info
Definition: grpc_types.h:720
grpc_channel_arg_pointer_create
grpc_arg grpc_channel_arg_pointer_create(char *name, void *value, const grpc_arg_pointer_vtable *vtable)
Definition: channel_args.cc:492
grpc_core::ChannelFilter::Args
Definition: promise_based_filter.h:64
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
setup.target
target
Definition: third_party/bloaty/third_party/protobuf/python/setup.py:179
grpc_core::ChannelArgsPreconditioning::PreconditionChannelArgs
ChannelArgs PreconditionChannelArgs(const grpc_channel_args *args) const
Definition: channel_args_preconditioning.cc:34
grpc_core::Channel::Create
static absl::StatusOr< RefCountedPtr< Channel > > Create(const char *target, ChannelArgs args, grpc_channel_stack_type channel_stack_type, grpc_transport *optional_transport)
Definition: channel.cc:202
sync.h
GRPC_API_TRACE
#define GRPC_API_TRACE(fmt, nargs, args)
Definition: api_trace.h:48
GRPC_STATUS_UNKNOWN
@ GRPC_STATUS_UNKNOWN
Definition: include/grpc/impl/codegen/status.h:40
grpc_core::LameClientFilter::State
Definition: lame_client.h:62
GRPC_CLIENT_LAME_CHANNEL
@ GRPC_CLIENT_LAME_CHANNEL
Definition: channel_stack_type.h:31
channel.h
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:14