Skip to content

Commit b7418fb

Browse files
Ensure gRPC server dll is never unloaded from the process once it is loaded (#143)
* Fix crash while unloading labview-grpc dll * Ensure gRPC server dll is never unloaded from the process once it is loaded * Minor cleanup
1 parent 5adac80 commit b7418fb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ add_library(labview_grpc_server SHARED
6363
src/message_element_metadata_owner.cc
6464
src/any_support.cc
6565
src/unpacked_fields.cc
66+
src/grpc_load.cc
6667
)
6768
target_link_libraries(labview_grpc_server
6869
${_REFLECTION}

src/grpc_load.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef _WIN32
2+
#include <dlfcn.h>
3+
#else
4+
#include <wtypes.h>
5+
#endif
6+
7+
namespace grpc_labview
8+
{
9+
#ifndef _WIN32
10+
typedef void* LibHandle;
11+
#else
12+
typedef HMODULE LibHandle;
13+
#endif
14+
15+
LibHandle LockgRPCLibraryIntoProcessMem()
16+
{
17+
#if _WIN32
18+
auto dllHandle = LoadLibrary("labview_grpc_server.dll");
19+
#else
20+
auto dllHandle = dlopen("liblabview_grpc_server.so", RTLD_LAZY);
21+
#endif
22+
return dllHandle;
23+
}
24+
25+
LibHandle gSelfLibHandle = LockgRPCLibraryIntoProcessMem();
26+
}

0 commit comments

Comments
 (0)