Skip to content

Commit db27dd3

Browse files
committed
resolve the conflicts with master
# Conflicts: # src/brpc/channel.cpp # src/brpc/details/naming_service_thread.cpp # src/brpc/details/naming_service_thread.h # src/brpc/socket_map.cpp # src/brpc/socket_map.h
2 parents 428bee6 + d92e7cf commit db27dd3

19 files changed

Lines changed: 241 additions & 48 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if(POLICY CMP0042)
4040
cmake_policy(SET CMP0042 NEW)
4141
endif()
4242

43-
set(BRPC_VERSION 1.15.0)
43+
set(BRPC_VERSION 1.16.0)
4444

4545
SET(CPACK_GENERATOR "DEB")
4646
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "brpc authors")

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module(
22
name = 'brpc',
3-
version = '1.15.0',
3+
version = '1.16.0',
44
compatibility_level = 1,
55
)
66

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Apache bRPC
2-
Copyright 2018-2025 The Apache Software Foundation
2+
Copyright 2018-2026 The Apache Software Foundation
33

44
This product includes software developed at
55
The Apache Software Foundation (http://www.apache.org/).

RELEASE_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.15.0
1+
1.16.0

package/rpm/brpc.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020
Name: brpc
21-
Version: 1.15.0
21+
Version: 1.16.0
2222
Release: 1%{?dist}
2323
Summary: Industrial-grade RPC framework using C++ Language.
2424

src/brpc/channel.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,27 @@ int Channel::InitSingle(const butil::EndPoint& server_addr_and_port,
340340
LOG(ERROR) << "Invalid port=" << port;
341341
return -1;
342342
}
343+
butil::EndPoint client_endpoint;
344+
if (!_options.client_host.empty() &&
345+
butil::str2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0 &&
346+
butil::hostname2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0) {
347+
LOG(ERROR) << "Invalid client host=`" << _options.client_host << '\'';
348+
return -1;
349+
}
343350
_server_address = server_addr_and_port;
344351
const ChannelSignature sig = ComputeChannelSignature(_options);
345352
std::shared_ptr<SocketSSLContext> ssl_ctx;
346353
if (CreateSocketSSLContext(_options, &ssl_ctx) != 0) {
347354
return -1;
348355
}
356+
SocketOptions opt;
357+
opt.local_side = client_endpoint;
358+
opt.initial_ssl_ctx = ssl_ctx;
359+
opt.socket_mode = _options.socket_mode;
360+
opt.hc_option = _options.hc_option;
361+
opt.device_name = _options.device_name;
349362
if (SocketMapInsert(SocketMapKey(server_addr_and_port, sig),
350-
&_server_id, ssl_ctx, _options.socket_mode, _options.hc_option) != 0) {
363+
&_server_id, opt) != 0) {
351364
LOG(ERROR) << "Fail to insert into SocketMap";
352365
return -1;
353366
}
@@ -375,6 +388,13 @@ int Channel::Init(const char* ns_url,
375388
_options.mutable_ssl_options()->sni_name = _service_name;
376389
}
377390
}
391+
butil::EndPoint client_endpoint;
392+
if (!_options.client_host.empty() &&
393+
butil::str2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0 &&
394+
butil::hostname2ip(_options.client_host.c_str(), &client_endpoint.ip) != 0) {
395+
LOG(ERROR) << "Invalid client host=`" << _options.client_host << '\'';
396+
return -1;
397+
}
378398
std::unique_ptr<LoadBalancerWithNaming> lb(new (std::nothrow)
379399
LoadBalancerWithNaming);
380400
if (NULL == lb) {
@@ -384,10 +404,13 @@ int Channel::Init(const char* ns_url,
384404
GetNamingServiceThreadOptions ns_opt;
385405
ns_opt.succeed_without_server = _options.succeed_without_server;
386406
ns_opt.log_succeed_without_server = _options.log_succeed_without_server;
387-
ns_opt.socket_mode = _options.socket_mode;
407+
ns_opt.socket_option.socket_mode = _options.socket_mode;
388408
ns_opt.channel_signature = ComputeChannelSignature(_options);
389-
ns_opt.hc_option = _options.hc_option;
390-
if (CreateSocketSSLContext(_options, &ns_opt.ssl_ctx) != 0) {
409+
ns_opt.socket_option.hc_option = _options.hc_option;
410+
ns_opt.socket_option.local_side = client_endpoint;
411+
ns_opt.socket_option.device_name = _options.device_name;
412+
if (CreateSocketSSLContext(_options,
413+
&ns_opt.socket_option.initial_ssl_ctx) != 0) {
391414
return -1;
392415
}
393416
if (lb->Init(ns_url, lb_name, _options.ns_filter, &ns_opt) != 0) {

src/brpc/channel.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ struct ChannelOptions {
149149
// Its priority is higher than FLAGS_health_check_path and FLAGS_health_check_timeout_ms.
150150
// When it is not set, FLAGS_health_check_path and FLAGS_health_check_timeout_ms will take effect.
151151
HealthCheckOption hc_option;
152+
153+
// IP address or host name of the client.
154+
// if the client_host is "", the client IP address is determined by the OS.
155+
// Default: ""
156+
std::string client_host;
157+
158+
// The device name of the client's network adapter.
159+
// if the device_name is "", the flow control is determined by the OS.
160+
// Default: ""
161+
std::string device_name;
152162
private:
153163
// SSLOptions is large and not often used, allocate it on heap to
154164
// prevent ChannelOptions from being bloated in most cases.

src/brpc/details/naming_service_thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ void NamingServiceThread::Actions::ResetServers(
125125
// Socket. SocketMapKey may be passed through AddWatcher. Make sure
126126
// to pick those Sockets with the right settings during OnAddedServers
127127
const SocketMapKey key(_added[i], _owner->_options.channel_signature);
128-
CHECK_EQ(0, SocketMapInsert(key, &tagged_id.id, _owner->_options.ssl_ctx,
129-
_owner->_options.socket_mode, _owner->_options.hc_option));
128+
CHECK_EQ(0, SocketMapInsert(key, &tagged_id.id,
129+
_owner->_options.socket_option));
130130
_added_sockets.push_back(tagged_id);
131131
}
132132

src/brpc/details/naming_service_thread.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,14 @@ class NamingServiceWatcher {
4545
struct GetNamingServiceThreadOptions {
4646
GetNamingServiceThreadOptions()
4747
: succeed_without_server(false)
48-
, log_succeed_without_server(true)
49-
, socket_mode(SOCKET_MODE_TCP) {}
50-
48+
, log_succeed_without_server(true) {
49+
socket_option.socket_mode = SOCKET_MODE_TCP;
50+
}
51+
5152
bool succeed_without_server;
5253
bool log_succeed_without_server;
53-
SocketMode socket_mode;
54-
HealthCheckOption hc_option;
5554
ChannelSignature channel_signature;
56-
std::shared_ptr<SocketSSLContext> ssl_ctx;
55+
SocketOptions socket_option;
5756
};
5857

5958
// A dedicated thread to map a name to ServerIds

src/brpc/selective_channel.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ typedef std::map<ChannelBase*, Socket*> ChannelToIdMap;
4141
class SubChannel : public SocketUser {
4242
public:
4343
ChannelBase* chan;
44+
ChannelOwnership ownership;
4445

4546
// internal channel is deleted after the fake Socket is SetFailed
4647
void BeforeRecycle(Socket*) {
47-
delete chan;
48+
if (ownership == OWNS_CHANNEL) {
49+
delete chan;
50+
}
4851
delete this;
4952
}
5053

@@ -83,7 +86,8 @@ class ChannelBalancer : public SharedLoadBalancer {
8386
ChannelBalancer() {}
8487
~ChannelBalancer();
8588
int Init(const char* lb_name);
86-
int AddChannel(ChannelBase* sub_channel, const std::string& tag,
89+
int AddChannel(ChannelBase* sub_channel,
90+
const SelectiveChannel::SubChannelOptions& subopt,
8791
SelectiveChannel::ChannelHandle* handle);
8892
void RemoveAndDestroyChannel(const SelectiveChannel::ChannelHandle& handle);
8993
int SelectChannel(const LoadBalancer::SelectIn& in, SelectOut* out);
@@ -168,7 +172,8 @@ int ChannelBalancer::Init(const char* lb_name) {
168172
return SharedLoadBalancer::Init(lb_name);
169173
}
170174

171-
int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag,
175+
int ChannelBalancer::AddChannel(ChannelBase* sub_channel,
176+
const SelectiveChannel::SubChannelOptions& subopt,
172177
SelectiveChannel::ChannelHandle* handle) {
173178
if (NULL == sub_channel) {
174179
LOG(ERROR) << "Parameter[sub_channel] is NULL";
@@ -185,6 +190,7 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag
185190
return -1;
186191
}
187192
sub_chan->chan = sub_channel;
193+
sub_chan->ownership = subopt.ownership;
188194
SocketId sock_id;
189195
SocketOptions options;
190196
options.user = sub_chan;
@@ -206,7 +212,7 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag
206212
<< sock_id << " is disabled";
207213
return -1;
208214
}
209-
if (!AddServer(ServerId(sock_id, tag))) {
215+
if (!AddServer(ServerId(sock_id, subopt.tag))) {
210216
LOG(ERROR) << "Duplicated sub_channel=" << sub_channel;
211217
// sub_chan will be deleted when the socket is recycled.
212218
ptr->SetFailed();
@@ -215,10 +221,10 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel, const std::string& tag
215221
return -1;
216222
}
217223
// The health-check-related reference has been held on created.
218-
_chan_map[sub_channel]= ptr.get();
224+
_chan_map[sub_channel] = ptr.get();
219225
if (handle) {
220226
handle->id = sock_id;
221-
handle->tag = tag;
227+
handle->tag = subopt.tag;
222228
}
223229
return 0;
224230
}
@@ -532,20 +538,15 @@ bool SelectiveChannel::initialized() const {
532538
}
533539

534540
int SelectiveChannel::AddChannel(ChannelBase* sub_channel,
535-
ChannelHandle* handle) {
536-
return AddChannel(sub_channel, "", handle);
537-
}
538-
539-
int SelectiveChannel::AddChannel(ChannelBase* sub_channel,
540-
const std::string& tag,
541+
const SubChannelOptions& option,
541542
ChannelHandle* handle) {
542543
schan::ChannelBalancer* lb =
543544
static_cast<schan::ChannelBalancer*>(_chan._lb.get());
544545
if (lb == NULL) {
545546
LOG(ERROR) << "You must call Init() to initialize a SelectiveChannel";
546547
return -1;
547548
}
548-
return lb->AddChannel(sub_channel, tag, handle);
549+
return lb->AddChannel(sub_channel, option, handle);
549550
}
550551

551552
void SelectiveChannel::RemoveAndDestroyChannel(const ChannelHandle& handle) {

0 commit comments

Comments
 (0)