First page Back Continue Last page Summary Graphics
Examples
kqueue() in stead of poll():
handle_events()
{
int i, n, timeout = TIMEOUT;
n = poll(pfd, nfds, timeout);
if (n <= 0)
goto error_or_timeout;
for (i = 0; n != 0; i++) {
if (pfdi.revents == 0)
continue;
n--;
if (pfdi.revents & (POLLERR | POLLNVAL))
/* error */
if (pfdi.revents & POLLIN)
readable_fd(pfdi.fd);
if (pfdi.revents & POLLOUT)
writeable_fd(pfdi.fd);
}
...
}
update_fd(int fd, int action, int events)
{
if (action == ADD) {
pfdfd.fd = fd;
pfdfd.events = events;
} else
pfdfd.fd = -1;
}
Notes: