diff --git a/HISTORY b/HISTORY index 36d1750..c723a82 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,9 @@ -Version 1.52 2021-06-02 +Version 1.52 2021-06-08 * process_stop more gracefully (kill -9 on timeout) * add function fc_queue_pop_to_queue_ex * add function get_path_block_size and get_device_block_size + * add function fc_check_realloc_iovec_array Version 1.51 2021-05-27 * fast_mblock.[hc]: support batch alloc and batch free diff --git a/src/common_define.h b/src/common_define.h index cdcb40d..31f6428 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -249,6 +249,13 @@ typedef struct pthread_cond_t cond; } pthread_lock_cond_pair_t; +typedef struct +{ + int alloc; + int count; + struct iovec *iovs; +} iovec_array_t; + typedef struct { char buff[PATH_MAX]; @@ -293,6 +300,12 @@ typedef void* (*MallocFunc)(size_t size); //for printf format %.*s #define FC_PRINTF_STAR_STRING_PARAMS(s) (s).len, (s).str +#define FC_SET_IOVEC(iovec, buff, len) \ + do { \ + (iovec).iov_base = buff; \ + (iovec).iov_len = len; \ + } while (0) + #define FC_SET_STRING(dest, src) \ do { \ (dest).str = src; \ diff --git a/src/fast_task_queue.h b/src/fast_task_queue.h index 0b44f8b..fd6bd19 100644 --- a/src/fast_task_queue.h +++ b/src/fast_task_queue.h @@ -84,7 +84,13 @@ struct fast_task_info char client_ip[IP_ADDRESS_SIZE]; }; void *arg; //extra argument pointer - char *data; //buffer for write or recv + char *data; //buffer for write or read + + struct { + struct iovec *iovs; + int count; + } iovec_array; //for writev + int size; //alloc size int length; //data length int offset; //current offset diff --git a/src/shared_func.h b/src/shared_func.h index 1468df5..99d05b3 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -24,6 +24,7 @@ #include #include #include "common_define.h" +#include "fc_memory.h" #include "ini_file_reader.h" #define NORMALIZE_FLAGS_URL_ENABLED 1 @@ -1104,6 +1105,38 @@ int fc_check_filename(const string_t *filename, const char *caption); */ bool is_digital_string(const char *str); +static inline int fc_check_realloc_iovec_array( + iovec_array_t *array, const int target_size) +{ + int new_alloc; + struct iovec *new_iovs; + + if (array->alloc >= target_size) { + return 0; + } + + if (array->alloc == 0) { + new_alloc = 64; + } else { + new_alloc = array->alloc * 2; + } + while (new_alloc < target_size) { + new_alloc *= 2; + } + + new_iovs = (struct iovec *)fc_malloc( + sizeof(struct iovec) * new_alloc); + if (new_iovs == NULL) { + return ENOMEM; + } + + if (array->iovs != NULL) { + free(array->iovs); + } + array->iovs = new_iovs; + array->alloc = new_alloc; + return 0; +} #ifdef __cplusplus }