add realloc_task_buffer options

connection_manager
YuQing 2020-03-16 13:09:11 +08:00
parent 115b1e7750
commit 3b4aeff2d0
5 changed files with 25 additions and 1 deletions

View File

@ -28,7 +28,7 @@ SFGlobalVariables g_sf_global_vars = {
SFContext g_sf_context = {
NULL, 0, -1, -1, 0, 0, 1, DEFAULT_WORK_THREADS,
{'\0'}, {'\0'}, 0, true, NULL, NULL, NULL,
{'\0'}, {'\0'}, 0, true, true, NULL, NULL, NULL,
sf_task_finish_clean_up, NULL
};

View File

@ -436,6 +436,18 @@ int sf_client_sock_read(int sock, short event, void *arg)
if (task->length > task->size) {
int old_size;
if (!SF_CTX->realloc_task_buffer) {
logError("file: "__FILE__", line: %d, "
"client ip: %s, pkg length: %d exceeds "
"task size: %d, but realloc buffer disabled",
__LINE__, task->client_ip, task->size,
task->length);
iovent_add_to_deleted_list(task);
return -1;
}
old_size = task->size;
if (free_queue_realloc_buffer(task, task->length) != 0) {
logError("file: "__FILE__", line: %d, "

View File

@ -106,6 +106,8 @@ int sf_service_init_ex(SFContext *sf_context,
pthread_t tid;
pthread_attr_t thread_attr;
sf_context->realloc_task_buffer = g_sf_global_vars.
min_buff_size < g_sf_global_vars.max_buff_size;
sf_context->accept_done_func = accept_done_callback;
sf_set_parameters_ex(sf_context, proto_header_size, set_body_length_func,
deal_func, task_cleanup_func, timeout_callback);

View File

@ -61,6 +61,15 @@ void sf_enable_thread_notify_ex(SFContext *sf_context, const bool enabled);
#define sf_enable_thread_notify(enabled) \
sf_enable_thread_notify_ex(&g_sf_context, enabled)
static inline void sf_enable_realloc_task_buffer_ex(SFContext *sf_context,
const bool enabled)
{
sf_context->realloc_task_buffer = enabled;
}
#define sf_enable_realloc_task_buffer(enabled) \
sf_enable_realloc_task_buffer_ex(&g_sf_context, enabled)
#ifdef __cplusplus
}
#endif

View File

@ -33,6 +33,7 @@ typedef struct sf_context {
int header_size;
bool remove_from_ready_list;
bool realloc_task_buffer;
sf_deal_task_func deal_task;
sf_set_body_length_callback set_body_length;
sf_accept_done_callback accept_done_func;