… | |
… | |
148 | typedef struct ev_watcher_list *WL; |
148 | typedef struct ev_watcher_list *WL; |
149 | typedef struct ev_watcher_time *WT; |
149 | typedef struct ev_watcher_time *WT; |
150 | |
150 | |
151 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
151 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
152 | |
152 | |
153 | #if WIN32 |
153 | #include "ev_win32.c" |
154 | /* note: the comment below could not be substantiated, but what would I care */ |
|
|
155 | /* MSDN says this is required to handle SIGFPE */ |
|
|
156 | volatile double SIGFPE_REQ = 0.0f; |
|
|
157 | |
|
|
158 | static int |
|
|
159 | ev_socketpair_tcp (int filedes [2]) |
|
|
160 | { |
|
|
161 | struct sockaddr_in addr = { 0 }; |
|
|
162 | int addr_size = sizeof (addr); |
|
|
163 | SOCKET listener; |
|
|
164 | SOCKET sock [2] = { -1, -1 }; |
|
|
165 | |
|
|
166 | if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
|
|
167 | return -1; |
|
|
168 | |
|
|
169 | addr.sin_family = AF_INET; |
|
|
170 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
|
|
171 | addr.sin_port = 0; |
|
|
172 | |
|
|
173 | if (bind (listener, (struct sockaddr *)&addr, addr_size)) |
|
|
174 | goto fail; |
|
|
175 | |
|
|
176 | if (getsockname(listener, (struct sockaddr *)&addr, &addr_size)) |
|
|
177 | goto fail; |
|
|
178 | |
|
|
179 | if (listen (listener, 1)) |
|
|
180 | goto fail; |
|
|
181 | |
|
|
182 | if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) |
|
|
183 | goto fail; |
|
|
184 | |
|
|
185 | if (connect (sock[0], (struct sockaddr *)&addr, addr_size)) |
|
|
186 | goto fail; |
|
|
187 | |
|
|
188 | if ((sock[1] = accept (listener, 0, 0)) < 0) |
|
|
189 | goto fail; |
|
|
190 | |
|
|
191 | closesocket (listener); |
|
|
192 | |
|
|
193 | filedes [0] = sock [0]; |
|
|
194 | filedes [1] = sock [1]; |
|
|
195 | |
|
|
196 | return 0; |
|
|
197 | |
|
|
198 | fail: |
|
|
199 | closesocket (listener); |
|
|
200 | |
|
|
201 | if (sock [0] != INVALID_SOCKET) closesocket (sock [0]); |
|
|
202 | if (sock [1] != INVALID_SOCKET) closesocket (sock [1]); |
|
|
203 | |
|
|
204 | return -1; |
|
|
205 | } |
|
|
206 | |
|
|
207 | # define ev_pipe(filedes) ev_socketpair_tcp (filedes) |
|
|
208 | #else |
|
|
209 | # define ev_pipe(filedes) pipe (filedes) |
|
|
210 | #endif |
|
|
211 | |
154 | |
212 | /*****************************************************************************/ |
155 | /*****************************************************************************/ |
213 | |
156 | |
214 | static void (*syserr_cb)(const char *msg); |
157 | static void (*syserr_cb)(const char *msg); |
215 | |
158 | |
… | |
… | |
828 | ev_ref (EV_A); |
771 | ev_ref (EV_A); |
829 | ev_io_stop (EV_A_ &sigev); |
772 | ev_io_stop (EV_A_ &sigev); |
830 | close (sigpipe [0]); |
773 | close (sigpipe [0]); |
831 | close (sigpipe [1]); |
774 | close (sigpipe [1]); |
832 | |
775 | |
833 | while (ev_pipe (sigpipe)) |
776 | while (pipe (sigpipe)) |
834 | syserr ("(libev) error creating pipe"); |
777 | syserr ("(libev) error creating pipe"); |
835 | |
778 | |
836 | siginit (EV_A); |
779 | siginit (EV_A); |
837 | } |
780 | } |
838 | |
781 | |
… | |
… | |
881 | int |
824 | int |
882 | #endif |
825 | #endif |
883 | ev_default_loop (int methods) |
826 | ev_default_loop (int methods) |
884 | { |
827 | { |
885 | if (sigpipe [0] == sigpipe [1]) |
828 | if (sigpipe [0] == sigpipe [1]) |
886 | if (ev_pipe (sigpipe)) |
829 | if (pipe (sigpipe)) |
887 | return 0; |
830 | return 0; |
888 | |
831 | |
889 | if (!default_loop) |
832 | if (!default_loop) |
890 | { |
833 | { |
891 | #if EV_MULTIPLICITY |
834 | #if EV_MULTIPLICITY |