Skip to content

Commit 257134d

Browse files
authored
optimize the fallback code style (#3008)
1 parent 05ec537 commit 257134d

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/brpc/rdma/rdma_helper.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,22 @@ static void OnRdmaAsyncEvent(Socket* m) {
337337
}
338338

339339
static int ReadRdmaDynamicLib() {
340-
g_handle_ibverbs = dlopen("libibverbs.so", RTLD_LAZY);
341-
if (!g_handle_ibverbs) {
342-
LOG(WARNING) << "Failed to load libibverbs.so " << dlerror() << " try libibverbs.so.1";
343-
// Clear existing error
344-
dlerror();
345-
g_handle_ibverbs = dlopen("libibverbs.so.1", RTLD_LAZY);
346-
if (!g_handle_ibverbs) {
347-
LOG(ERROR) << "Fail to load libibverbs.so.1 due to " << dlerror();
348-
return -1;
340+
const static char* const kRdmaLibs[] = {
341+
"libibverbs.so",
342+
"libibverbs.so.1"
343+
};
344+
for (const char* lib : kRdmaLibs) {
345+
dlerror(); // Clear existing error
346+
g_handle_ibverbs = dlopen(lib, RTLD_LAZY);
347+
if (g_handle_ibverbs) {
348+
LOG(INFO) << "Successfully loaded " << lib;
349+
break;
349350
}
351+
LOG(WARNING) << "Failed to load " << lib << ": " << dlerror();
352+
}
353+
if (!g_handle_ibverbs) {
354+
LOG(ERROR) << "Failed to load any of the RDMA libraries";
355+
return -1;
350356
}
351357

352358
LoadSymbol(g_handle_ibverbs, IbvGetDeviceList, "ibv_get_device_list");

0 commit comments

Comments
 (0)