mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
python: call gnutls_global_init/gnutls_global_deinit on module load/unload
This commit is contained in:
1 parent
4a34045c0f
commit
dd247d15ba
3 files changed
+20
-1
No files matched your search
@@ -34,6 +34,20 @@ cimport opendht_cpp as cpp
|
||||
|
||||
import threading
|
||||
|
||||
cdef inline void _initialize_gnutls():
|
||||
cdef int err = cpp.gnutls_global_init()
|
||||
if err != 0:
|
||||
print(f"Failed to initialize GnuTLS: {cpp.gnutls_strerror(err).decode()}")
|
||||
else:
|
||||
import atexit
|
||||
atexit.register(_deinitialize_gnutls)
|
||||
|
||||
cdef inline _deinitialize_gnutls():
|
||||
cpp.gnutls_global_deinit()
|
||||
|
||||
# Initialize GnuTLS when this module is imported
|
||||
_initialize_gnutls()
|
||||
|
||||
cdef inline void lookup_callback(cpp.vector[cpp.shared_ptr[cpp.IndexValue]]* values, cpp.Prefix* p, void *user_data) noexcept with gil:
|
||||
cbs = <object>user_data
|
||||
if 'lookup' in cbs and cbs['lookup']:
|
||||
|
||||
@@ -326,3 +326,8 @@ cdef extern from "opendht/indexation/pht.h" namespace "dht::indexation":
|
||||
void insert(IndexKey k, IndexValue v, DoneCallbackSimple cb)
|
||||
@staticmethod
|
||||
LookupCallback bindLookupCb(LookupCallbackRaw cb, void *user_data)
|
||||
|
||||
cdef extern from "gnutls/gnutls.h" nogil:
|
||||
int gnutls_global_init()
|
||||
void gnutls_global_deinit()
|
||||
const char* gnutls_strerror(int error)
|
||||
+1
-1
@@ -42,7 +42,7 @@ setup(name="opendht",
|
||||
language="c++",
|
||||
extra_compile_args=["-std=c++17", "-DMSGPACK_NO_BOOST", "-DMSGPACK_DISABLE_LEGACY_NIL", "-DMSGPACK_DISABLE_LEGACY_CONVERT", "-DOPENDHT_INDEXATION", "-Dopendht_EXPORTS"],
|
||||
extra_link_args=["-std=c++17"],
|
||||
libraries=["opendht"],
|
||||
libraries=["opendht", "gnutls"],
|
||||
include_dirs = ['@PROJECT_SOURCE_DIR@/include'@OPENDHT_PYTHON_INCLUDE_DIRS@],
|
||||
library_dirs = ['@CURRENT_BINARY_DIR@', '@PROJECT_BINARY_DIR@'@OPENDHT_PYTHON_LIBRARY_DIRS@]
|
||||
)]
|
||||
|
||||
Reference in new issue
Block a user