修改并增加新接口

This commit is contained in:
pengxuanzheng
2020-09-21 19:19:18 +08:00
parent a00d892928
commit eb41917cb2
22 changed files with 1916 additions and 106 deletions

52
src/hos_hash.cpp Normal file
View File

@@ -0,0 +1,52 @@
/*************************************************************************
> File Name: uthash.cpp
> Author: pxz
> Created Time: Fri 18 Sep 2020 04:26:09 PM CST
************************************************************************/
#include "hos_hash.h"
void add_hos_info(hos_info_t **handle, hos_info_t *input)
{
hos_info_t *value = NULL;
HASH_FIND_INT(*handle, &input->fd, value);
if (value == NULL)
{
value = (hos_info_t *)malloc(sizeof(hos_info_t));
memcpy(value, input, sizeof(hos_info_t));
HASH_ADD_INT(*handle, fd, value);
}
else
{
value->bucket = input->bucket;
value->object = input->object;
value->callback = input->callback;
value->userdata = input->userdata;
}
}
hos_info_t *find_info_by_fd(hos_info_t *handle, size_t fd)
{
hos_info_t *value = NULL;
HASH_FIND_INT(handle, &fd, value);
return value;
}
void delete_info_by_fd(hos_info_t *handle, size_t fd)
{
hos_info_t *value = NULL;
HASH_FIND_INT(handle, &fd, value);
if (value)
{
HASH_DEL(handle, value);
free(value);
}
}
void delete_all(hos_info_t *handle)
{
hos_info_t *current, *tmp;
HASH_ITER(hh, handle, current, tmp)
{
HASH_DEL(handle, current);
}
}