Skip to content

Commit

Permalink
Ensure gRPC server dll is never unloaded from the process once it is …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
shivaprasad-basavaraj committed Sep 16, 2022
1 parent 5adac80 commit b7418fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ add_library(labview_grpc_server SHARED
src/message_element_metadata_owner.cc
src/any_support.cc
src/unpacked_fields.cc
src/grpc_load.cc
)
target_link_libraries(labview_grpc_server
${_REFLECTION}
Expand Down
26 changes: 26 additions & 0 deletions src/grpc_load.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _WIN32
#include <dlfcn.h>
#else
#include <wtypes.h>
#endif

namespace grpc_labview
{
#ifndef _WIN32
typedef void* LibHandle;
#else
typedef HMODULE LibHandle;
#endif

LibHandle LockgRPCLibraryIntoProcessMem()
{
#if _WIN32
auto dllHandle = LoadLibrary("labview_grpc_server.dll");
#else
auto dllHandle = dlopen("liblabview_grpc_server.so", RTLD_LAZY);
#endif
return dllHandle;
}

LibHandle gSelfLibHandle = LockgRPCLibraryIntoProcessMem();
}

0 comments on commit b7418fb

Please sign in to comment.