Skip to content

Commit ec6d269

Browse files
committed
review
1 parent df18000 commit ec6d269

File tree

5 files changed

+48
-52
lines changed

5 files changed

+48
-52
lines changed

src/brpc/channel.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,15 @@ int Channel::InitSingle(const butil::EndPoint& server_addr_and_port,
385385
if (CreateSocketSSLContext(_options, &ssl_ctx) != 0) {
386386
return -1;
387387
}
388+
SocketOptions opt;
389+
opt.remote_side = server_addr_and_port;
390+
opt.local_side = client_endpoint;
391+
opt.initial_ssl_ctx = ssl_ctx;
392+
opt.use_rdma = _options.use_rdma;
393+
opt.hc_option = _options.hc_option;
394+
opt.device_name = _options.device_name;
388395
if (SocketMapInsert(SocketMapKey(server_addr_and_port, sig),
389-
&_server_id, ssl_ctx, _options.use_rdma,
390-
_options.hc_option, client_endpoint,
391-
_options.device_name) != 0) {
396+
&_server_id, opt) != 0) {
392397
LOG(ERROR) << "Fail to insert into SocketMap";
393398
return -1;
394399
}
@@ -432,12 +437,13 @@ int Channel::Init(const char* ns_url,
432437
GetNamingServiceThreadOptions ns_opt;
433438
ns_opt.succeed_without_server = _options.succeed_without_server;
434439
ns_opt.log_succeed_without_server = _options.log_succeed_without_server;
435-
ns_opt.use_rdma = _options.use_rdma;
440+
ns_opt.socket_option.use_rdma = _options.use_rdma;
436441
ns_opt.channel_signature = ComputeChannelSignature(_options);
437-
ns_opt.hc_option = _options.hc_option;
438-
ns_opt.client_endpoint = client_endpoint;
439-
ns_opt.device_name = _options.device_name;
440-
if (CreateSocketSSLContext(_options, &ns_opt.ssl_ctx) != 0) {
442+
ns_opt.socket_option.hc_option = _options.hc_option;
443+
ns_opt.socket_option.local_side = client_endpoint;
444+
ns_opt.socket_option.device_name = _options.device_name;
445+
if (CreateSocketSSLContext(_options,
446+
&ns_opt.socket_option.initial_ssl_ctx) != 0) {
441447
return -1;
442448
}
443449
if (lb->Init(ns_url, lb_name, _options.ns_filter, &ns_opt) != 0) {

src/brpc/details/naming_service_thread.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +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.use_rdma, _owner->_options.hc_option,
130-
_owner->_options.client_endpoint,
131-
_owner->_options.device_name));
128+
CHECK_EQ(0, SocketMapInsert(key, &tagged_id.id,
129+
_owner->_options.socket_option));
132130
_added_sockets.push_back(tagged_id);
133131
}
134132

src/brpc/details/naming_service_thread.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,14 @@ class NamingServiceWatcher {
4444
struct GetNamingServiceThreadOptions {
4545
GetNamingServiceThreadOptions()
4646
: succeed_without_server(false)
47-
, log_succeed_without_server(true)
48-
, use_rdma(false) {}
47+
, log_succeed_without_server(true) {
48+
socket_option.use_rdma = false;
49+
}
4950

5051
bool succeed_without_server;
5152
bool log_succeed_without_server;
52-
bool use_rdma;
53-
HealthCheckOption hc_option;
5453
ChannelSignature channel_signature;
55-
std::shared_ptr<SocketSSLContext> ssl_ctx;
56-
butil::EndPoint client_endpoint;
57-
std::string device_name;
54+
SocketOptions socket_option;
5855
};
5956

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

src/brpc/socket_map.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,9 @@ SocketMap* get_or_new_client_side_socket_map() {
9090
}
9191

9292
int SocketMapInsert(const SocketMapKey& key, SocketId* id,
93-
const std::shared_ptr<SocketSSLContext>& ssl_ctx,
94-
bool use_rdma,
95-
const HealthCheckOption& hc_option,
96-
const butil::EndPoint& client_endpoint,
97-
const std::string& device_name) {
98-
return get_or_new_client_side_socket_map()->Insert(key, id, ssl_ctx, use_rdma, hc_option, client_endpoint, device_name);
99-
}
93+
SocketOptions& opt) {
94+
return get_or_new_client_side_socket_map()->Insert(key, id, opt);
95+
}
10096

10197
int SocketMapFind(const SocketMapKey& key, SocketId* id) {
10298
SocketMap* m = get_client_side_socket_map();
@@ -229,11 +225,7 @@ void SocketMap::ShowSocketMapInBvarIfNeed() {
229225
}
230226

231227
int SocketMap::Insert(const SocketMapKey& key, SocketId* id,
232-
const std::shared_ptr<SocketSSLContext>& ssl_ctx,
233-
bool use_rdma,
234-
const HealthCheckOption& hc_option,
235-
const butil::EndPoint& client_endpoint,
236-
const std::string& device_name) {
228+
SocketOptions& opt) {
237229
ShowSocketMapInBvarIfNeed();
238230

239231
std::unique_lock<butil::Mutex> mu(_mutex);
@@ -253,13 +245,6 @@ int SocketMap::Insert(const SocketMapKey& key, SocketId* id,
253245
sc = NULL;
254246
}
255247
SocketId tmp_id;
256-
SocketOptions opt;
257-
opt.remote_side = key.peer.addr;
258-
opt.local_side = client_endpoint;
259-
opt.device_name = device_name;
260-
opt.initial_ssl_ctx = ssl_ctx;
261-
opt.use_rdma = use_rdma;
262-
opt.hc_option = hc_option;
263248
if (_options.socket_creator->CreateSocket(opt, &tmp_id) != 0) {
264249
PLOG(FATAL) << "Fail to create socket to " << key.peer;
265250
return -1;

src/brpc/socket_map.h

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,30 @@ struct SocketMapKeyHasher {
8080
// successfully, SocketMapRemove() MUST be called when the Socket is not needed.
8181
// Return 0 on success, -1 otherwise.
8282
int SocketMapInsert(const SocketMapKey& key, SocketId* id,
83+
SocketOptions& opt);
84+
85+
inline int SocketMapInsert(const SocketMapKey& key, SocketId* id,
8386
const std::shared_ptr<SocketSSLContext>& ssl_ctx,
8487
bool use_rdma,
85-
const HealthCheckOption& hc_option,
86-
const butil::EndPoint& client_endpoint,
87-
const std::string& device_name);
88+
const HealthCheckOption& hc_option) {
89+
SocketOptions opt;
90+
opt.remote_side = key.peer.addr;
91+
opt.initial_ssl_ctx = ssl_ctx;
92+
opt.use_rdma = use_rdma;
93+
opt.hc_option = hc_option;
94+
return SocketMapInsert(key, id, opt);
95+
}
8896

8997
inline int SocketMapInsert(const SocketMapKey& key, SocketId* id,
9098
const std::shared_ptr<SocketSSLContext>& ssl_ctx) {
9199
HealthCheckOption hc_option;
92-
butil::EndPoint endpoint;
93-
return SocketMapInsert(key, id, ssl_ctx, false, hc_option, endpoint, "");
100+
return SocketMapInsert(key, id, ssl_ctx, false, hc_option);
94101
}
95102

96103
inline int SocketMapInsert(const SocketMapKey& key, SocketId* id) {
97104
std::shared_ptr<SocketSSLContext> empty_ptr;
98105
HealthCheckOption hc_option;
99-
butil::EndPoint endpoint;
100-
return SocketMapInsert(key, id, empty_ptr, false, hc_option, endpoint, "");
106+
return SocketMapInsert(key, id, empty_ptr, false, hc_option);
101107
}
102108

103109
// Find the SocketId associated with `key'.
@@ -159,22 +165,26 @@ class SocketMap {
159165
int Insert(const SocketMapKey& key, SocketId* id,
160166
const std::shared_ptr<SocketSSLContext>& ssl_ctx,
161167
bool use_rdma,
162-
const HealthCheckOption& hc_option,
163-
const butil::EndPoint& client_endpoint,
164-
const std::string& device_name);
168+
const HealthCheckOption& hc_option) {
169+
SocketOptions opt;
170+
opt.remote_side = key.peer.addr;
171+
opt.initial_ssl_ctx = ssl_ctx;
172+
opt.use_rdma = use_rdma;
173+
opt.hc_option = hc_option;
174+
return Insert(key, id, opt);
175+
}
165176

166177
int Insert(const SocketMapKey& key, SocketId* id,
167178
const std::shared_ptr<SocketSSLContext>& ssl_ctx) {
168179
HealthCheckOption hc_option;
169-
butil::EndPoint endpoint;
170-
return Insert(key, id, ssl_ctx, false, hc_option, endpoint, "");
180+
return Insert(key, id, ssl_ctx, false, hc_option);
171181
}
172182
int Insert(const SocketMapKey& key, SocketId* id) {
173183
std::shared_ptr<SocketSSLContext> empty_ptr;
174184
HealthCheckOption hc_option;
175-
butil::EndPoint endpoint;
176-
return Insert(key, id, empty_ptr, false, hc_option, endpoint, "");
185+
return Insert(key, id, empty_ptr, false, hc_option);
177186
}
187+
int Insert(const SocketMapKey& key, SocketId* id, SocketOptions& opt);
178188

179189
void Remove(const SocketMapKey& key, SocketId expected_id);
180190
int Find(const SocketMapKey& key, SocketId* id);

0 commit comments

Comments
 (0)