1 |
root |
1.1 |
/* |
2 |
|
|
* libev win32 compatibility cruft |
3 |
|
|
* |
4 |
|
|
* Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
5 |
|
|
* All rights reserved. |
6 |
|
|
* |
7 |
|
|
* Redistribution and use in source and binary forms, with or without |
8 |
|
|
* modification, are permitted provided that the following conditions are |
9 |
|
|
* met: |
10 |
|
|
* |
11 |
|
|
* * Redistributions of source code must retain the above copyright |
12 |
|
|
* notice, this list of conditions and the following disclaimer. |
13 |
|
|
* |
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. |
18 |
|
|
* |
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. |
30 |
|
|
*/ |
31 |
|
|
|
32 |
root |
1.2 |
#ifdef _WIN32 |
33 |
root |
1.1 |
|
34 |
|
|
#include <sys/timeb.h> |
35 |
|
|
|
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; |
39 |
|
|
|
40 |
|
|
/* oh, the humanity! */ |
41 |
|
|
static int |
42 |
|
|
ev_pipe (int filedes [2]) |
43 |
|
|
{ |
44 |
|
|
struct sockaddr_in addr = { 0 }; |
45 |
|
|
int addr_size = sizeof (addr); |
46 |
|
|
SOCKET listener; |
47 |
|
|
SOCKET sock [2] = { -1, -1 }; |
48 |
|
|
|
49 |
|
|
if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
50 |
|
|
return -1; |
51 |
|
|
|
52 |
|
|
addr.sin_family = AF_INET; |
53 |
|
|
addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
54 |
|
|
addr.sin_port = 0; |
55 |
|
|
|
56 |
|
|
if (bind (listener, (struct sockaddr *)&addr, addr_size)) |
57 |
|
|
goto fail; |
58 |
|
|
|
59 |
|
|
if (getsockname(listener, (struct sockaddr *)&addr, &addr_size)) |
60 |
|
|
goto fail; |
61 |
|
|
|
62 |
|
|
if (listen (listener, 1)) |
63 |
|
|
goto fail; |
64 |
|
|
|
65 |
|
|
if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
66 |
|
|
goto fail; |
67 |
|
|
|
68 |
|
|
if (connect (sock[0], (struct sockaddr *)&addr, addr_size)) |
69 |
|
|
goto fail; |
70 |
|
|
|
71 |
|
|
if ((sock[1] = accept (listener, 0, 0)) < 0) |
72 |
|
|
goto fail; |
73 |
|
|
|
74 |
|
|
closesocket (listener); |
75 |
|
|
|
76 |
|
|
filedes [0] = sock [0]; |
77 |
|
|
filedes [1] = sock [1]; |
78 |
|
|
|
79 |
|
|
return 0; |
80 |
|
|
|
81 |
|
|
fail: |
82 |
|
|
closesocket (listener); |
83 |
|
|
|
84 |
|
|
if (sock [0] != INVALID_SOCKET) closesocket (sock [0]); |
85 |
|
|
if (sock [1] != INVALID_SOCKET) closesocket (sock [1]); |
86 |
|
|
|
87 |
|
|
return -1; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
#undef pipe |
91 |
|
|
#define pipe(filedes) ev_pipe (filedes) |
92 |
|
|
|
93 |
|
|
static int |
94 |
|
|
ev_gettimeofday (struct timeval *tv, struct timezone *tz) |
95 |
|
|
{ |
96 |
|
|
struct _timeb tb; |
97 |
|
|
|
98 |
|
|
_ftime (&tb); |
99 |
|
|
|
100 |
|
|
tv->tv_sec = (long)tb.time; |
101 |
|
|
tv->tv_usec = ((long)tb.millitm) * 1000; |
102 |
|
|
|
103 |
|
|
return 0; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
#undef gettimeofday |
107 |
root |
1.2 |
#define gettimeofday(tv,tz) ev_gettimeofday (tv, tz) |
108 |
root |
1.1 |
|
109 |
|
|
#endif |
110 |
root |
1.2 |
|