summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author彭宣正 <[email protected]>2021-04-12 16:56:05 +0800
committer彭宣正 <[email protected]>2021-04-12 16:56:05 +0800
commitbb3202153f06c6d4dcab487946a24cf3e6c4e0c0 (patch)
treefeb62279982b62bfd891cb3feed6c4bb1b573ecd /src
parent73c2ddb4767e501c3e05108a8fee1f24fb8e4cb3 (diff)
🐞fix(hos_set_thread_sum): 初始化hash_hos_infov1.0.21
Diffstat (limited to 'src')
-rw-r--r--src/hos_client.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/hos_client.cpp b/src/hos_client.cpp
index b98bbd8a..76f635cc 100644
--- a/src/hos_client.cpp
+++ b/src/hos_client.cpp
@@ -195,6 +195,7 @@ void hos_set_cache_count(hos_client_handle client, size_t cache_count)
void hos_set_thread_sum(hos_client_handle client, size_t thread_sum)
{
+ void *tmp = NULL;
if (client == NULL)
{
return;
@@ -204,7 +205,6 @@ void hos_set_thread_sum(hos_client_handle client, size_t thread_sum)
return;
}
- client->thread_sum = thread_sum;
for (size_t i = 0; i < thread_sum; i++)
{
fd_info[i][0] = 65533;
@@ -215,8 +215,14 @@ void hos_set_thread_sum(hos_client_handle client, size_t thread_sum)
}
if (hash_hos_info)
{
- hash_hos_info = (hos_info_t **)realloc(hash_hos_info, thread_sum * sizeof(hos_info_t*));
- }else
+ tmp = malloc(client->thread_sum * sizeof(hos_info_t *));
+ memcpy(tmp, hash_hos_info, client->thread_sum * sizeof(hos_info_t *));
+ hash_hos_info = (hos_info_t **)realloc(hash_hos_info, thread_sum * sizeof(hos_info_t *));
+ memset(hash_hos_info, 0, thread_sum * sizeof(hos_info_t *));
+ memcpy(hash_hos_info, tmp, thread_sum * sizeof(hos_info_t*));
+ free(tmp);
+ }
+ else
{
hash_hos_info = (hos_info_t **)calloc(thread_sum, sizeof(hos_info_t*));
}
@@ -227,6 +233,7 @@ void hos_set_thread_sum(hos_client_handle client, size_t thread_sum)
{
fd_info = (size_t (*) [MAX_HOS_CLIENT_FD_NUM + 1])calloc(thread_sum, sizeof(size_t [MAX_HOS_CLIENT_FD_NUM + 1]));
}
+ client->thread_sum = thread_sum;
return ;
}