From 850cbeb422b3d3ae1b5dafcc70b26081124d112c Mon Sep 17 00:00:00 2001 From: Ron Date: Tue, 13 Jun 2017 19:26:38 +0800 Subject: [PATCH] kevent copyout directly without --- lib/ff_epoll.c | 68 ++++++++++++++++++++-------------------- lib/ff_syscall_wrapper.c | 15 +++++---- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/lib/ff_epoll.c b/lib/ff_epoll.c index 81d457e83..d0e8d5a91 100644 --- a/lib/ff_epoll.c +++ b/lib/ff_epoll.c @@ -24,43 +24,43 @@ int ff_epoll_create(int size __attribute__((__unused__))) { - return ff_kqueue(); + return ff_kqueue(); } int ff_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) { - struct kevent kev[3]; + struct kevent kev[3]; - if (!event && op != EPOLL_CTL_DEL) { + if (!event && op != EPOLL_CTL_DEL) { errno = EINVAL; - return -1; - } + return -1; + } - if (op == EPOLL_CTL_ADD){ - EV_SET(&kev[0], fd, EVFILT_READ, - EV_ADD | (event->events & EPOLLIN ? 0 : EV_DISABLE), 0, 0, NULL); - EV_SET(&kev[1], fd, EVFILT_WRITE, - EV_ADD | (event->events & EPOLLOUT ? 0 : EV_DISABLE), 0, 0, NULL); - EV_SET(&kev[2], fd, EVFILT_USER, EV_ADD, - event->events & EPOLLRDHUP ? 1 : 0, 0, NULL); - } else if (op == EPOLL_CTL_DEL) { - EV_SET(&kev[0], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); - EV_SET(&kev[1], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); - EV_SET(&kev[2], fd, EVFILT_USER, EV_DELETE, 0, 0, NULL); - } else if (op == EPOLL_CTL_MOD) { - EV_SET(&kev[0], fd, EVFILT_READ, - event->events & EPOLLIN ? EV_ENABLE : EV_DISABLE, 0, 0, NULL); - EV_SET(&kev[1], fd, EVFILT_WRITE, - event->events & EPOLLOUT ? EV_ENABLE : EV_DISABLE, 0, 0, NULL); - EV_SET(&kev[2], fd, EVFILT_USER, 0, - NOTE_FFCOPY | (event->events & EPOLLRDHUP ? 1 : 0), 0, NULL); - } else { - errno = EINVAL; - return -1; - } + if (op == EPOLL_CTL_ADD){ + EV_SET(&kev[0], fd, EVFILT_READ, + EV_ADD | (event->events & EPOLLIN ? 0 : EV_DISABLE), 0, 0, NULL); + EV_SET(&kev[1], fd, EVFILT_WRITE, + EV_ADD | (event->events & EPOLLOUT ? 0 : EV_DISABLE), 0, 0, NULL); + EV_SET(&kev[2], fd, EVFILT_USER, EV_ADD, + event->events & EPOLLRDHUP ? 1 : 0, 0, NULL); + } else if (op == EPOLL_CTL_DEL) { + EV_SET(&kev[0], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); + EV_SET(&kev[1], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); + EV_SET(&kev[2], fd, EVFILT_USER, EV_DELETE, 0, 0, NULL); + } else if (op == EPOLL_CTL_MOD) { + EV_SET(&kev[0], fd, EVFILT_READ, + event->events & EPOLLIN ? EV_ENABLE : EV_DISABLE, 0, 0, NULL); + EV_SET(&kev[1], fd, EVFILT_WRITE, + event->events & EPOLLOUT ? EV_ENABLE : EV_DISABLE, 0, 0, NULL); + EV_SET(&kev[2], fd, EVFILT_USER, 0, + NOTE_FFCOPY | (event->events & EPOLLRDHUP ? 1 : 0), 0, NULL); + } else { + errno = EINVAL; + return -1; + } - return ff_kevent(epfd, kev, 3, NULL, 0, NULL); + return ff_kevent(epfd, kev, 3, NULL, 0, NULL); } static void @@ -81,7 +81,7 @@ ff_event_to_epoll(void **ev, struct kevent *kev) } if (kev->flags & EV_EOF) { - event_one |= EPOLLIN; + event_one |= EPOLLIN; } (*ppev)->events = event_one; @@ -93,11 +93,11 @@ int ff_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) { int i, ret; - if (!events || maxevents < 1) { - errno = EINVAL; - return -1; - } + if (!events || maxevents < 1) { + errno = EINVAL; + return -1; + } - return ff_kevent_do_each(epfd, NULL, 0, events, maxevents, NULL, ff_event_to_epoll); + return ff_kevent_do_each(epfd, NULL, 0, events, maxevents, NULL, ff_event_to_epoll); } diff --git a/lib/ff_syscall_wrapper.c b/lib/ff_syscall_wrapper.c index 3d25796d8..5eb1cbee4 100644 --- a/lib/ff_syscall_wrapper.c +++ b/lib/ff_syscall_wrapper.c @@ -946,19 +946,18 @@ static int kevent_copyout(void *arg, struct kevent *kevp, int count) { int i; - struct kevent *ke, **el; + struct kevent *ke; struct sys_kevent_args *uap; uap = (struct sys_kevent_args *)arg; - for (ke = kevp, i = 0; i < count; i++, ke++) { - if (uap->do_each) { - uap->do_each(&(uap->eventlist), ke); + if (!uap->do_each) { + bcopy(kevp, uap->eventlist, count * sizeof *kevp); + uap->eventlist = (void *)((struct kevent *)(uap->eventlist) + count); - } else { - el = (struct kevent **)(&uap->eventlist); - **el = *ke; - (*el)++; + } else { + for (ke = kevp, i = 0; i < count; i++, ke++) { + uap->do_each(&(uap->eventlist), ke); } }