#include <math.h>
#include <stdlib.h>
-#include <unistd.h>
#include <fcntl.h>
-#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
+#include <time.h>
+
+#ifndef PERL
+# include <signal.h>
+#endif
+
#ifndef WIN32
+# include <unistd.h>
+# include <sys/time.h>
# include <sys/wait.h>
#endif
-#include <sys/time.h>
-#include <time.h>
-
/**/
#ifndef EV_USE_MONOTONIC
#ifndef EV_USE_WIN32
# ifdef WIN32
-# define EV_USE_WIN32 1
+# 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
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;
}
w->pending = ++pendingcnt [ABSPRI (w)];
- array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], );
+ array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void));
pendings [ABSPRI (w)][w->pending - 1].w = w;
pendings [ABSPRI (w)][w->pending - 1].events = events;
}
anfds [fd].reify = 1;
++fdchangecnt;
- array_needsize (fdchanges, fdchangemax, fdchangecnt, );
+ array_needsize (fdchanges, fdchangemax, fdchangecnt, (void));
fdchanges [fdchangecnt - 1] = fd;
}
}
}
+static int
+fd_valid (int fd)
+{
+#ifdef WIN32
+ return !!win32_get_osfhandle (fd);
+#else
+ return fcntl (fd, F_GETFD) != -1;
+#endif
+}
+
/* called on EBADF to verify fds */
static void
fd_ebadf (EV_P)
for (fd = 0; fd < anfdmax; ++fd)
if (anfds [fd].events)
- if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
+ if (!fd_valid (fd) == -1 && errno == EBADF)
fd_kill (EV_A_ fd);
}
/*****************************************************************************/
+static struct ev_child *childs [PID_HASHSIZE];
+
#ifndef WIN32
-static struct ev_child *childs [PID_HASHSIZE];
static struct ev_signal childev;
#ifndef WCONTINUED
for (i = NUMPRI; i--; )
array_free (pending, [i]);
- array_free (fdchange, );
- array_free (timer, );
- array_free (periodic, );
- array_free (idle, );
- array_free (prepare, );
- array_free (check, );
+ /* have to use the microsoft-never-gets-it-right macro */
+ array_free_microshit (fdchange);
+ array_free_microshit (timer);
+ array_free_microshit (periodic);
+ array_free_microshit (idle);
+ array_free_microshit (prepare);
+ array_free_microshit (check);
method = 0;
}
struct ev_loop *loop = default_loop;
#endif
+#ifndef WIN32
ev_ref (EV_A); /* child watcher */
ev_signal_stop (EV_A_ &childev);
+#endif
ev_ref (EV_A); /* signal watcher */
ev_io_stop (EV_A_ &sigev);
assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
ev_start (EV_A_ (W)w, ++timercnt);
- array_needsize (timers, timermax, timercnt, );
+ array_needsize (timers, timermax, timercnt, (void));
timers [timercnt - 1] = w;
upheap ((WT *)timers, timercnt - 1);
((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
ev_start (EV_A_ (W)w, ++periodiccnt);
- array_needsize (periodics, periodicmax, periodiccnt, );
+ array_needsize (periodics, periodicmax, periodiccnt, (void));
periodics [periodiccnt - 1] = w;
upheap ((WT *)periodics, periodiccnt - 1);
return;
ev_start (EV_A_ (W)w, ++idlecnt);
- array_needsize (idles, idlemax, idlecnt, );
+ array_needsize (idles, idlemax, idlecnt, (void));
idles [idlecnt - 1] = w;
}
return;
ev_start (EV_A_ (W)w, ++preparecnt);
- array_needsize (prepares, preparemax, preparecnt, );
+ array_needsize (prepares, preparemax, preparecnt, (void));
prepares [preparecnt - 1] = w;
}
return;
ev_start (EV_A_ (W)w, ++checkcnt);
- array_needsize (checks, checkmax, checkcnt, );
+ array_needsize (checks, checkmax, checkcnt, (void));
checks [checkcnt - 1] = w;
}