--- libaitsched/src/hooks.c 2016/09/29 13:44:23 1.31 +++ libaitsched/src/hooks.c 2017/08/31 12:18:38 1.31.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.31 2016/09/29 13:44:23 misho Exp $ +* $Id: hooks.c,v 1.31.2.1 2017/08/31 12:18:38 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -245,13 +245,14 @@ sched_hook_cancel(void *task, void *arg __unused) #endif #elif SUP_ENABLE == EP_SUPPORT ee.data.fd = TASK_FD(t); + ee.events ^= ee.events; if (FD_ISSET(TASK_FD(t), &r->root_fds[1])) ee.events = EPOLLOUT; if (flg < 2) FD_CLR(TASK_FD(t), &r->root_fds[0]); else - ee.events |= (EPOLLIN | EPOLLPRI | EPOLLRDHUP); + ee.events |= EPOLLIN | EPOLLPRI; #else if (flg < 2) { FD_CLR(TASK_FD(t), &r->root_fds[0]); @@ -283,8 +284,9 @@ sched_hook_cancel(void *task, void *arg __unused) #endif #elif SUP_ENABLE == EP_SUPPORT ee.data.fd = TASK_FD(t); + ee.events ^= ee.events; if (FD_ISSET(TASK_FD(t), &r->root_fds[0])) - ee.events = EPOLLIN | EPOLLPRI | EPOLLRDHUP; + ee.events = EPOLLIN | EPOLLPRI; if (flg < 2) FD_CLR(TASK_FD(t), &r->root_fds[1]); @@ -553,7 +555,7 @@ sched_hook_read(void *task, void *arg __unused) struct kevent chg[1]; struct timespec timeout = { 0, 0 }; #elif SUP_ENABLE == EP_SUPPORT - struct epoll_event ee = { .events = EPOLLIN | EPOLLPRI | EPOLLRDHUP, .data.fd = 0 }; + struct epoll_event ee = { .events = EPOLLIN | EPOLLPRI, .data.fd = 0 }; int flg = 0; #endif @@ -642,7 +644,7 @@ sched_hook_write(void *task, void *arg __unused) #elif SUP_ENABLE == EP_SUPPORT if (FD_ISSET(TASK_FD(t), &r->root_fds[0])) { flg |= 1; - ee.events |= EPOLLIN | EPOLLPRI | EPOLLRDHUP; + ee.events |= EPOLLIN | EPOLLPRI; } if (FD_ISSET(TASK_FD(t), &r->root_fds[1])) flg |= 2; @@ -1065,29 +1067,23 @@ fetch_hook_kevent_proceed(int en, struct kevent *res, static inline void fetch_hook_epoll_proceed(int en, struct epoll_event *res, sched_root_task_t *r) { - register int i, flg; + register int i, flg, oevt; int ops = EPOLL_CTL_DEL; sched_task_t *task, *tmp; struct epoll_event evt[1]; for (i = 0; i < en; i++) { memcpy(evt, &res[i], sizeof evt); + oevt = evt->events & EPOLLOUT; - if (evt->events & (EPOLLIN | EPOLLPRI | EPOLLET)) { + if (evt->events & (EPOLLIN | EPOLLPRI)) { flg = 0; TAILQ_FOREACH_SAFE(task, &r->root_read, task_node, tmp) { if (TASK_FD(task) != evt->data.fd) continue; else { flg++; - FD_CLR(TASK_FD(task), &r->root_fds[0]); TASK_FLAG(task) = ioctl(TASK_FD(task), FIONREAD, &TASK_RET(task)); - - evt->events &= ~(EPOLLIN | EPOLLPRI | EPOLLET | EPOLLRDHUP); - if (FD_ISSET(TASK_FD(task), &r->root_fds[1])) { - ops = EPOLL_CTL_MOD; - evt->events |= EPOLLOUT; - } } /* remove read handle */ remove_task_from(task, &r->root_read); @@ -1106,26 +1102,30 @@ fetch_hook_epoll_proceed(int en, struct epoll_event *r insert_task_to(task, &r->root_ready); } } - if (flg > 1) - ops = EPOLL_CTL_MOD; + + if (flg) { + evt->events ^= evt->events; + if (FD_ISSET(evt->data.fd, &r->root_fds[1])) { + ops = EPOLL_CTL_MOD; + evt->events |= EPOLLOUT; + } + if (flg > 1) { + ops = EPOLL_CTL_MOD; + evt->events |= EPOLLIN | EPOLLPRI; + } else + FD_CLR(evt->data.fd, &r->root_fds[0]); + } } - if (evt->events & EPOLLOUT) { + if (oevt) { flg = 0; TAILQ_FOREACH_SAFE(task, &r->root_write, task_node, tmp) { if (TASK_FD(task) != evt->data.fd) continue; else { flg++; - FD_CLR(TASK_FD(task), &r->root_fds[1]); TASK_FLAG(task) = ioctl(TASK_FD(task), FIONWRITE, &TASK_RET(task)); - - evt->events &= ~EPOLLOUT; - if (FD_ISSET(TASK_FD(task), &r->root_fds[0])) { - ops = EPOLL_CTL_MOD; - evt->events |= EPOLLIN | EPOLLPRI | EPOLLRDHUP; - } } /* remove write handle */ remove_task_from(task, &r->root_write); @@ -1144,8 +1144,19 @@ fetch_hook_epoll_proceed(int en, struct epoll_event *r insert_task_to(task, &r->root_ready); } } - if (flg > 1) - ops = EPOLL_CTL_MOD; + + if (flg) { + evt->events ^= evt->events; + if (FD_ISSET(evt->data.fd, &r->root_fds[0])) { + ops = EPOLL_CTL_MOD; + evt->events |= EPOLLIN | EPOLLPRI; + } + if (flg > 1) { + ops = EPOLL_CTL_MOD; + evt->events |= EPOLLOUT; + } else + FD_CLR(evt->data.fd, &r->root_fds[1]); + } } if (epoll_ctl(r->root_kq, ops, evt->data.fd, evt) == -1) {