… | |
… | |
20 | (PERL_REVISION > (a) \ |
20 | (PERL_REVISION > (a) \ |
21 | || (PERL_REVISION == (a) \ |
21 | || (PERL_REVISION == (a) \ |
22 | && (PERL_VERSION > (b) \ |
22 | && (PERL_VERSION > (b) \ |
23 | || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) |
23 | || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) |
24 | |
24 | |
|
|
25 | #ifndef PERL_MAGIC_ext |
|
|
26 | # define PERL_MAGIC_ext '~' |
|
|
27 | #endif |
|
|
28 | |
25 | #if !PERL_VERSION_ATLEAST (5,6,0) |
29 | #if !PERL_VERSION_ATLEAST (5,6,0) |
26 | # ifndef PL_ppaddr |
30 | # ifndef PL_ppaddr |
27 | # define PL_ppaddr ppaddr |
31 | # define PL_ppaddr ppaddr |
28 | # endif |
32 | # endif |
29 | # ifndef call_sv |
33 | # ifndef call_sv |
… | |
… | |
209 | /* taken almost verbatim from libev's ev_win32.c */ |
213 | /* taken almost verbatim from libev's ev_win32.c */ |
210 | /* oh, the humanity! */ |
214 | /* oh, the humanity! */ |
211 | static int |
215 | static int |
212 | s_pipe (int filedes [2]) |
216 | s_pipe (int filedes [2]) |
213 | { |
217 | { |
|
|
218 | dTHX; |
|
|
219 | |
214 | struct sockaddr_in addr = { 0 }; |
220 | struct sockaddr_in addr = { 0 }; |
215 | int addr_size = sizeof (addr); |
221 | int addr_size = sizeof (addr); |
216 | struct sockaddr_in adr2; |
222 | struct sockaddr_in adr2; |
217 | int adr2_size = sizeof (adr2); |
223 | int adr2_size = sizeof (adr2); |
218 | SOCKET listener; |
224 | SOCKET listener; |
… | |
… | |
337 | #endif |
343 | #endif |
338 | |
344 | |
339 | typedef struct { |
345 | typedef struct { |
340 | int fd[2]; /* read, write fd, might be equal */ |
346 | int fd[2]; /* read, write fd, might be equal */ |
341 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
347 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
342 | volatile sig_atomic_t sent; |
|
|
343 | } s_epipe; |
348 | } s_epipe; |
344 | |
349 | |
345 | static int |
350 | static int |
346 | s_epipe_new (s_epipe *epp) |
351 | s_epipe_new (s_epipe *epp) |
347 | { |
352 | { |
… | |
… | |
360 | return -1; |
365 | return -1; |
361 | |
366 | |
362 | if (s_fd_prepare (ep.fd [0]) |
367 | if (s_fd_prepare (ep.fd [0]) |
363 | || s_fd_prepare (ep.fd [1])) |
368 | || s_fd_prepare (ep.fd [1])) |
364 | { |
369 | { |
|
|
370 | dTHX; |
|
|
371 | |
365 | close (ep.fd [0]); |
372 | close (ep.fd [0]); |
366 | close (ep.fd [1]); |
373 | close (ep.fd [1]); |
367 | return -1; |
374 | return -1; |
368 | } |
375 | } |
369 | |
376 | |
370 | ep.len = 1; |
377 | ep.len = 1; |
371 | } |
378 | } |
372 | |
379 | |
373 | ep.sent = 0; |
|
|
374 | *epp = ep; |
380 | *epp = ep; |
375 | return 0; |
381 | return 0; |
376 | } |
382 | } |
377 | |
383 | |
378 | static void |
384 | static void |
379 | s_epipe_destroy (s_epipe *epp) |
385 | s_epipe_destroy (s_epipe *epp) |
380 | { |
386 | { |
|
|
387 | dTHX; |
|
|
388 | |
381 | close (epp->fd [0]); |
389 | close (epp->fd [0]); |
382 | |
390 | |
383 | if (epp->fd [1] != epp->fd [0]) |
391 | if (epp->fd [1] != epp->fd [0]) |
384 | close (epp->fd [1]); |
392 | close (epp->fd [1]); |
385 | |
393 | |
… | |
… | |
387 | } |
395 | } |
388 | |
396 | |
389 | static void |
397 | static void |
390 | s_epipe_signal (s_epipe *epp) |
398 | s_epipe_signal (s_epipe *epp) |
391 | { |
399 | { |
392 | if (epp->sent) |
|
|
393 | return; |
|
|
394 | |
|
|
395 | epp->sent = 1; |
|
|
396 | { |
|
|
397 | #ifdef _WIN32 |
400 | #ifdef _WIN32 |
398 | /* perl overrides send with a function that crashes in other threads. |
401 | /* perl overrides send with a function that crashes in other threads. |
399 | * unfortunately, it overrides it with an argument-less macro, so |
402 | * unfortunately, it overrides it with an argument-less macro, so |
400 | * there is no way to force usage of the real send function. |
403 | * there is no way to force usage of the real send function. |
401 | * incompetent windows programmers - is this redundant? |
404 | * incompetent windows programmers - is this redundant? |
402 | */ |
405 | */ |
403 | DWORD dummy; |
406 | DWORD dummy; |
404 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
407 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
405 | #else |
408 | #else |
406 | static uint64_t counter = 1; |
409 | static uint64_t counter = 1; |
407 | /* some modules accept fd's from outside, support eventfd here */ |
410 | /* some modules accept fd's from outside, support eventfd here */ |
408 | if (write (epp->fd [1], &counter, epp->len) < 0 |
411 | if (write (epp->fd [1], &counter, epp->len) < 0 |
409 | && errno == EINVAL |
412 | && errno == EINVAL |
410 | && epp->len != 8) |
413 | && epp->len != 8) |
411 | write (epp->fd [1], &counter, (epp->len = 8)); |
414 | write (epp->fd [1], &counter, (epp->len = 8)); |
412 | #endif |
415 | #endif |
413 | } |
|
|
414 | } |
416 | } |
415 | |
417 | |
416 | static void |
418 | static void |
417 | s_epipe_drain (s_epipe *epp) |
419 | s_epipe_drain (s_epipe *epp) |
418 | { |
420 | { |
|
|
421 | dTHX; |
419 | char buf [9]; |
422 | char buf [9]; |
420 | |
423 | |
421 | #ifdef _WIN32 |
424 | #ifdef _WIN32 |
422 | recv (epp->fd [0], buf, sizeof (buf), 0); |
425 | recv (epp->fd [0], buf, sizeof (buf), 0); |
423 | #else |
426 | #else |
424 | read (epp->fd [0], buf, sizeof (buf)); |
427 | read (epp->fd [0], buf, sizeof (buf)); |
425 | #endif |
428 | #endif |
426 | |
|
|
427 | epp->sent = 0; |
|
|
428 | } |
429 | } |
429 | |
430 | |
430 | /* like new, but dups over old */ |
431 | /* like new, but dups over old */ |
431 | static int |
432 | static int |
432 | s_epipe_renew (s_epipe *epp) |
433 | s_epipe_renew (s_epipe *epp) |
433 | { |
434 | { |
|
|
435 | dTHX; |
434 | s_epipe epn; |
436 | s_epipe epn; |
435 | |
437 | |
436 | if (epp->fd [1] != epp->fd [0]) |
438 | if (epp->fd [1] != epp->fd [0]) |
437 | close (epp->fd [1]); |
439 | close (epp->fd [1]); |
438 | |
440 | |
… | |
… | |
458 | #define s_epipe_fd(epp) ((epp)->fd [0]) |
460 | #define s_epipe_fd(epp) ((epp)->fd [0]) |
459 | |
461 | |
460 | static int |
462 | static int |
461 | s_epipe_wait (s_epipe *epp) |
463 | s_epipe_wait (s_epipe *epp) |
462 | { |
464 | { |
|
|
465 | dTHX; |
463 | #ifdef _WIN32 |
466 | #ifdef _WIN32 |
464 | fd_set rfd; |
467 | fd_set rfd; |
465 | int fd = s_epipe_fd (epp); |
468 | int fd = s_epipe_fd (epp); |
466 | |
469 | |
467 | FD_ZERO (&rfd); |
470 | FD_ZERO (&rfd); |
… | |
… | |
473 | struct pollfd pfd; |
476 | struct pollfd pfd; |
474 | |
477 | |
475 | pfd.fd = s_epipe_fd (epp); |
478 | pfd.fd = s_epipe_fd (epp); |
476 | pfd.events = POLLIN; |
479 | pfd.events = POLLIN; |
477 | |
480 | |
478 | return poll (&pfd, 1, 0); |
481 | return poll (&pfd, 1, -1); |
479 | #endif |
482 | #endif |
480 | } |
483 | } |
481 | |
484 | |
482 | #endif |
485 | #endif |
483 | |
486 | |