GRPC C++  1.39.1
channel.h
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 
19 #ifndef GRPC_CORE_LIB_SURFACE_CHANNEL_H
20 #define GRPC_CORE_LIB_SURFACE_CHANNEL_H
21 
23 
24 #include <map>
25 
32 
33 grpc_channel* grpc_channel_create(const char* target,
34  const grpc_channel_args* args,
35  grpc_channel_stack_type channel_stack_type,
36  grpc_transport* optional_transport,
37  grpc_resource_user* resource_user = nullptr,
38  grpc_error_handle* error = nullptr);
39 
43 
46  grpc_channel_stack_type channel_stack_type,
47  grpc_error_handle* error = nullptr);
48 
58  grpc_channel* channel, grpc_call* parent_call, uint32_t propagation_mask,
59  grpc_pollset_set* pollset_set, const grpc_slice& method,
60  const grpc_slice* host, grpc_millis deadline, void* reserved);
61 
64 
66  grpc_channel* channel);
67 
69 void grpc_channel_update_call_size_estimate(grpc_channel* channel, size_t size);
70 
71 namespace grpc_core {
72 
74  // The method and host are kept as part of this struct just to manage their
75  // lifetime since they must outlive the mdelem contents.
76  std::string method;
77  std::string host;
78 
81 
82  explicit RegisteredCall(const char* method_arg, const char* host_arg);
83  // TODO(vjpai): delete copy constructor once all supported compilers allow
84  // std::map value_type to be MoveConstructible.
85  RegisteredCall(const RegisteredCall& other);
86  RegisteredCall(RegisteredCall&& other) noexcept;
89 
91 };
92 
95  // The map key should be owned strings rather than unowned char*'s to
96  // guarantee that it outlives calls on the core channel (which may outlast the
97  // C++ or other wrapped language Channel that registered these calls).
98  std::map<std::pair<std::string, std::string>, RegisteredCall> map
100  int method_registration_attempts ABSL_GUARDED_BY(mu) = 0;
101 };
102 
103 } // namespace grpc_core
104 
105 struct grpc_channel {
108 
111 
112  // TODO(vjpai): Once the grpc_channel is allocated via new rather than malloc,
113  // expand the members of the CallRegistrationTable directly into
114  // the grpc_channel. For now it is kept separate so that all the
115  // manual constructing can be done with a single call rather than
116  // a separate manual construction for each field.
120 
121  char* target;
122 };
123 #define CHANNEL_STACK_FROM_CHANNEL(c) ((grpc_channel_stack*)((c) + 1))
124 
126  const grpc_channel* channel) {
127  return channel->compression_options;
128 }
129 
131  grpc_channel* channel) {
132  return CHANNEL_STACK_FROM_CHANNEL(channel);
133 }
134 
136  grpc_channel* channel) {
137  return channel->channelz_node.get();
138 }
139 
140 #ifndef NDEBUG
142  const char* reason) {
144 }
146  const char* reason) {
148 }
149 #define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \
150  grpc_channel_internal_ref(channel, reason)
151 #define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \
152  grpc_channel_internal_unref(channel, reason)
153 #else
154 inline void grpc_channel_internal_ref(grpc_channel* channel) {
156 }
157 inline void grpc_channel_internal_unref(grpc_channel* channel) {
159 }
160 #define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \
161  grpc_channel_internal_ref(channel)
162 #define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \
163  grpc_channel_internal_unref(channel)
164 #endif
165 
166 // Return the channel's compression options.
168  const grpc_channel* channel);
169 
170 // Ping the channels peer (load balanced channels will select one sub-channel to
171 // ping); if the channel is not connected, posts a failed.
173  void* tag, void* reserved);
174 
175 #endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_H */
#define GRPC_CHANNEL_STACK_REF(channel_stack, reason)
Definition: channel_stack.h:247
#define GRPC_CHANNEL_STACK_UNREF(channel_stack, reason)
Definition: channel_stack.h:249
grpc_channel_stack_type
Definition: channel_stack_type.h:26
Definition: sync.h:59
T * get() const
Definition: ref_counted_ptr.h:147
Definition: channelz.h:174
int64_t grpc_millis
Definition: exec_ctx.h:37
intptr_t gpr_atm
Definition: atm_gcc_atomic.h:30
grpc_error_handle error
Definition: lame_client.cc:54
Round Robin Policy.
Definition: backend_metric.cc:26
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
void grpc_channel_ping(grpc_channel *channel, grpc_completion_queue *cq, void *tag, void *reserved)
Definition: channel_ping.cc:47
size_t grpc_channel_get_call_size_estimate(grpc_channel *channel)
Definition: channel.cc:284
grpc_compression_options grpc_channel_compression_options(const grpc_channel *channel)
Definition: channel.h:125
grpc_channel * grpc_channel_create(const char *target, const grpc_channel_args *args, grpc_channel_stack_type channel_stack_type, grpc_transport *optional_transport, grpc_resource_user *resource_user=nullptr, grpc_error_handle *error=nullptr)
Definition: channel.cc:223
#define CHANNEL_STACK_FROM_CHANNEL(c)
Definition: channel.h:123
void grpc_channel_update_call_size_estimate(grpc_channel *channel, size_t size)
Definition: channel.cc:298
grpc_core::channelz::ChannelNode * grpc_channel_get_channelz_node(grpc_channel *channel)
Definition: channel.h:135
void grpc_channel_internal_unref(grpc_channel *channel, const char *reason)
Definition: channel.h:145
grpc_channel * grpc_channel_create_with_builder(grpc_channel_stack_builder *builder, grpc_channel_stack_type channel_stack_type, grpc_error_handle *error=nullptr)
Definition: channel.cc:59
grpc_call * grpc_channel_create_pollset_set_call(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_pollset_set *pollset_set, const grpc_slice &method, const grpc_slice *host, grpc_millis deadline, void *reserved)
Create a call given a grpc_channel, in order to call method.
Definition: channel.cc:397
void grpc_channel_destroy_internal(grpc_channel *channel)
The same as grpc_channel_destroy, but doesn't create an ExecCtx, and so is safe to use from within co...
Definition: channel.cc:520
grpc_channel_stack * grpc_channel_get_channel_stack(grpc_channel *channel)
Get a (borrowed) pointer to this channels underlying channel stack.
Definition: channel.h:130
void grpc_channel_internal_ref(grpc_channel *channel, const char *reason)
Definition: channel.h:141
Definition: call.cc:139
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Definition: channel_stack_builder.cc:36
Definition: channel_stack.h:182
Definition: channel.h:105
grpc_core::RefCountedPtr< grpc_core::channelz::ChannelNode > channelz_node
Definition: channel.h:119
gpr_atm call_size_estimate
Definition: channel.h:109
int is_client
Definition: channel.h:106
grpc_resource_user * resource_user
Definition: channel.h:110
grpc_compression_options compression_options
Definition: channel.h:107
char * target
Definition: channel.h:121
grpc_core::ManualConstructor< grpc_core::CallRegistrationTable > registration_table
Definition: channel.h:118
Definition: completion_queue.cc:339
Definition: compression_types.h:79
Definition: channel.h:93
grpc_core::Mutex mu
Definition: channel.h:94
std::map< std::pair< std::string, std::string >, RegisteredCall > map ABSL_GUARDED_BY(mu)
int method_registration_attempts ABSL_GUARDED_BY(mu)=0
Definition: channel.h:73
grpc_mdelem path
Definition: channel.h:79
RegisteredCall & operator=(const RegisteredCall &)=delete
std::string host
Definition: channel.h:77
RegisteredCall(const char *method_arg, const char *host_arg)
Definition: channel.cc:412
std::string method
Definition: channel.h:76
grpc_mdelem authority
Definition: channel.h:80
RegisteredCall & operator=(RegisteredCall &&)=delete
~RegisteredCall()
Definition: channel.cc:443
Definition: error_internal.h:41
Definition: metadata.h:98
Definition: resource_quota.cc:65
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1].
Definition: slice.h:60
Definition: transport_impl.h:66
Definition: call.cc:118