X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/36718ee47b617f9eeb411c70d1dd87bc33389db3..4b05fe94e44407cd62092863e204337c521e7d8a:/ev.c?ds=inline diff --git a/ev.c b/ev.c index 79b3786..e3e7e57 100644 --- a/ev.c +++ b/ev.c @@ -150,64 +150,7 @@ typedef struct ev_watcher_time *WT; static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ -#if WIN32 -/* note: the comment below could not be substantiated, but what would I care */ -/* MSDN says this is required to handle SIGFPE */ -volatile double SIGFPE_REQ = 0.0f; - -static int -ev_socketpair_tcp (int filedes [2]) -{ - struct sockaddr_in addr = { 0 }; - int addr_size = sizeof (addr); - SOCKET listener; - SOCKET sock [2] = { -1, -1 }; - - if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) - return -1; - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); - addr.sin_port = 0; - - if (bind (listener, (struct sockaddr *)&addr, addr_size)) - goto fail; - - if (getsockname(listener, (struct sockaddr *)&addr, &addr_size)) - goto fail; - - if (listen (listener, 1)) - goto fail; - - if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) - goto fail; - - if (connect (sock[0], (struct sockaddr *)&addr, addr_size)) - goto fail; - - if ((sock[1] = accept (listener, 0, 0)) < 0) - goto fail; - - closesocket (listener); - - filedes [0] = sock [0]; - filedes [1] = sock [1]; - - return 0; - -fail: - closesocket (listener); - - if (sock [0] != INVALID_SOCKET) closesocket (sock [0]); - if (sock [1] != INVALID_SOCKET) closesocket (sock [1]); - - return -1; -} - -# define ev_pipe(filedes) ev_socketpair_tcp (filedes) -#else -# define ev_pipe(filedes) pipe (filedes) -#endif +#include "ev_win32.c" /*****************************************************************************/ @@ -327,28 +270,28 @@ ev_now (EV_P) return rt_now; } -#define array_roundsize(base,n) ((n) | 4 & ~3) +#define array_roundsize(type,n) ((n) | 4 & ~3) -#define array_needsize(base,cur,cnt,init) \ +#define array_needsize(type,base,cur,cnt,init) \ if (expect_false ((cnt) > cur)) \ { \ int newcnt = cur; \ do \ { \ - newcnt = array_roundsize (base, newcnt << 1); \ + newcnt = array_roundsize (type, newcnt << 1); \ } \ while ((cnt) > newcnt); \ \ - base = ev_realloc (base, sizeof (*base) * (newcnt)); \ + base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\ init (base + cur, newcnt - cur); \ cur = newcnt; \ } -#define array_slim(stem) \ +#define array_slim(type,stem) \ if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ { \ stem ## max = array_roundsize (stem ## cnt >> 1); \ - base = ev_realloc (base, sizeof (*base) * (stem ## max)); \ + base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ } @@ -385,7 +328,7 @@ event (EV_P_ W w, int events) } w->pending = ++pendingcnt [ABSPRI (w)]; - array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void)); + array_needsize (ANPENDING, 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; } @@ -450,7 +393,7 @@ fd_change (EV_P_ int fd) anfds [fd].reify = 1; ++fdchangecnt; - array_needsize (fdchanges, fdchangemax, fdchangecnt, (void)); + array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void)); fdchanges [fdchangecnt - 1] = fd; } @@ -830,7 +773,7 @@ loop_fork (EV_P) close (sigpipe [0]); close (sigpipe [1]); - while (ev_pipe (sigpipe)) + while (pipe (sigpipe)) syserr ("(libev) error creating pipe"); siginit (EV_A); @@ -883,7 +826,7 @@ int ev_default_loop (int methods) { if (sigpipe [0] == sigpipe [1]) - if (ev_pipe (sigpipe)) + if (pipe (sigpipe)) return 0; if (!default_loop) @@ -1268,7 +1211,7 @@ ev_io_start (EV_P_ struct ev_io *w) assert (("ev_io_start called with negative fd", fd >= 0)); ev_start (EV_A_ (W)w, 1); - array_needsize (anfds, anfdmax, fd + 1, anfds_init); + array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); wlist_add ((WL *)&anfds[fd].head, (WL)w); fd_change (EV_A_ fd); @@ -1298,7 +1241,7 @@ ev_timer_start (EV_P_ struct ev_timer *w) 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, (void)); + array_needsize (struct ev_timer *, timers, timermax, timercnt, (void)); timers [timercnt - 1] = w; upheap ((WT *)timers, timercnt - 1); @@ -1355,7 +1298,7 @@ ev_periodic_start (EV_P_ struct ev_periodic *w) ((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, (void)); + array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); periodics [periodiccnt - 1] = w; upheap ((WT *)periodics, periodiccnt - 1); @@ -1387,7 +1330,7 @@ ev_idle_start (EV_P_ struct ev_idle *w) return; ev_start (EV_A_ (W)w, ++idlecnt); - array_needsize (idles, idlemax, idlecnt, (void)); + array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void)); idles [idlecnt - 1] = w; } @@ -1409,7 +1352,7 @@ ev_prepare_start (EV_P_ struct ev_prepare *w) return; ev_start (EV_A_ (W)w, ++preparecnt); - array_needsize (prepares, preparemax, preparecnt, (void)); + array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void)); prepares [preparecnt - 1] = w; } @@ -1431,7 +1374,7 @@ ev_check_start (EV_P_ struct ev_check *w) return; ev_start (EV_A_ (W)w, ++checkcnt); - array_needsize (checks, checkmax, checkcnt, (void)); + array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void)); checks [checkcnt - 1] = w; } @@ -1462,7 +1405,7 @@ ev_signal_start (EV_P_ struct ev_signal *w) assert (("ev_signal_start called with illegal signal number", w->signum > 0)); ev_start (EV_A_ (W)w, 1); - array_needsize (signals, signalmax, w->signum, signals_init); + array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); if (!((WL)w)->next) @@ -1555,7 +1498,7 @@ once_cb_to (EV_P_ struct ev_timer *w, int revents) void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) { - struct ev_once *once = ev_malloc (sizeof (struct ev_once)); + struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); if (!once) cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);