From 2fde047707205b8d8f1c71482d2df57105217e17 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 31 Oct 2007 20:46:44 +0000 Subject: stuffs --- Changes | 5 +++++ ev.c | 36 +++++++++++++++++++++++++++--------- ev.h | 25 +++++++++++++++---------- ev_epoll.c | 10 +++++++--- ev_select.c | 7 ++++--- 5 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 Changes diff --git a/Changes b/Changes new file mode 100644 index 0000000..a60c3b4 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for libev, a high-performance and full-featured event loop + +0.1 Wed Oct 31 21:31:48 CET 2007 + - original version; hacked together in <24h. + diff --git a/ev.c b/ev.c index f48b007..8a09326 100644 --- a/ev.c +++ b/ev.c @@ -199,7 +199,7 @@ queue_events (W *events, int eventcnt, int type) /* called on EBADF to verify fds */ static void -fd_recheck () +fd_recheck (void) { int fd; @@ -207,7 +207,10 @@ fd_recheck () if (anfds [fd].wev) if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) while (anfds [fd].head) - evio_stop (anfds [fd].head); + { + event ((W)anfds [fd].head, EV_ERROR); + evio_stop (anfds [fd].head); + } } /*****************************************************************************/ @@ -374,6 +377,18 @@ childcb (struct ev_signal *sw, int revents) # include "ev_select.c" #endif +int +ev_version_major (void) +{ + return EV_VERSION_MAJOR; +} + +int +ev_version_minor (void) +{ + return EV_VERSION_MINOR; +} + int ev_init (int flags) { if (!ev_method) @@ -416,17 +431,20 @@ int ev_init (int flags) /*****************************************************************************/ -void ev_prefork (void) +void +ev_prefork (void) { /* nop */ } -void ev_postfork_parent (void) +void +ev_postfork_parent (void) { /* nop */ } -void ev_postfork_child (void) +void +ev_postfork_child (void) { #if HAVE_EPOLL if (ev_method == EVMETHOD_EPOLL) @@ -469,7 +487,7 @@ fd_reify (void) } static void -call_pending () +call_pending (void) { while (pendingcnt) { @@ -484,7 +502,7 @@ call_pending () } static void -timers_reify () +timers_reify (void) { while (timercnt && timers [0]->at <= now) { @@ -505,7 +523,7 @@ timers_reify () } static void -periodics_reify () +periodics_reify (void) { while (periodiccnt && periodics [0]->at <= ev_now) { @@ -551,7 +569,7 @@ periodics_reschedule (ev_tstamp diff) } static void -time_update () +time_update (void) { int i; diff --git a/ev.h b/ev.h index 6a32606..0454138 100644 --- a/ev.h +++ b/ev.h @@ -34,16 +34,16 @@ typedef double ev_tstamp; /* eventmask, revents, events... */ #define EV_UNDEF -1 /* guaranteed to be invalid */ -#define EV_NONE 0x00 -#define EV_READ 0x01 -#define EV_WRITE 0x02 -#define EV_TIMEOUT 0x04 -#define EV_SIGNAL 0x08 -#define EV_IDLE 0x10 -#define EV_CHECK 0x20 -#define EV_PREPARE 0x40 -#define EV_CHILD 0x80 -#define EV_ERROR (0xff|0x8000) +#define EV_NONE 0x000000 +#define EV_READ 0x000001 +#define EV_WRITE 0x000002 +#define EV_TIMEOUT 0x000004 +#define EV_SIGNAL 0x000008 +#define EV_IDLE 0x000010 +#define EV_CHECK 0x000020 +#define EV_PREPARE 0x000040 +#define EV_CHILD 0x000080 +#define EV_ERROR 0x800000 /* can be used to add custom fields to all watchers */ #ifndef EV_COMMON @@ -53,6 +53,9 @@ typedef double ev_tstamp; # define EV_PROTOTYPES 1 #endif +#define EV_VERSION_MAJOR 1 +#define EV_VERSION_MINOR 1 + /* * struct member types: * private: you can look at them, but not change them, and they might not mean anything to you. @@ -157,6 +160,8 @@ struct ev_child #if EV_PROTOTYPES extern int ev_method; int ev_init (int flags); /* returns ev_method */ +int ev_version_major (void); +int ev_version_minor (void); /* these three calls are suitable for plugging into pthread_atfork */ void ev_prefork (void); diff --git a/ev_epoll.c b/ev_epoll.c index c6d3af5..92587c2 100644 --- a/ev_epoll.c +++ b/ev_epoll.c @@ -45,7 +45,8 @@ epoll_modify (int fd, int oev, int nev) epoll_ctl (epoll_fd, mode, fd, &ev); } -void epoll_postfork_child (void) +static void +epoll_postfork_child (void) { int fd; @@ -61,7 +62,8 @@ void epoll_postfork_child (void) static struct epoll_event *events; static int eventmax; -static void epoll_poll (ev_tstamp timeout) +static void +epoll_poll (ev_tstamp timeout) { int eventcnt = epoll_wait (epoll_fd, events, eventmax, ceil (timeout * 1000.)); int i; @@ -85,7 +87,8 @@ static void epoll_poll (ev_tstamp timeout) } } -void epoll_init (int flags) +static void +epoll_init (int flags) { epoll_fd = epoll_create (256); @@ -102,3 +105,4 @@ void epoll_init (int flags) eventmax = 64; /* intiial number of events receivable per poll */ events = malloc (sizeof (struct epoll_event) * eventmax); } + diff --git a/ev_select.c b/ev_select.c index 46a77e2..0dfa312 100644 --- a/ev_select.c +++ b/ev_select.c @@ -70,7 +70,8 @@ select_modify (int fd, int oev, int nev) vec_wi [offs] &= ~mask; } -static void select_poll (ev_tstamp timeout) +static void +select_poll (ev_tstamp timeout) { struct timeval tv; int res; @@ -117,7 +118,8 @@ static void select_poll (ev_tstamp timeout) } } -void select_init (int flags) +static void +select_init (int flags) { ev_method = EVMETHOD_SELECT; method_fudge = 1e-2; /* needed to compensate for select returning early, very conservative */ @@ -125,4 +127,3 @@ void select_init (int flags) method_poll = select_poll; } - -- cgit v1.2.3