3737#include " brpc/details/usercode_backup_pool.h" // TooManyUserCode
3838#include " brpc/rdma/rdma_helper.h"
3939#include " brpc/policy/esp_authenticator.h"
40+ #include " brpc/transport_factory.h"
4041
4142namespace brpc {
4243
@@ -60,7 +61,7 @@ ChannelOptions::ChannelOptions()
6061 , connection_type(CONNECTION_TYPE_UNKNOWN)
6162 , succeed_without_server(true )
6263 , log_succeed_without_server(true )
63- , use_rdma( false )
64+ , socket_mode(TCP )
6465 , auth(NULL )
6566 , backup_request_policy(NULL )
6667 , retry_policy(NULL )
@@ -120,7 +121,7 @@ static ChannelSignature ComputeChannelSignature(const ChannelOptions& opt) {
120121 } else {
121122 // All disabled ChannelSSLOptions are the same
122123 }
123- if (opt.use_rdma ) {
124+ if (opt.socket_mode == RDMA ) {
124125 buf.append (" |rdma" );
125126 }
126127 butil::MurmurHash3_x64_128_Update (&mm_ctx, buf.data (), buf.size ());
@@ -163,20 +164,6 @@ Channel::~Channel() {
163164 }
164165}
165166
166- #if BRPC_WITH_RDMA
167- static bool OptionsAvailableForRdma (const ChannelOptions* opt) {
168- if (opt->has_ssl_options ()) {
169- LOG (WARNING) << " Cannot use SSL and RDMA at the same time" ;
170- return false ;
171- }
172- if (!rdma::SupportedByRdma (opt->protocol .name ())) {
173- LOG (WARNING) << " Cannot use " << opt->protocol .name ()
174- << " over RDMA" ;
175- return false ;
176- }
177- return true ;
178- }
179- #endif
180167
181168int Channel::InitChannelOptions (const ChannelOptions* options) {
182169 if (options) { // Override default options if user provided one.
@@ -191,20 +178,8 @@ int Channel::InitChannelOptions(const ChannelOptions* options) {
191178 _options.hc_option .health_check_path = FLAGS_health_check_path;
192179 _options.hc_option .health_check_timeout_ms = FLAGS_health_check_timeout_ms;
193180 }
194- if (_options.use_rdma ) {
195- #if BRPC_WITH_RDMA
196- if (!OptionsAvailableForRdma (&_options)) {
197- return -1 ;
198- }
199- rdma::GlobalRdmaInitializeOrDie ();
200- if (!rdma::InitPollingModeWithTag (bthread_self_tag ())) {
201- return -1 ;
202- }
203- #else
204- LOG (WARNING) << " Cannot use rdma since brpc does not compile with rdma" ;
205- return -1 ;
206- #endif
207- }
181+ auto ret = TransportFactory::ContextInitOrDie (options->socket_mode , false , &_options);
182+ CHECK (ret == 0 );
208183
209184 _serialize_request = protocol->serialize_request ;
210185 _pack_request = protocol->pack_request ;
@@ -369,7 +344,7 @@ int Channel::InitSingle(const butil::EndPoint& server_addr_and_port,
369344 return -1 ;
370345 }
371346 if (SocketMapInsert (SocketMapKey (server_addr_and_port, sig),
372- &_server_id, ssl_ctx, _options.use_rdma , _options.hc_option ) != 0 ) {
347+ &_server_id, ssl_ctx, _options.socket_mode , _options.hc_option ) != 0 ) {
373348 LOG (ERROR) << " Fail to insert into SocketMap" ;
374349 return -1 ;
375350 }
@@ -406,7 +381,7 @@ int Channel::Init(const char* ns_url,
406381 GetNamingServiceThreadOptions ns_opt;
407382 ns_opt.succeed_without_server = _options.succeed_without_server ;
408383 ns_opt.log_succeed_without_server = _options.log_succeed_without_server ;
409- ns_opt.use_rdma = _options.use_rdma ;
384+ ns_opt.socket_mode = _options.socket_mode ;
410385 ns_opt.channel_signature = ComputeChannelSignature (_options);
411386 ns_opt.hc_option = _options.hc_option ;
412387 if (CreateSocketSSLContext (_options, &ns_opt.ssl_ctx ) != 0 ) {
0 commit comments