From bf8023287e5dbcff067e12dfef9f43bcb1e7f0e8 Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 2 Sep 2016 19:14:00 +0800 Subject: [PATCH] add function iovent_add_to_deleted_list --- HISTORY | 3 ++- src/ioevent_loop.c | 18 +++++++++++++++++- src/ioevent_loop.h | 2 ++ src/shared_func.c | 11 ++++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index 5255bfa..fad9a07 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,9 @@ -Version 1.30 2016-08-12 +Version 1.30 2016-09-02 * modify php-fastcommon/test.php * php7_ext_wrapper.h: fix memory leak in php 7 * setsockopt SO_NOSIGPIPE when nessary + * add function iovent_add_to_deleted_list Version 1.29 2016-06-17 * ini_file_reader support #@if diff --git a/src/ioevent_loop.c b/src/ioevent_loop.c index 2a9ed9d..fd1ade9 100644 --- a/src/ioevent_loop.c +++ b/src/ioevent_loop.c @@ -16,6 +16,10 @@ static void deal_ioevents(IOEventPoller *ioevent) if (pEntry != NULL) { pEntry->callback(pEntry->fd, event, pEntry->timer.data); } + else { + logDebug("file: "__FILE__", line: %d, " + "ignore iovent : %d, index: %d", __LINE__, event, ioevent->iterator.index); + } } } @@ -40,6 +44,8 @@ int ioevent_remove(IOEventPoller *ioevent, void *data) { pEntry = (IOEventEntry *)IOEVENT_GET_DATA(ioevent, index); if (pEntry != NULL && pEntry->timer.data == data) { + logDebug("file: "__FILE__", line: %d, " + "clear iovent data: %p", __LINE__, data); IOEVENT_CLEAR_DATA(ioevent, index); return 0; } @@ -70,6 +76,16 @@ static void deal_timeouts(FastTimerEntry *head) } } +void iovent_add_to_deleted_list(struct fast_task_info *pTask) +{ + if (pTask->thread_data == NULL) { + return; + } + + pTask->next = pTask->thread_data->deleted_list; + pTask->thread_data->deleted_list = pTask; +} + int ioevent_loop(struct nio_thread_data *pThreadData, IOEventCallback recv_notify_callback, TaskCleanUpCallback clean_up_callback, volatile bool *continue_flag) @@ -96,10 +112,10 @@ int ioevent_loop(struct nio_thread_data *pThreadData, return result; } + pThreadData->deleted_list = NULL; last_check_time = g_current_time; while (*continue_flag) { - pThreadData->deleted_list = NULL; pThreadData->ev_puller.iterator.count = ioevent_poll(&pThreadData->ev_puller); if (pThreadData->ev_puller.iterator.count > 0) { diff --git a/src/ioevent_loop.h b/src/ioevent_loop.h index 7740fc7..d875eec 100644 --- a/src/ioevent_loop.h +++ b/src/ioevent_loop.h @@ -17,6 +17,8 @@ int ioevent_remove(IOEventPoller *ioevent, void *data); int ioevent_set(struct fast_task_info *pTask, struct nio_thread_data *pThread, int sock, short event, IOEventCallback callback, const int timeout); +void iovent_add_to_deleted_list(struct fast_task_info *pTask); + #ifdef __cplusplus } #endif diff --git a/src/shared_func.c b/src/shared_func.c index 17777d9..3f8e0d6 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -959,7 +959,16 @@ void chopPath(char *filePath) int getFileContent(const char *filename, char **buff, int64_t *file_size) { int fd; - + + if (!isFile(filename)) + { + *buff = NULL; + *file_size = 0; + logError("file: "__FILE__", line: %d, " + "%s is not a regular file", __LINE__, filename); + return EINVAL; + } + fd = open(filename, O_RDONLY); if (fd < 0) {