--- libaitsched/src/hooks.c 2015/07/02 23:27:06 1.30 +++ 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.30 2015/07/02 23:27:06 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 @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2015 +Copyright 2004 - 2016 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -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; @@ -869,7 +871,6 @@ fetch_hook_kevent_proceed(int en, struct kevent *res, struct aiocb *acb; #ifdef EVFILT_LIO int l; - register int j; off_t off; struct aiocb **acbs; struct iovec *iv; @@ -1019,7 +1020,7 @@ fetch_hook_kevent_proceed(int en, struct kevent *res, iv = (struct iovec*) TASK_DATA(task); fd = acbs[0]->aio_fildes; off = acbs[0]->aio_offset; - for (j = len = 0; i < TASK_DATLEN(task); len += l, i++) { + for (len = 0; i < TASK_DATLEN(task); len += l, i++) { if ((iv[i].iov_len = aio_return(acbs[i])) == -1) l = 0; else @@ -1066,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); @@ -1107,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); @@ -1145,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) {