# define EV_USE_SELECT 1
# endif
-# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL)
+# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) && !defined (__APPLE__)
# define EV_USE_POLL 1
# endif
-# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL)
+# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL)
# define EV_USE_EPOLL 1
# endif
-# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE)
+# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) && !defined (__APPLE__)
# define EV_USE_KQUEUE 1
# endif
#include <signal.h>
-#ifndef WIN32
+#ifndef _WIN32
# include <unistd.h>
# include <sys/time.h>
# include <sys/wait.h>
+#else
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+# ifndef EV_SELECT_IS_WINSOCKET
+# define EV_SELECT_IS_WINSOCKET 1
+# endif
#endif
+
/**/
#ifndef EV_USE_MONOTONIC
#ifndef EV_USE_SELECT
# define EV_USE_SELECT 1
+# define EV_SELECT_USE_FD_SET 1
#endif
#ifndef EV_USE_POLL
-# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */
+# ifdef _WIN32
+# define EV_USE_POLL 0
+# else
+# define EV_USE_POLL 1
+# endif
#endif
#ifndef EV_USE_EPOLL
# define EV_USE_KQUEUE 0
#endif
-#ifndef EV_USE_WIN32
-# ifdef WIN32
-# define EV_USE_WIN32 0 /* it does not exist, use select */
-# undef EV_USE_SELECT
-# define EV_USE_SELECT 1
-# else
-# define EV_USE_WIN32 0
-# endif
-#endif
-
#ifndef EV_USE_REALTIME
# define EV_USE_REALTIME 1
#endif
# define EV_USE_REALTIME 0
#endif
+#if EV_SELECT_IS_WINSOCKET
+# include <winsock.h>
+#endif
+
/**/
#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
#define ABSPRI(w) ((w)->priority - EV_MINPRI)
+#define EMPTY /* required for microsofts broken pseudo-c compiler */
+
typedef struct ev_watcher *W;
typedef struct ev_watcher_list *WL;
typedef struct ev_watcher_time *WT;
static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
-#include "ev_win32.c"
+#ifdef _WIN32
+# include "ev_win32.c"
+#endif
/*****************************************************************************/
WL head;
unsigned char events;
unsigned char reify;
+#if EV_SELECT_IS_WINSOCKET
+ SOCKET handle;
+#endif
} ANFD;
typedef struct
struct ev_loop
{
ev_tstamp ev_rt_now;
+ #define ev_rt_now ((loop)->ev_rt_now)
#define VAR(name,decl) decl;
#include "ev_vars.h"
#undef VAR
fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
}
-/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */
-/* bringing us everlasting joy in form of stupid extra macros that are not required in C */
-#define array_free_microshit(stem) \
- ev_free (stem ## s); stem ## cnt = stem ## max = 0;
-
#define array_free(stem, idx) \
ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
events |= w->events;
+#if EV_SELECT_IS_WINSOCKET
+ if (events)
+ {
+ unsigned long argp;
+ anfd->handle = _get_osfhandle (fd);
+ assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0));
+ }
+#endif
+
anfd->reify = 0;
method_modify (EV_A_ fd, anfd->events, events);
static int
fd_valid (int fd)
{
-#ifdef WIN32
- return !!win32_get_osfhandle (fd);
+#ifdef _WIN32
+ return _get_osfhandle (fd) != -1;
#else
return fcntl (fd, F_GETFD) != -1;
#endif
}
inline void
-adjustheap (WT *heap, int N, int k, ev_tstamp at)
+adjustheap (WT *heap, int N, int k)
{
- ev_tstamp old_at = heap [k]->at;
- heap [k]->at = at;
-
- if (old_at < at)
- downheap (heap, N, k);
- else
- upheap (heap, k);
+ upheap (heap, k);
+ downheap (heap, N, k);
}
/*****************************************************************************/
static void
sighandler (int signum)
{
-#if WIN32
+#if _WIN32
signal (signum, sighandler);
#endif
{
int old_errno = errno;
gotsig = 1;
-#ifdef WIN32
- send (sigpipe [1], &signum, 1, MSG_DONTWAIT);
-#else
write (sigpipe [1], &signum, 1);
-#endif
errno = old_errno;
}
}
{
int signum;
-#ifdef WIN32
- recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
-#else
read (sigpipe [0], &revents, 1);
-#endif
gotsig = 0;
for (signum = signalmax; signum--; )
ev_feed_signal_event (EV_A_ signum + 1);
}
+inline void
+fd_intern (int fd)
+{
+#ifdef _WIN32
+ int arg = 1;
+ ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
+#else
+ fcntl (fd, F_SETFD, FD_CLOEXEC);
+ fcntl (fd, F_SETFL, O_NONBLOCK);
+#endif
+}
+
static void
siginit (EV_P)
{
-#ifndef WIN32
- fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC);
- fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC);
-
- /* rather than sort out wether we really need nb, set it */
- fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
- fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
-#endif
+ fd_intern (sigpipe [0]);
+ fd_intern (sigpipe [1]);
ev_io_set (&sigev, sigpipe [0], EV_READ);
ev_io_start (EV_A_ &sigev);
static struct ev_child *childs [PID_HASHSIZE];
-#ifndef WIN32
+#ifndef _WIN32
static struct ev_signal childev;
static int
enable_secure (void)
{
-#ifdef WIN32
+#ifdef _WIN32
return 0;
#else
return getuid () != geteuid ()
methods = EVMETHOD_ANY;
method = 0;
-#if EV_USE_WIN32
- if (!method && (methods & EVMETHOD_WIN32 )) method = win32_init (EV_A_ methods);
-#endif
#if EV_USE_KQUEUE
if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods);
#endif
{
int i;
-#if EV_USE_WIN32
- if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
-#endif
#if EV_USE_KQUEUE
if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
#endif
array_free (pending, [i]);
/* have to use the microsoft-never-gets-it-right macro */
- array_free_microshit (fdchange);
- array_free_microshit (timer);
+ array_free (fdchange, EMPTY);
+ array_free (timer, EMPTY);
#if EV_PERIODICS
- array_free_microshit (periodic);
+ array_free (periodic, EMPTY);
#endif
- array_free_microshit (idle);
- array_free_microshit (prepare);
- array_free_microshit (check);
+ array_free (idle, EMPTY);
+ array_free (prepare, EMPTY);
+ array_free (check, EMPTY);
method = 0;
}
{
siginit (EV_A);
-#ifndef WIN32
+#ifndef _WIN32
ev_signal_init (&childev, childcb, SIGCHLD);
ev_set_priority (&childev, EV_MAXPRI);
ev_signal_start (EV_A_ &childev);
struct ev_loop *loop = default_loop;
#endif
-#ifndef WIN32
+#ifndef _WIN32
ev_ref (EV_A); /* child watcher */
ev_signal_stop (EV_A_ &childev);
#endif
if (((W)w)->active < timercnt--)
{
timers [((W)w)->active - 1] = timers [timercnt];
- downheap ((WT *)timers, timercnt, ((W)w)->active - 1);
+ adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
}
((WT)w)->at -= mn_now;
if (ev_is_active (w))
{
if (w->repeat)
- adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat);
+ {
+ ((WT)w)->at = mn_now + w->repeat;
+ adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
+ }
else
ev_timer_stop (EV_A_ w);
}
if (((W)w)->active < periodiccnt--)
{
periodics [((W)w)->active - 1] = periodics [periodiccnt];
- downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
+ adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
}
ev_stop (EV_A_ (W)w);
ev_idle_stop (EV_P_ struct ev_idle *w)
{
ev_clear_pending (EV_A_ (W)w);
- if (ev_is_active (w))
+ if (!ev_is_active (w))
return;
idles [((W)w)->active - 1] = idles [--idlecnt];
ev_prepare_stop (EV_P_ struct ev_prepare *w)
{
ev_clear_pending (EV_A_ (W)w);
- if (ev_is_active (w))
+ if (!ev_is_active (w))
return;
prepares [((W)w)->active - 1] = prepares [--preparecnt];
if (!((WL)w)->next)
{
-#if WIN32
+#if _WIN32
signal (w->signum, sighandler);
#else
struct sigaction sa;