add realloc_task_buffer options
parent
115b1e7750
commit
3b4aeff2d0
|
|
@ -28,7 +28,7 @@ SFGlobalVariables g_sf_global_vars = {
|
||||||
|
|
||||||
SFContext g_sf_context = {
|
SFContext g_sf_context = {
|
||||||
NULL, 0, -1, -1, 0, 0, 1, DEFAULT_WORK_THREADS,
|
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
|
sf_task_finish_clean_up, NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
12
src/sf_nio.c
12
src/sf_nio.c
|
|
@ -436,6 +436,18 @@ int sf_client_sock_read(int sock, short event, void *arg)
|
||||||
|
|
||||||
if (task->length > task->size) {
|
if (task->length > task->size) {
|
||||||
int old_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;
|
old_size = task->size;
|
||||||
if (free_queue_realloc_buffer(task, task->length) != 0) {
|
if (free_queue_realloc_buffer(task, task->length) != 0) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,8 @@ int sf_service_init_ex(SFContext *sf_context,
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
pthread_attr_t thread_attr;
|
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_context->accept_done_func = accept_done_callback;
|
||||||
sf_set_parameters_ex(sf_context, proto_header_size, set_body_length_func,
|
sf_set_parameters_ex(sf_context, proto_header_size, set_body_length_func,
|
||||||
deal_func, task_cleanup_func, timeout_callback);
|
deal_func, task_cleanup_func, timeout_callback);
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,15 @@ void sf_enable_thread_notify_ex(SFContext *sf_context, const bool enabled);
|
||||||
#define sf_enable_thread_notify(enabled) \
|
#define sf_enable_thread_notify(enabled) \
|
||||||
sf_enable_thread_notify_ex(&g_sf_context, 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ typedef struct sf_context {
|
||||||
|
|
||||||
int header_size;
|
int header_size;
|
||||||
bool remove_from_ready_list;
|
bool remove_from_ready_list;
|
||||||
|
bool realloc_task_buffer;
|
||||||
sf_deal_task_func deal_task;
|
sf_deal_task_func deal_task;
|
||||||
sf_set_body_length_callback set_body_length;
|
sf_set_body_length_callback set_body_length;
|
||||||
sf_accept_done_callback accept_done_func;
|
sf_accept_done_callback accept_done_func;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue