Merge pull request #1 from F-Stack/master

update to data
dev
chenwei 2017-12-07 21:08:20 +08:00 committed by GitHub
commit 7138141b32
2 changed files with 63 additions and 24 deletions

View File

@ -185,7 +185,7 @@ static MALLOC_DEFINE(M_SCTPNAT, "sctpnat", "sctp nat dbs");
/* Use kernel allocator. */
#ifdef _SYS_MALLOC_H_
#define sn_malloc(x) malloc(x, M_SCTPNAT, M_NOWAIT|M_ZERO)
#define sn_calloc(n,x) sn_malloc(x * n)
#define sn_calloc(n,x) sn_malloc((x) * (n))
#define sn_free(x) free(x, M_SCTPNAT)
#endif// #ifdef _SYS_MALLOC_H_

View File

@ -27,40 +27,79 @@ ff_epoll_create(int size __attribute__((__unused__)))
return ff_kqueue();
}
int
int
ff_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
{
struct kevent kev[3];
/*
* Since kqueue uses EVFILT_READ and EVFILT_WRITE filters to
* handle read/write events, so we need two kevents.
*/
const int changes = 2;
struct kevent kev[changes];
int flags = 0;
int read_flags, write_flags;
if (!event && op != EPOLL_CTL_DEL) {
if ((!event && op != EPOLL_CTL_DEL) ||
(op != EPOLL_CTL_ADD &&
op != EPOLL_CTL_MOD &&
op != EPOLL_CTL_DEL)) {
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) {
/*
* EPOLL_CTL_DEL doesn't need to care for event->events.
*/
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, changes, NULL, 0, NULL);
}
return ff_kevent(epfd, kev, 3, NULL, 0, NULL);
/*
* FIXME:
*
* Kqueue doesn't have edge-triggered mode that exactly
* same with epoll, the most similar way is setting EV_CLEAR
* or EV_DISPATCH flag, but there are still some differences.
*
* EV_CLEAR:after the event is retrieved by the user,
* its state is reset.
* EV_DISPATCH: disable the event source immediately
* after delivery of an event.
*
* Here we use EV_CLEAR temporarily.
*
*/
if (event->events & EPOLLET) {
flags |= EV_CLEAR;
}
if (event->events & EPOLLONESHOT) {
flags |= EV_ONESHOT;
}
if (op == EPOLL_CTL_ADD) {
flags |= EV_ADD;
}
read_flags = write_flags = flags | EV_DISABLE;
if (event->events & EPOLLIN) {
read_flags &= ~EV_DISABLE;
read_flags |= EV_ENABLE;
}
if (event->events & EPOLLOUT) {
write_flags &= ~EV_DISABLE;
write_flags |= EV_ENABLE;
}
EV_SET(&kev[0], fd, EVFILT_READ, read_flags, 0, 0, NULL);
EV_SET(&kev[1], fd, EVFILT_WRITE, write_flags, 0, 0, NULL);
return ff_kevent(epfd, kev, changes, NULL, 0, NULL);
}
static void