grpclb_balancer_addresses.cc
Go to the documentation of this file.
1 //
2 // Copyright 2019 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
18 
20 
21 #include <stddef.h>
22 
23 #include <memory>
24 
27 
28 // Channel arg key for the list of balancer addresses.
29 #define GRPC_ARG_GRPCLB_BALANCER_ADDRESSES "grpc.grpclb_balancer_addresses"
30 
31 namespace grpc_core {
32 
33 namespace {
34 
35 void* BalancerAddressesArgCopy(void* p) {
36  ServerAddressList* address_list = static_cast<ServerAddressList*>(p);
37  return new ServerAddressList(*address_list);
38 }
39 
40 void BalancerAddressesArgDestroy(void* p) {
41  ServerAddressList* address_list = static_cast<ServerAddressList*>(p);
42  delete address_list;
43 }
44 
45 int BalancerAddressesArgCmp(void* p, void* q) {
46  ServerAddressList* address_list1 = static_cast<ServerAddressList*>(p);
47  ServerAddressList* address_list2 = static_cast<ServerAddressList*>(q);
48  if (address_list1 == nullptr || address_list2 == nullptr) {
49  return QsortCompare(address_list1, address_list2);
50  }
51  if (address_list1->size() > address_list2->size()) return 1;
52  if (address_list1->size() < address_list2->size()) return -1;
53  for (size_t i = 0; i < address_list1->size(); ++i) {
54  int retval = (*address_list1)[i].Cmp((*address_list2)[i]);
55  if (retval != 0) return retval;
56  }
57  return 0;
58 }
59 
60 const grpc_arg_pointer_vtable kBalancerAddressesArgVtable = {
61  BalancerAddressesArgCopy, BalancerAddressesArgDestroy,
62  BalancerAddressesArgCmp};
63 
64 } // namespace
65 
67  const ServerAddressList* address_list) {
69  const_cast<char*>(GRPC_ARG_GRPCLB_BALANCER_ADDRESSES),
70  const_cast<ServerAddressList*>(address_list),
71  &kBalancerAddressesArgVtable);
72 }
73 
75  const grpc_channel_args& args) {
76  return grpc_channel_args_find_pointer<const ServerAddressList>(
77  &args, const_cast<char*>(GRPC_ARG_GRPCLB_BALANCER_ADDRESSES));
78 }
79 
80 } // namespace grpc_core
grpc_arg
Definition: grpc_types.h:103
grpc_core
Definition: call_metric_recorder.h:31
useful.h
GRPC_ARG_GRPCLB_BALANCER_ADDRESSES
#define GRPC_ARG_GRPCLB_BALANCER_ADDRESSES
Definition: grpclb_balancer_addresses.cc:29
grpc_arg_pointer_vtable
Definition: grpc_types.h:85
grpc_channel_args
Definition: grpc_types.h:132
grpc_core::CreateGrpclbBalancerAddressesArg
grpc_arg CreateGrpclbBalancerAddressesArg(const ServerAddressList *address_list)
Definition: grpclb_balancer_addresses.cc:66
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::FindGrpclbBalancerAddressesInChannelArgs
const ServerAddressList * FindGrpclbBalancerAddressesInChannelArgs(const grpc_channel_args &args)
Definition: grpclb_balancer_addresses.cc:74
grpc_core::ServerAddressList
std::vector< ServerAddress > ServerAddressList
Definition: server_address.h:120
grpclb_balancer_addresses.h
grpc_core::QsortCompare
int QsortCompare(const T &a, const T &b)
Definition: useful.h:95
channel_args.h
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
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:45