OCT 1. 优化vCPE BRAS后线程linux系统文件描述符fd资源占用 340+->264
2. 删除多余硬件信息调试日志
This commit is contained in:
parent
cf5375c893
commit
789ddbc716
|
@ -27,7 +27,7 @@ void hardwareRefreshCb(uv_timer_t *UNUSED(pArg)) {
|
|||
get_memory_info(&g_hardwareInfo.memInfo);
|
||||
}
|
||||
|
||||
printf("%s\n", get_hardware_json());
|
||||
//printf("%s\n", get_hardware_json());
|
||||
}
|
||||
|
||||
int init_hardware() {
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
#include "inet_misc.h"
|
||||
#include "crypto.h"
|
||||
#include "hardware.h"
|
||||
#include "msg_queue.h"
|
||||
#include "http_svr.h"
|
||||
#include "lib_config.h"
|
||||
#include "prj_config.h"
|
||||
#include "zlog_module.h"
|
||||
#ifdef ZEROMQ_ON
|
||||
#include "msg_queue.h"
|
||||
#endif
|
||||
|
||||
#define DEFAULT_CONFIG_FILE ("vcpe.cfg")
|
||||
#define DEFAULT_CONFIG_DIR ("config")
|
||||
|
|
|
@ -25,6 +25,7 @@ using namespace std;
|
|||
#include "sds/sds.h"
|
||||
#include "inet_misc.h"
|
||||
#include "http_svr.h"
|
||||
#include "task_manager.h"
|
||||
|
||||
extern data2 cfig;
|
||||
extern bool kRunning;
|
||||
|
@ -341,7 +342,7 @@ static int add_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
|
|||
logDHCPMess(logBuff, 1);
|
||||
return ERR_PROTO_DECODE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef JSON_SCHEMA_ON
|
||||
if (errCode == ERR_JSON_VALID_SCH) {
|
||||
*pRsp = pStrContent;
|
||||
|
@ -488,7 +489,7 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
|
|||
PHASH_MAP s;
|
||||
HASH_FIND_INT(delMap, &st_addr, s);
|
||||
if (s == nullptr) {
|
||||
s = (PHASH_MAP)malloc(sizeof(HASH_MAP));
|
||||
s = (PHASH_MAP)malloc(sizeof(HASH_MAP));
|
||||
s->key = st_addr;
|
||||
s->value = en_addr;
|
||||
HASH_ADD_INT(delMap, key, s);
|
||||
|
@ -765,68 +766,63 @@ static void on_http_response_cb(void *pData,
|
|||
free(pUserData);
|
||||
}
|
||||
|
||||
void iptvCacheCb(void *UNUSED(pArg)) {
|
||||
do {
|
||||
bool isReport = false;
|
||||
const char *pUrl = config_get_agent_iptv_report_url();
|
||||
PIPTV_DEV_SET report = nullptr;
|
||||
PIPTV_DEV_SET pDev, pTmp = nullptr;
|
||||
uv_rwlock_wrlock(&g_uvCacheLock);
|
||||
HASH_ITER(hh, g_iptvNewDevs, pDev, pTmp) {
|
||||
PIPTV_DEV_SET pTemp;
|
||||
const char *pDevMac = strdup(pDev->iptvMAC);
|
||||
HASH_FIND_STR(g_iptvCacheDevs, pDevMac, pTemp);
|
||||
// 新发现设备没有被上报过
|
||||
if (!pTemp) {
|
||||
auto pCacheDev = (PIPTV_DEV_SET)malloc(sizeof(IPTV_DEV_SET));
|
||||
auto pRepDev = (PIPTV_DEV_SET)malloc(sizeof(IPTV_DEV_SET));
|
||||
|
||||
memcpy(pCacheDev, pDev, sizeof(IPTV_DEV_SET));
|
||||
memcpy(pRepDev, pDev, sizeof(IPTV_DEV_SET));
|
||||
HASH_ADD_STR(report, iptvMAC, pRepDev);
|
||||
|
||||
isReport = true;
|
||||
// 添加到缓存列表供后续查询
|
||||
HASH_ADD_STR(g_iptvCacheDevs, iptvMAC, pCacheDev);
|
||||
LOG_MOD(debug,
|
||||
ZLOG_MOD_OPENDHCPD,
|
||||
"Add IPTV device %s vni %d to cache\n",
|
||||
pCacheDev->iptvMAC,
|
||||
pCacheDev->vni);
|
||||
}
|
||||
|
||||
HASH_DEL(g_iptvNewDevs, pDev);
|
||||
free(pDev);
|
||||
free((void *)pDevMac);
|
||||
}
|
||||
uv_rwlock_wrunlock(&g_uvCacheLock);
|
||||
|
||||
if (isReport && pUrl && strlen(pUrl) > 0) {
|
||||
cJSON *pRspMsg = cJSON_CreateObject();
|
||||
cJSON *pMsgArray = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(pRspMsg, "iptvDevs", pMsgArray);
|
||||
|
||||
HASH_ITER(hh, report, pDev, pTmp) {
|
||||
cJSON *pRspItem = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(pRspItem, "mac", pDev->iptvMAC);
|
||||
cJSON_AddNumberToObject(pRspItem, "vni", pDev->vni);
|
||||
pDev->isReport = 1;
|
||||
cJSON_AddItemToArray(pMsgArray, pRspItem);
|
||||
}
|
||||
|
||||
const char *pStrPro = proto_create_new(pRspMsg, 200);
|
||||
|
||||
// Report new IPTV device MAC
|
||||
inet_http_post_async(pUrl, pStrPro, on_http_response_cb, (void *)pStrPro);
|
||||
}
|
||||
void iptvCacheCb(uv_timer_t *UNUSED(pArg)) {
|
||||
bool isReport = false;
|
||||
const char *pUrl = config_get_agent_iptv_report_url();
|
||||
PIPTV_DEV_SET report = nullptr;
|
||||
PIPTV_DEV_SET pDev, pTmp = nullptr;
|
||||
uv_rwlock_wrlock(&g_uvCacheLock);
|
||||
HASH_ITER(hh, g_iptvNewDevs, pDev, pTmp) uv_sleep(10);
|
||||
HASH_ITER(hh, report, pDev, pTmp) {
|
||||
HASH_DEL(report, pDev);
|
||||
free(pDev);
|
||||
}
|
||||
HASH_ITER(hh, report, pDev, pTmp) if (isReport && pUrl && strlen(pUrl) > 0) {
|
||||
cJSON *pRspMsg = cJSON_CreateObject();
|
||||
cJSON *pMsgArray = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(pRspMsg, "iptvDevs", pMsgArray);
|
||||
|
||||
HASH_ITER(hh, report, pDev, pTmp) {
|
||||
HASH_DEL(report, pDev);
|
||||
free(pDev);
|
||||
cJSON *pRspItem = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(pRspItem, "mac", pDev->iptvMAC);
|
||||
cJSON_AddNumberToObject(pRspItem, "vni", pDev->vni);
|
||||
pDev->isReport = 1;
|
||||
cJSON_AddItemToArray(pMsgArray, pRspItem);
|
||||
}
|
||||
|
||||
uv_sleep(10);
|
||||
} while (true);
|
||||
const char *pStrPro = proto_create_new(pRspMsg, 200);
|
||||
|
||||
// Report new IPTV device MAC
|
||||
inet_http_post_async(pUrl, pStrPro, on_http_response_cb, (void *)pStrPro);
|
||||
}
|
||||
uv_rwlock_wrunlock(&g_uvCacheLock);
|
||||
HASH_ITER(hh, g_iptvNewDevs, pDev, pTmp) {
|
||||
PIPTV_DEV_SET pTemp;
|
||||
const char *pDevMac = strdup(pDev->iptvMAC);
|
||||
HASH_FIND_STR(g_iptvCacheDevs, pDevMac, pTemp);
|
||||
// 新发现设备没有被上报过
|
||||
if (!pTemp) {
|
||||
auto pCacheDev = (PIPTV_DEV_SET)malloc(sizeof(IPTV_DEV_SET));
|
||||
auto pRepDev = (PIPTV_DEV_SET)malloc(sizeof(IPTV_DEV_SET));
|
||||
|
||||
memcpy(pCacheDev, pDev, sizeof(IPTV_DEV_SET));
|
||||
memcpy(pRepDev, pDev, sizeof(IPTV_DEV_SET));
|
||||
HASH_ADD_STR(report, iptvMAC, pRepDev);
|
||||
|
||||
isReport = true;
|
||||
// 添加到缓存列表供后续查询
|
||||
HASH_ADD_STR(g_iptvCacheDevs, iptvMAC, pCacheDev);
|
||||
LOG_MOD(debug,
|
||||
ZLOG_MOD_OPENDHCPD,
|
||||
"Add IPTV device %s vni %d to cache\n",
|
||||
pCacheDev->iptvMAC,
|
||||
pCacheDev->vni);
|
||||
}
|
||||
|
||||
HASH_DEL(g_iptvNewDevs, pDev);
|
||||
free(pDev);
|
||||
free((void *)pDevMac);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -950,10 +946,13 @@ static HTTP_ROUTE_INFO g_routeTable[] = {
|
|||
void opendhcp_init_http_server() {
|
||||
static int added = FALSE;
|
||||
static uv_thread_t uvThread;
|
||||
|
||||
static uv_timer_t uvTm;
|
||||
if (!added) {
|
||||
uv_rwlock_init(&g_uvCacheLock);
|
||||
uv_thread_create(&uvThread, iptvCacheCb, nullptr);
|
||||
uv_timer_init(get_task_manager(), &uvTm);
|
||||
|
||||
uv_timer_start(&uvTm, iptvCacheCb, 1000, 1000);
|
||||
//uv_thread_create(&uvThread, iptvCacheCb, nullptr);
|
||||
for (auto &i : g_routeTable) {
|
||||
PHTTP_ROUTE_INFO p = &i;
|
||||
http_add_route(p->routeName, p->method, p->priority, p->cb, p->pUserData);
|
||||
|
|
Loading…
Reference in New Issue