From 42795a736105515ba4e95903b7bb0737b453aa84 Mon Sep 17 00:00:00 2001 From: huangxin Date: Fri, 18 Nov 2022 11:02:30 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E4=BF=AE=E6=AD=A3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=202.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E9=80=80=E5=87=BA=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E8=B5=84=E6=BA=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/haywire/http_response_cache.c | 13 ++++-- .../src/haywire/http_response_cache.h | 1 + srcs/httpserver/src/haywire/http_server.c | 9 ++-- srcs/libs/configure/config.c | 43 +++++++++++-------- srcs/libs/include/config.h | 1 + srcs/libs/init/init.c | 1 + 6 files changed, 44 insertions(+), 24 deletions(-) diff --git a/srcs/httpserver/src/haywire/http_response_cache.c b/srcs/httpserver/src/haywire/http_response_cache.c index 1802ebf..911c6d7 100644 --- a/srcs/httpserver/src/haywire/http_response_cache.c +++ b/srcs/httpserver/src/haywire/http_response_cache.c @@ -13,8 +13,9 @@ #define CRLF "\r\n" KHASH_MAP_INIT_STR(string_hashmap, hw_string *) -static uv_timer_t cache_invalidation_timer; -static uv_key_t thread_cache_key; +//static uv_timer_t cache_invalidation_timer; +static uv_key_t thread_cache_key; +static uv_timer_t *cache_invalidation_timer; void initialize_http_request_cache(); void free_http_request_cache(); @@ -27,8 +28,14 @@ void initialize_http_request_cache() { uv_key_create(&thread_cache_key); } +void uninit_http_request_cache() { + if (cache_invalidation_timer) { + free(cache_invalidation_timer); + } +} + void http_request_cache_configure_listener(uv_loop_t *loop, uv_async_t *handle) { - uv_timer_t *cache_invalidation_timer = malloc(sizeof(uv_timer_t)); + cache_invalidation_timer = malloc(sizeof(uv_timer_t)); uv_timer_init(loop, cache_invalidation_timer); uv_timer_start(cache_invalidation_timer, http_request_cache_timer, 500, 500); diff --git a/srcs/httpserver/src/haywire/http_response_cache.h b/srcs/httpserver/src/haywire/http_response_cache.h index b48df67..60f5a4d 100644 --- a/srcs/httpserver/src/haywire/http_response_cache.h +++ b/srcs/httpserver/src/haywire/http_response_cache.h @@ -5,3 +5,4 @@ void initialize_http_request_cache(); hw_string *get_cached_request(const char *http_status); void http_request_cache_configure_listener(uv_loop_t *loop, uv_async_t *handle); +void uninit_http_request_cache(); \ No newline at end of file diff --git a/srcs/httpserver/src/haywire/http_server.c b/srcs/httpserver/src/haywire/http_server.c index 53dd8fb..fbf0c3a 100644 --- a/srcs/httpserver/src/haywire/http_server.c +++ b/srcs/httpserver/src/haywire/http_server.c @@ -145,13 +145,14 @@ void free_http_server() { free((char *)v); }); kh_destroy(string_hashmap, routes); - + uv_close((uv_handle_t*)&server, NULL); + uninit_http_request_cache(); dzlog_debug("HTTP Server Close http://%s:%d\n", config->http_listen_address, config->http_listen_port); } int hw_http_open() { int threads = (int)config->thread_count; - uv_async_t *service_handle; + static uv_async_t service_handle; if (routes == NULL) { routes = kh_init(string_hashmap); @@ -180,8 +181,8 @@ int hw_http_open() { listeners_created_barrier = malloc(sizeof(uv_barrier_t)); uv_barrier_init(listeners_created_barrier, listener_count + 1); - service_handle = malloc(sizeof(uv_async_t)); - uv_async_init(uv_loop, service_handle, NULL); + //service_handle = malloc(sizeof(uv_async_t)); + uv_async_init(uv_loop, &service_handle, NULL); if (listener_count == 0) { /* If running single threaded there is no need to use the IPC pipe diff --git a/srcs/libs/configure/config.c b/srcs/libs/configure/config.c index abe1922..5247e33 100644 --- a/srcs/libs/configure/config.c +++ b/srcs/libs/configure/config.c @@ -147,31 +147,31 @@ static const char *load_string_value(const char *pKeyName) { } } -static int load_boolean_value(const char *pKeyName, int defValue) { +static int load_boolean_value(const char *pKeyName) { int val; if (config_lookup_bool(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) { dzlog_error("No {%s} setting in configuration file.\n", pKeyName); - return defValue; + return DEFAULT_INTEGRAL_ERR_VALUE; } return val; } -static long long load_integral_value(const char *pKeyName, long long defValue) { +static long long int load_integral_value(const char *pKeyName) { long long val; if (config_lookup_int64(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) { dzlog_error("No {%s} setting in configuration file.\n", pKeyName); - return defValue; + return DEFAULT_INTEGRAL_ERR_VALUE; } return val; } -static double load_float_value(const char *pKeyName, double defValue) { +static double load_float_value(const char *pKeyName) { double val; if (config_lookup_float(&g_cfgContent, pKeyName, &val) != CONFIG_TRUE) { dzlog_error("No {%s} setting in configuration file.\n", pKeyName); - return defValue; + return DEFAULT_INTEGRAL_ERR_VALUE; } return val; @@ -254,15 +254,10 @@ static int load_array_obj(const char *pKeyName, PCONFIG_ITEM pValue) { v.lease = 0xFFFFFFFF; } - if (pValue->value.array == NULL) { - pValue->value.array = vect_create(128, sizeof(OBJ_DHCP_RNG), ZV_SEC_WIPE); - } - if (!vect_bsearch(pValue->value.array, &v, cmp_dhcp_obj, &idx)) { memcpy(&k, &v, sizeof(OBJ_DHCP_RNG)); vect_push(pValue->value.array, &k); pValue->isChanged = TRUE; - printf("++++Add %s\n", k.rangAddr); } } break; @@ -304,8 +299,7 @@ static int setConfigItemValue(PCONFIG_ITEM pItem, const char *pValue) { } else if (pItem->valType == VALUE_TYPE_ARRAY_STR) { pItem->value.array = vect_create(128, 512, ZV_SEC_WIPE); } else if (pItem->valType == VALUE_TYPE_ARRAY_OBJ) { - pItem->value.array = NULL; - vect_create(128, sizeof(int), ZV_SEC_WIPE | ZV_BYREF); + pItem->value.array = vect_create(128, sizeof(OBJ_DHCP_RNG), ZV_SEC_WIPE); } else { return -ERR_UN_SUPPORT; } @@ -397,7 +391,7 @@ static void refreshCfgFileCb() { } break; case VALUE_TYPE_BOOL: - iVal = load_boolean_value(pItem->pcfgKey, DEFAULT_INTEGRAL_ERR_VALUE); + iVal = load_boolean_value(pItem->pcfgKey); if (iVal != DEFAULT_INTEGRAL_ERR_VALUE) { if (pItem->value.longValue != iVal) { @@ -408,7 +402,7 @@ static void refreshCfgFileCb() { break; case VALUE_TYPE_INTEGRAL: - iVal = load_integral_value(pItem->pcfgKey, DEFAULT_INTEGRAL_ERR_VALUE); + iVal = load_integral_value(pItem->pcfgKey); if (iVal != DEFAULT_INTEGRAL_ERR_VALUE) { if (pItem->value.longValue != iVal) { @@ -419,7 +413,7 @@ static void refreshCfgFileCb() { break; case VALUE_TYPE_FLOAT: - fVal = load_float_value(pItem->pcfgKey, DEFAULT_INTEGRAL_ERR_VALUE); + fVal = load_float_value(pItem->pcfgKey); if (fVal != DEFAULT_INTEGRAL_ERR_VALUE) { if (pItem->value.floatValue != fVal) { @@ -681,6 +675,21 @@ int init_config_system(const char *pCfgFile, const char *pKey) { return ERR_SUCCESS; } +void uninit_config_system() { + PCONFIG_ITEM pItem, pTmp; + HASH_ITER(hh, g_pConfigItem, pItem, pTmp) { + switch (pItem->valType) { + case VALUE_TYPE_ARRAY_STR: + case VALUE_TYPE_ARRAY_OBJ: + vect_destroy(pItem->value.array); + break; + default: + break; + } + } + config_destroy(&g_cfgContent); +} + const char *get_config_keygen() { char buf[MAX_PATH]; CPU_INFO cpuInfo; @@ -703,7 +712,7 @@ const char *get_config_key(const char *pKeygen) { unsigned char *pBase64 = (unsigned char *)base64_decode(pKeygen, (unsigned int *)&outSize); if (pBase64 == NULL) { - printf("Base64 decode error: %s\n", pKeygen); + dzlog_error("Base64 decode error: %s\n", pKeygen); return NULL; } diff --git a/srcs/libs/include/config.h b/srcs/libs/include/config.h index 4a0379b..d716a82 100644 --- a/srcs/libs/include/config.h +++ b/srcs/libs/include/config.h @@ -96,6 +96,7 @@ long double cfg_get_float_value(CONFIG_ITEM_ID id); int cfg_get_bool_value(CONFIG_ITEM_ID id); long long cfg_get_integral_value(CONFIG_ITEM_ID id); int init_config_system(const char *pCfgFile, const char *pKey); +void uninit_config_system(); void config_item_dump(const char *titleMessage); const char *config_item_dump_fmt(const char *titleMessage); const char *get_config_key(const char *pKeygen); diff --git a/srcs/libs/init/init.c b/srcs/libs/init/init.c index 04f23da..f6c524f 100644 --- a/srcs/libs/init/init.c +++ b/srcs/libs/init/init.c @@ -127,5 +127,6 @@ void user_uninit() { free_http_server(); mq_uninit(); zlog_fini(); + uninit_config_system(); uv_loop_close(get_task_manager()); }