GRPC Core  9.0.0
server_address.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 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_EXT_FILTERS_CLIENT_CHANNEL_SERVER_ADDRESS_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVER_ADDRESS_H
21 
23 
27 
28 // Channel arg key for a bool indicating whether an address is a grpclb
29 // load balancer (as opposed to a backend).
30 #define GRPC_ARG_ADDRESS_IS_BALANCER "grpc.address_is_balancer"
31 
32 // Channel arg key for a string indicating an address's balancer name.
33 #define GRPC_ARG_ADDRESS_BALANCER_NAME "grpc.address_balancer_name"
34 
35 namespace grpc_core {
36 
37 //
38 // ServerAddress
39 //
40 
41 // A server address is a grpc_resolved_address with an associated set of
42 // channel args. Any args present here will be merged into the channel
43 // args when a subchannel is created for this address.
45  public:
46  // Takes ownership of args.
48  ServerAddress(const void* address, size_t address_len,
50 
52 
53  // Copyable.
55  : address_(other.address_), args_(grpc_channel_args_copy(other.args_)) {}
57  address_ = other.address_;
59  args_ = grpc_channel_args_copy(other.args_);
60  return *this;
61  }
62 
63  // Movable.
65  : address_(other.address_), args_(other.args_) {
66  other.args_ = nullptr;
67  }
69  address_ = other.address_;
71  args_ = other.args_;
72  other.args_ = nullptr;
73  return *this;
74  }
75 
76  bool operator==(const ServerAddress& other) const;
77 
78  const grpc_resolved_address& address() const { return address_; }
79  const grpc_channel_args* args() const { return args_; }
80 
81  bool IsBalancer() const;
82 
83  private:
84  grpc_resolved_address address_;
85  grpc_channel_args* args_;
86 };
87 
88 //
89 // ServerAddressList
90 //
91 
93 
94 } // namespace grpc_core
95 
96 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVER_ADDRESS_H */
ServerAddress & operator=(ServerAddress &&other)
Definition: server_address.h:68
An array of arguments that can be passed around.
Definition: grpc_types.h:132
grpc_channel_args * grpc_channel_args_copy(const grpc_channel_args *src)
Copy the arguments in src into a new instance.
Definition: channel_args.cc:116
Definition: resolve_address.h:44
Round Robin Policy.
Definition: backend_metric.cc:24
void grpc_channel_args_destroy(grpc_channel_args *a)
Destroy arguments created by grpc_channel_args_copy.
Definition: channel_args.cc:197
ServerAddress(const grpc_resolved_address &address, grpc_channel_args *args)
Definition: server_address.cc:29
ServerAddress(ServerAddress &&other)
Definition: server_address.h:64
const grpc_channel_args * args() const
Definition: server_address.h:79
~ServerAddress()
Definition: server_address.h:51
ServerAddress & operator=(const ServerAddress &other)
Definition: server_address.h:56
bool operator==(const ServerAddress &other) const
Definition: server_address.cc:40
ServerAddress(const ServerAddress &other)
Definition: server_address.h:54
const grpc_resolved_address & address() const
Definition: server_address.h:78
bool IsBalancer() const
Definition: server_address.cc:46
Definition: server_address.h:44
InlinedVector< ServerAddress, 1 > ServerAddressList
Definition: server_address.h:92