2 * libev win32 compatibility cruft
4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/timeb.h>
36 /* note: the comment below could not be substantiated, but what would I care */
37 /* MSDN says this is required to handle SIGFPE */
38 volatile double SIGFPE_REQ = 0.0f;
40 /* oh, the humanity! */
42 ev_pipe (int filedes [2])
44 struct sockaddr_in addr = { 0 };
45 int addr_size = sizeof (addr);
47 SOCKET sock [2] = { -1, -1 };
49 if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
52 addr.sin_family = AF_INET;
53 addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
56 if (bind (listener, (struct sockaddr *)&addr, addr_size))
59 if (getsockname(listener, (struct sockaddr *)&addr, &addr_size))
62 if (listen (listener, 1))
65 if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
68 if (connect (sock[0], (struct sockaddr *)&addr, addr_size))
71 if ((sock[1] = accept (listener, 0, 0)) < 0)
74 closesocket (listener);
76 #if EV_SELECT_IS_WINSOCKET
77 filedes [0] = _open_osfhandle (sock [0], 0);
78 filedes [1] = _open_osfhandle (sock [1], 0);
80 /* when select isn't winsocket, we also expect socket, connect, accept etc.
82 filedes [0] = sock [0];
83 filedes [1] = sock [1];
89 closesocket (listener);
91 if (sock [0] != INVALID_SOCKET) closesocket (sock [0]);
92 if (sock [1] != INVALID_SOCKET) closesocket (sock [1]);
98 #define pipe(filedes) ev_pipe (filedes)
101 ev_gettimeofday (struct timeval *tv, struct timezone *tz)
107 tv->tv_sec = (long)tb.time;
108 tv->tv_usec = ((long)tb.millitm) * 1000;
114 #define gettimeofday(tv,tz) ev_gettimeofday (tv, tz)