summaryrefslogtreecommitdiff
path: root/ev.c
diff options
context:
space:
mode:
authorroot <root>2007-11-06 16:09:37 +0000
committerroot <root>2007-11-06 16:09:37 +0000
commit36718ee47b617f9eeb411c70d1dd87bc33389db3 (patch)
tree0d3cf784be49cf9d8848a2af1afe3e682553b5d0 /ev.c
parent4ee0973144c5b6c7cf136b1256e7ce9cb802e682 (diff)
big win32 check-in
Diffstat (limited to 'ev.c')
-rw-r--r--ev.c61
1 files changed, 56 insertions, 5 deletions
diff --git a/ev.c b/ev.c
index 0976897..79b3786 100644
--- a/ev.c
+++ b/ev.c
@@ -66,9 +66,7 @@
#include <sys/types.h>
#include <time.h>
-#ifndef PERL
-# include <signal.h>
-#endif
+#include <signal.h>
#ifndef WIN32
# include <unistd.h>
@@ -156,6 +154,59 @@ static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
/* 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
/*****************************************************************************/
@@ -779,7 +830,7 @@ loop_fork (EV_P)
close (sigpipe [0]);
close (sigpipe [1]);
- while (pipe (sigpipe))
+ while (ev_pipe (sigpipe))
syserr ("(libev) error creating pipe");
siginit (EV_A);
@@ -832,7 +883,7 @@ int
ev_default_loop (int methods)
{
if (sigpipe [0] == sigpipe [1])
- if (pipe (sigpipe))
+ if (ev_pipe (sigpipe))
return 0;
if (!default_loop)