/* * Copyright 2000-2003 Niels Provos <[email protected]> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include <sys/types.h> #include <sys/resource.h> #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #else #include <sys/_libevent_time.h> #endif #include <sys/queue.h> #include <sys/epoll.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif #include "event.h" #include "event-internal.h" #include "evsignal.h" #include "log.h" /* due to limitations in the epoll interface, we need to keep track of * all file descriptors outself. */ struct evepoll { … }; struct epollop { … }; static void *epoll_init (struct event_base *); static int epoll_add (void *, struct event *); static int epoll_del (void *, struct event *); static int epoll_dispatch (struct event_base *, void *, struct timeval *); static void epoll_dealloc (struct event_base *, void *); const struct eventop epollops = …; #ifdef HAVE_SETFD #define FD_CLOSEONEXEC(x) … #else #define FD_CLOSEONEXEC … #endif /* On Linux kernels at least up to 2.6.24.4, epoll can't handle timeout * values bigger than (LONG_MAX - 999ULL)/HZ. HZ in the wild can be * as big as 1000, and LONG_MAX can be as small as (1<<31)-1, so the * largest number of msec we can support here is 2147482. Let's * round that down by 47 seconds. */ #define MAX_EPOLL_TIMEOUT_MSEC … #define INITIAL_NFILES … #define INITIAL_NEVENTS … #define MAX_NEVENTS … static void * epoll_init(struct event_base *base) { … } static int epoll_recalc(struct event_base *base, void *arg, int max) { … } static int epoll_dispatch(struct event_base *base, void *arg, struct timeval *tv) { … } static int epoll_add(void *arg, struct event *ev) { … } static int epoll_del(void *arg, struct event *ev) { … } static void epoll_dealloc(struct event_base *base, void *arg) { … }