mirror of https://github.com/F-Stack/f-stack.git
kevent copyout directly without
This commit is contained in:
parent
1a78ce8ea6
commit
850cbeb422
|
@ -24,43 +24,43 @@
|
||||||
int
|
int
|
||||||
ff_epoll_create(int size __attribute__((__unused__)))
|
ff_epoll_create(int size __attribute__((__unused__)))
|
||||||
{
|
{
|
||||||
return ff_kqueue();
|
return ff_kqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ff_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
|
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;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op == EPOLL_CTL_ADD){
|
if (op == EPOLL_CTL_ADD){
|
||||||
EV_SET(&kev[0], fd, EVFILT_READ,
|
EV_SET(&kev[0], fd, EVFILT_READ,
|
||||||
EV_ADD | (event->events & EPOLLIN ? 0 : EV_DISABLE), 0, 0, NULL);
|
EV_ADD | (event->events & EPOLLIN ? 0 : EV_DISABLE), 0, 0, NULL);
|
||||||
EV_SET(&kev[1], fd, EVFILT_WRITE,
|
EV_SET(&kev[1], fd, EVFILT_WRITE,
|
||||||
EV_ADD | (event->events & EPOLLOUT ? 0 : EV_DISABLE), 0, 0, NULL);
|
EV_ADD | (event->events & EPOLLOUT ? 0 : EV_DISABLE), 0, 0, NULL);
|
||||||
EV_SET(&kev[2], fd, EVFILT_USER, EV_ADD,
|
EV_SET(&kev[2], fd, EVFILT_USER, EV_ADD,
|
||||||
event->events & EPOLLRDHUP ? 1 : 0, 0, NULL);
|
event->events & EPOLLRDHUP ? 1 : 0, 0, NULL);
|
||||||
} else if (op == EPOLL_CTL_DEL) {
|
} else if (op == EPOLL_CTL_DEL) {
|
||||||
EV_SET(&kev[0], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
|
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[1], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
|
||||||
EV_SET(&kev[2], fd, EVFILT_USER, EV_DELETE, 0, 0, NULL);
|
EV_SET(&kev[2], fd, EVFILT_USER, EV_DELETE, 0, 0, NULL);
|
||||||
} else if (op == EPOLL_CTL_MOD) {
|
} else if (op == EPOLL_CTL_MOD) {
|
||||||
EV_SET(&kev[0], fd, EVFILT_READ,
|
EV_SET(&kev[0], fd, EVFILT_READ,
|
||||||
event->events & EPOLLIN ? EV_ENABLE : EV_DISABLE, 0, 0, NULL);
|
event->events & EPOLLIN ? EV_ENABLE : EV_DISABLE, 0, 0, NULL);
|
||||||
EV_SET(&kev[1], fd, EVFILT_WRITE,
|
EV_SET(&kev[1], fd, EVFILT_WRITE,
|
||||||
event->events & EPOLLOUT ? EV_ENABLE : EV_DISABLE, 0, 0, NULL);
|
event->events & EPOLLOUT ? EV_ENABLE : EV_DISABLE, 0, 0, NULL);
|
||||||
EV_SET(&kev[2], fd, EVFILT_USER, 0,
|
EV_SET(&kev[2], fd, EVFILT_USER, 0,
|
||||||
NOTE_FFCOPY | (event->events & EPOLLRDHUP ? 1 : 0), 0, NULL);
|
NOTE_FFCOPY | (event->events & EPOLLRDHUP ? 1 : 0), 0, NULL);
|
||||||
} else {
|
} else {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ff_kevent(epfd, kev, 3, NULL, 0, NULL);
|
return ff_kevent(epfd, kev, 3, NULL, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -81,7 +81,7 @@ ff_event_to_epoll(void **ev, struct kevent *kev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kev->flags & EV_EOF) {
|
if (kev->flags & EV_EOF) {
|
||||||
event_one |= EPOLLIN;
|
event_one |= EPOLLIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*ppev)->events = event_one;
|
(*ppev)->events = event_one;
|
||||||
|
@ -93,11 +93,11 @@ int
|
||||||
ff_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
|
ff_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
|
||||||
{
|
{
|
||||||
int i, ret;
|
int i, ret;
|
||||||
if (!events || maxevents < 1) {
|
if (!events || maxevents < 1) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -946,19 +946,18 @@ static int
|
||||||
kevent_copyout(void *arg, struct kevent *kevp, int count)
|
kevent_copyout(void *arg, struct kevent *kevp, int count)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct kevent *ke, **el;
|
struct kevent *ke;
|
||||||
struct sys_kevent_args *uap;
|
struct sys_kevent_args *uap;
|
||||||
|
|
||||||
uap = (struct sys_kevent_args *)arg;
|
uap = (struct sys_kevent_args *)arg;
|
||||||
|
|
||||||
for (ke = kevp, i = 0; i < count; i++, ke++) {
|
if (!uap->do_each) {
|
||||||
if (uap->do_each) {
|
bcopy(kevp, uap->eventlist, count * sizeof *kevp);
|
||||||
uap->do_each(&(uap->eventlist), ke);
|
uap->eventlist = (void *)((struct kevent *)(uap->eventlist) + count);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
el = (struct kevent **)(&uap->eventlist);
|
for (ke = kevp, i = 0; i < count; i++, ke++) {
|
||||||
**el = *ke;
|
uap->do_each(&(uap->eventlist), ke);
|
||||||
(*el)++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue