diff --git a/src/sf_nio.c b/src/sf_nio.c index 1800cb7..e2c8728 100644 --- a/src/sf_nio.c +++ b/src/sf_nio.c @@ -95,8 +95,6 @@ static inline void release_iovec_buffer(struct fast_task_info *task) void sf_task_finish_clean_up(struct fast_task_info *task) { - //int next_stage; - /* assert(task->event.fd >= 0); if (task->event.fd < 0) { @@ -112,18 +110,6 @@ void sf_task_finish_clean_up(struct fast_task_info *task) task->finish_callback = NULL; } - /* - if (SF_G_EPOLL_EDGE_TRIGGER && (next_stage=FC_ATOMIC_GET(task-> - nio_stages.next)) != SF_NIO_STAGE_NONE) - { - logWarning("file: "__FILE__", line: %d, " - "task: %p, nio_stages.next: %d != 0", - __LINE__, task, FC_ATOMIC_GET(task->nio_stages.next)); - __sync_bool_compare_and_swap(&task->nio_stages.next, - next_stage, SF_NIO_STAGE_NONE); - } - */ - release_iovec_buffer(task); sf_task_detach_thread(task); @@ -158,7 +144,7 @@ static inline int set_write_event(struct fast_task_info *task) return 0; } -static int setup_read_event(struct fast_task_info *task) +int sf_set_read_event(struct fast_task_info *task) { int result; @@ -184,33 +170,6 @@ static int setup_read_event(struct fast_task_info *task) return 0; } -int sf_set_read_event(struct fast_task_info *task) -{ - int result; - - if ((result=setup_read_event(task)) != 0) { - return result; - } - return 0; - - if (SF_G_EPOLL_EDGE_TRIGGER) { - if (FC_ATOMIC_GET(task->nio_stages.notify) == SF_NIO_STAGE_SEND) { - if (__sync_bool_compare_and_swap(&task->nio_stages.next, - SF_NIO_STAGE_NONE, SF_NIO_STAGE_RECV)) - { - return 0; - } else { - return EAGAIN; - } - } else { - return sf_nio_notify(task, SF_NIO_STAGE_RECV); - return 0; - } - } else { - return 0; - } -} - static inline int sf_ioevent_add(struct fast_task_info *task, IOEventCallback callback, const int timeout) { @@ -318,7 +277,7 @@ static int sf_nio_deal_task(struct fast_task_info *task, const int stage) result = sf_connect_server(task); break; case SF_NIO_STAGE_RECV: - if ((result=setup_read_event(task)) == 0) { + if ((result=sf_set_read_event(task)) == 0) { if (sf_client_sock_read(task->event.fd, IOEVENT_READ, task) < 0) { @@ -397,20 +356,7 @@ int sf_nio_notify(struct fast_task_info *task, const int stage) __LINE__, stage); return 0; - } else if (old_stage == SF_NIO_STAGE_NONE) { - continue; - /* - } else if (SF_G_EPOLL_EDGE_TRIGGER && ( - (old_stage == SF_NIO_STAGE_RECV && - stage == SF_NIO_STAGE_SEND) || - (old_stage == SF_NIO_STAGE_SEND && - stage == SF_NIO_STAGE_RECV))) - { - __sync_bool_compare_and_swap(&task->nio_stages. - next, SF_NIO_STAGE_NONE, stage); - return 0; - */ - } else { + } else if (old_stage != SF_NIO_STAGE_NONE) { logWarning("file: "__FILE__", line: %d, " "current stage: %d != %d, skip set stage to %d", __LINE__, old_stage, SF_NIO_STAGE_NONE, stage); @@ -451,8 +397,6 @@ void sf_recv_notify_read(int sock, short event, void *arg) { int64_t n; int stage; - int next; - int result; struct nio_thread_data *thread_data; struct fast_task_info *task; struct fast_task_info *current; @@ -479,21 +423,12 @@ void sf_recv_notify_read(int sock, short event, void *arg) /* MUST set to SF_NIO_STAGE_NONE first for re-entry */ __sync_bool_compare_and_swap(&task->nio_stages.notify, stage, SF_NIO_STAGE_NONE); - result = sf_nio_deal_task(task, stage); + sf_nio_deal_task(task, stage); } else { - result = sf_nio_deal_task(task, stage); + sf_nio_deal_task(task, stage); __sync_bool_compare_and_swap(&task->nio_stages.notify, stage, SF_NIO_STAGE_NONE); } - - if (SF_G_EPOLL_EDGE_TRIGGER && result >= 0) { - next = FC_ATOMIC_GET(task->nio_stages.next); - if (next != SF_NIO_STAGE_NONE) { - //sf_nio_notify(task, next); - __sync_bool_compare_and_swap(&task->nio_stages.next, - next, SF_NIO_STAGE_NONE); - } - } } else { if (stage != SF_NIO_STAGE_NONE) { if (stage == SF_NIO_STAGE_CONTINUE) {