fiber's dns module can unloaded automaticly when process exiting

This commit is contained in:
zsx 2017-12-21 22:23:07 +08:00
parent e1a32b11ad
commit a94fd0299b
2 changed files with 21 additions and 7 deletions

View File

@ -54,14 +54,10 @@ endif()
############################################################################## ##############################################################################
set(src ${CMAKE_CURRENT_SOURCE_DIR}/src) set(src ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(acl_path ${CMAKE_CURRENT_SOURCE_DIR}/../../lib_acl)
set(acl_include ${acl_path}/include)
include_directories( include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${acl_include}
${acl_path}/src/master
) )
set(sources set(sources
@ -83,15 +79,13 @@ if(NOT CMAKE_SYSTEM_NAME MATCHES "ANDROID")
add_library(fiber_static STATIC ${lib_src}) add_library(fiber_static STATIC ${lib_src})
SET_TARGET_PROPERTIES(fiber_static PROPERTIES OUTPUT_NAME "fiber") SET_TARGET_PROPERTIES(fiber_static PROPERTIES OUTPUT_NAME "fiber")
set(CMAKE_SHARED_LINKER_FLAGS
-Wl,-rpath,. -L${lib_output_path} -lacl)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path})
link_directories(${lib_output_path}) link_directories(${lib_output_path})
endif() endif()
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_library(fiber SHARED ${lib_src}) add_library(fiber SHARED ${lib_src})
target_link_libraries(fiber acl) # target_link_libraries(fiber acl)
endif() endif()
############################################################################## ##############################################################################

View File

@ -11,6 +11,24 @@ void dns_set_read_wait(int timeout)
set_read_timeout(timeout); set_read_timeout(timeout);
} }
static void dns_on_exit(void)
{
if (var_dns_conf) {
dns_resconf_close(var_dns_conf);
var_dns_conf = NULL;
}
if (var_dns_hosts) {
dns_hosts_close(var_dns_hosts);
var_dns_hosts = NULL;
}
if (var_dns_hints) {
dns_hints_close(var_dns_hints);
var_dns_hints = NULL;
}
}
void dns_init(void) void dns_init(void)
{ {
static pthread_mutex_t __lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t __lock = PTHREAD_MUTEX_INITIALIZER;
@ -36,5 +54,7 @@ void dns_init(void)
var_dns_hints = dns_hints_local(var_dns_conf, &err); var_dns_hints = dns_hints_local(var_dns_conf, &err);
assert(var_dns_hints && err == 0); assert(var_dns_hints && err == 0);
atexit(dns_on_exit);
(void) pthread_mutex_unlock(&__lock); (void) pthread_mutex_unlock(&__lock);
} }