add function ioevent_remove
parent
ed4a70d97b
commit
118f657c7f
3
HISTORY
3
HISTORY
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
Version 1.06 2014-08-11
|
||||
Version 1.06 2014-08-25
|
||||
* update source code from FastDFS V5.02
|
||||
* add function short2buff and buff2short
|
||||
* add object memory pool (fast_mblock.h and fast_mblock.c)
|
||||
|
|
@ -22,6 +22,7 @@ Version 1.06 2014-08-11
|
|||
* support OS Darwin
|
||||
* socket send and recv ignore erno EINTR
|
||||
* http_parse_query_ex support binary buffer, and set both lengths of key and name
|
||||
* add function ioevent_remove
|
||||
|
||||
Version 1.05 2012-07-08
|
||||
* update source code from FastDFS V3.09
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ int ioevent_init(IOEventPoller *ioevent, const int size,
|
|||
|
||||
ioevent->size = size;
|
||||
ioevent->extra_events = extra_events;
|
||||
ioevent->iterator.index = 0;
|
||||
ioevent->iterator.count = 0;
|
||||
|
||||
#if IOEVENT_USE_EPOLL
|
||||
ioevent->timeout = timeout;
|
||||
|
|
|
|||
|
|
@ -52,6 +52,11 @@ typedef struct ioevent_puller {
|
|||
int extra_events;
|
||||
int poll_fd;
|
||||
|
||||
struct {
|
||||
int index;
|
||||
int count;
|
||||
} iterator; //for deal event loop
|
||||
|
||||
#if IOEVENT_USE_EPOLL
|
||||
struct epoll_event *events;
|
||||
int timeout;
|
||||
|
|
@ -90,6 +95,19 @@ typedef struct ioevent_puller {
|
|||
#error port me
|
||||
#endif
|
||||
|
||||
#if IOEVENT_USE_EPOLL
|
||||
#define IOEVENT_CLEAR_DATA(ioevent, index) \
|
||||
ioevent->events[index].data.ptr = NULL
|
||||
#elif IOEVENT_USE_KQUEUE
|
||||
#define IOEVENT_CLEAR_DATA(ioevent, index) \
|
||||
ioevent->events[index].udata = NULL
|
||||
#elif IOEVENT_USE_PORT
|
||||
#define IOEVENT_CLEAR_DATA(ioevent, index) \
|
||||
ioevent->events[index].portev_user = NULL
|
||||
#else
|
||||
#error port me
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,20 +2,52 @@
|
|||
#include "logger.h"
|
||||
#include "ioevent_loop.h"
|
||||
|
||||
static void deal_ioevents(IOEventPoller *ioevent, const int count)
|
||||
static void deal_ioevents(IOEventPoller *ioevent)
|
||||
{
|
||||
int i;
|
||||
int event;
|
||||
IOEventEntry *pEntry;
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
event = IOEVENT_GET_EVENTS(ioevent, i);
|
||||
pEntry = (IOEventEntry *)IOEVENT_GET_DATA(ioevent, i);
|
||||
|
||||
pEntry->callback(pEntry->fd, event, pEntry->timer.data);
|
||||
for (ioevent->iterator.index=0; ioevent->iterator.index < ioevent->iterator.
|
||||
count; ioevent->iterator.index++)
|
||||
{
|
||||
event = IOEVENT_GET_EVENTS(ioevent, ioevent->iterator.index);
|
||||
pEntry = (IOEventEntry *)IOEVENT_GET_DATA(ioevent,
|
||||
ioevent->iterator.index);
|
||||
if (pEntry != NULL) {
|
||||
pEntry->callback(pEntry->fd, event, pEntry->timer.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ioevent_remove(IOEventPoller *ioevent, void *data)
|
||||
{
|
||||
IOEventEntry *pEntry;
|
||||
int index;
|
||||
|
||||
if (ioevent->iterator.index >= ioevent->iterator.count)
|
||||
{
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
pEntry = (IOEventEntry *)IOEVENT_GET_DATA(ioevent,
|
||||
ioevent->iterator.index);
|
||||
if (pEntry != NULL && pEntry->timer.data == data) {
|
||||
return 0; //do NOT clear current entry
|
||||
}
|
||||
|
||||
for (index=ioevent->iterator.index + 1; index < ioevent->iterator.count;
|
||||
index++)
|
||||
{
|
||||
pEntry = (IOEventEntry *)IOEVENT_GET_DATA(ioevent, index);
|
||||
if (pEntry != NULL && pEntry->timer.data == data) {
|
||||
IOEVENT_CLEAR_DATA(ioevent, index);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
static void deal_timeouts(FastTimerEntry *head)
|
||||
{
|
||||
FastTimerEntry *entry;
|
||||
|
|
@ -67,12 +99,12 @@ int ioevent_loop(struct nio_thread_data *pThreadData,
|
|||
while (*continue_flag)
|
||||
{
|
||||
pThreadData->deleted_list = NULL;
|
||||
count = ioevent_poll(&pThreadData->ev_puller);
|
||||
if (count > 0)
|
||||
pThreadData->ev_puller.iterator.count = ioevent_poll(&pThreadData->ev_puller);
|
||||
if (pThreadData->ev_puller.iterator.count > 0)
|
||||
{
|
||||
deal_ioevents(&pThreadData->ev_puller, count);
|
||||
deal_ioevents(&pThreadData->ev_puller);
|
||||
}
|
||||
else if (count < 0)
|
||||
else if (pThreadData->ev_puller.iterator.count < 0)
|
||||
{
|
||||
result = errno != 0 ? errno : EINVAL;
|
||||
if (result != EINTR)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ int ioevent_loop(struct nio_thread_data *pThreadData,
|
|||
IOEventCallback recv_notify_callback, TaskCleanUpCallback
|
||||
clean_up_callback, volatile bool *continue_flag);
|
||||
|
||||
//remove entry from ready list
|
||||
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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue