PERFORCE change 136770 for review
Roman Divacky
rdivacky at FreeBSD.org
Mon Mar 3 22:51:40 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=136770
Change 136770 by rdivacky at rdivacky_witten on 2008/03/03 22:51:17
Add some comments, adjust some other comments and fix a few style issues.
Suggested by: netchild
Affected files ...
.. //depot/projects/soc2007/rdivacky/linux_epoll/sys/compat/linux/linux_epoll.c#8 edit
Differences ...
==== //depot/projects/soc2007/rdivacky/linux_epoll/sys/compat/linux/linux_epoll.c#8 (text+ko) ====
@@ -47,6 +47,7 @@
#endif
+/* Create a new epoll file descriptor. */
int
linux_epoll_create(struct thread *td, struct linux_epoll_create_args *args)
{
@@ -54,11 +55,12 @@
if (args->size <= 0)
return (EINVAL);
- /* XXX: args->size is ignored. Linux ignores it as well. */
+ /* args->size is unused. Linux ignores it as well. */
- return kqueue(td, &k_args);
+ return (kqueue(td, &k_args));
}
+/* Structure converting function from epoll to kevent. */
static void
linux_epoll_to_kevent(int fd, struct linux_epoll_event *event, struct kevent *kevent)
{
@@ -71,7 +73,7 @@
filter |= EVFILT_WRITE;
if (event->events & LINUX_EPOLLPRI)
filter |= EVFILT_READ;
- if (event->events & LINUX_EPOLLET) /* XXX: not sure about this */
+ if (event->events & LINUX_EPOLLET)
flags |= EV_CLEAR;
if (event->events & LINUX_EPOLLONESHOT)
flags |= EV_ONESHOT;
@@ -79,6 +81,7 @@
EV_SET(kevent, fd, filter, flags, 0, 0, 0);
}
+/* Structure converting function from kevent to epoll. */
static void
linux_kevent_to_epoll(struct kevent *kevent, struct linux_epoll_event *event)
{
@@ -100,6 +103,11 @@
}
}
+/*
+ * Copyout callback used by kevent. This converts kevent
+ * events to epoll events and copies them back to the
+ * userspace.
+ */
static int
linux_kev_copyout(void *arg, struct kevent *kevp, int count)
{
@@ -123,6 +131,10 @@
return (0);
}
+/*
+ * Copyin callback used by kevent. This copies already
+ * converted filters to the kevent internal memory.
+ */
static int
linux_kev_copyin(void *arg, struct kevent *kevp, int count)
{
@@ -137,7 +149,10 @@
return (0);
}
-
+/*
+ * Load epoll filter, convert it to kevent filter
+ * and load it into kevent subsystem.
+ */
int
linux_epoll_ctl(struct thread *td, struct linux_epoll_ctl_args *args)
{
@@ -155,10 +170,11 @@
#ifdef DEBUG
if (ldebug(epoll_ctl))
printf(ARGS(epoll_ctl,"%i, %i, %i, %u"), args->epfd, args->op,
- args->fd, le.events);
+ args->fd, le.events);
#endif
k_args.fd = args->epfd;
- k_args.changelist = &kev; /* epoll can register only 1 filter at once*/
+ k_args.changelist = &kev;
+ /* The epoll can register only 1 filter at once. */
k_args.nchanges = 1;
k_args.eventlist = NULL;
k_args.nevents = 0;
@@ -169,18 +185,20 @@
kev.flags = EV_ADD | EV_ENABLE;
break;
case LINUX_EPOLL_CTL_MOD:
- /* XXX: DELETE && ADD maybe? */
+ /* TODO: DELETE && ADD maybe? */
return (EINVAL);
break;
case LINUX_EPOLL_CTL_DEL:
- kev.flags = EV_DELETE | EV_DISABLE;
+ kev.flags = EV_DELETE | EV_DISABLE;
break;
}
linux_epoll_to_kevent(args->fd, &le, &kev);
- return kern_kevent(td, args->epfd, 1, 0, &k_ops, NULL);
+ return (kern_kevent(td, args->epfd, 1, 0, &k_ops, NULL));
}
+/*
+ * Wait for a filter to be triggered on the epoll file descriptor. */
int
linux_epoll_wait(struct thread *td, struct linux_epoll_wait_args *args)
{
@@ -191,6 +209,7 @@
linux_kev_copyin};
int error;
+ /* Convert from miliseconds to timespec. */
ts.tv_sec = args->timeout / 1000000;
ts.tv_nsec = (args->timeout % 1000000) * 1000;
@@ -198,8 +217,9 @@
k_args.changelist = NULL;
k_args.nchanges = 0;
/*
- * we dont mind the wrong type-cast because
- * our copyout function handles this
+ * We don't mind the bogus type-cast because
+ * our copyout function knows about this and
+ * handles it correctly.
*/
k_args.eventlist = (struct kevent *)args->events;
k_args.nevents = args->maxevents;
@@ -207,6 +227,6 @@
error = kern_kevent(td, args->epfd, 0, args->maxevents, &k_ops, &ts);
- /* XXX: translation? */
+ /* translation? */
return (error);
}
More information about the p4-projects
mailing list