… | |
… | |
6 | */ |
6 | */ |
7 | |
7 | |
8 | #include <signal.h> |
8 | #include <signal.h> |
9 | #include <errno.h> |
9 | #include <errno.h> |
10 | |
10 | |
11 | #ifndef _WIN32 |
11 | #if defined(WIN32 ) || defined(_MINIX) |
|
|
12 | # define SCHMORP_H_PREFER_SELECT 1 |
|
|
13 | #endif |
|
|
14 | |
|
|
15 | #if !SCHMORP_H_PREFER_SELECT |
12 | # include <poll.h> |
16 | # include <poll.h> |
13 | #endif |
17 | #endif |
14 | |
18 | |
15 | /* useful stuff, used by schmorp mostly */ |
19 | /* useful stuff, used by schmorp mostly */ |
16 | |
20 | |
… | |
… | |
19 | #define PERL_VERSION_ATLEAST(a,b,c) \ |
23 | #define PERL_VERSION_ATLEAST(a,b,c) \ |
20 | (PERL_REVISION > (a) \ |
24 | (PERL_REVISION > (a) \ |
21 | || (PERL_REVISION == (a) \ |
25 | || (PERL_REVISION == (a) \ |
22 | && (PERL_VERSION > (b) \ |
26 | && (PERL_VERSION > (b) \ |
23 | || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) |
27 | || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) |
|
|
28 | |
|
|
29 | #ifndef PERL_MAGIC_ext |
|
|
30 | # define PERL_MAGIC_ext '~' |
|
|
31 | #endif |
24 | |
32 | |
25 | #if !PERL_VERSION_ATLEAST (5,6,0) |
33 | #if !PERL_VERSION_ATLEAST (5,6,0) |
26 | # ifndef PL_ppaddr |
34 | # ifndef PL_ppaddr |
27 | # define PL_ppaddr ppaddr |
35 | # define PL_ppaddr ppaddr |
28 | # endif |
36 | # endif |
… | |
… | |
323 | } |
331 | } |
324 | |
332 | |
325 | #endif |
333 | #endif |
326 | |
334 | |
327 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
335 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
|
|
336 | # define SCHMORP_H_HAVE_EVENTFD 1 |
328 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
337 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
329 | # include <stdint.h> |
338 | # include <stdint.h> |
330 | # ifdef __cplusplus |
339 | # ifdef __cplusplus |
331 | extern "C" { |
340 | extern "C" { |
332 | # endif |
341 | # endif |
… | |
… | |
400 | * incompetent windows programmers - is this redundant? |
409 | * incompetent windows programmers - is this redundant? |
401 | */ |
410 | */ |
402 | DWORD dummy; |
411 | DWORD dummy; |
403 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
412 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
404 | #else |
413 | #else |
|
|
414 | # if SCHMORP_H_HAVE_EVENTFD |
405 | static uint64_t counter = 1; |
415 | static uint64_t counter = 1; |
|
|
416 | # else |
|
|
417 | static char counter [8]; |
|
|
418 | # endif |
406 | /* some modules accept fd's from outside, support eventfd here */ |
419 | /* some modules accept fd's from outside, support eventfd here */ |
407 | if (write (epp->fd [1], &counter, epp->len) < 0 |
420 | if (write (epp->fd [1], &counter, epp->len) < 0 |
408 | && errno == EINVAL |
421 | && errno == EINVAL |
409 | && epp->len != 8) |
422 | && epp->len != 8) |
410 | write (epp->fd [1], &counter, (epp->len = 8)); |
423 | write (epp->fd [1], &counter, (epp->len = 8)); |
… | |
… | |
440 | if (epp->len) |
453 | if (epp->len) |
441 | { |
454 | { |
442 | if (dup2 (epn.fd [0], epp->fd [0]) < 0) |
455 | if (dup2 (epn.fd [0], epp->fd [0]) < 0) |
443 | croak ("unable to dup over old event pipe"); /* should not croak */ |
456 | croak ("unable to dup over old event pipe"); /* should not croak */ |
444 | |
457 | |
445 | if (epp->fd [1] != epp->fd [0]) |
|
|
446 | close (epn.fd [0]); |
458 | close (epn.fd [0]); |
|
|
459 | |
|
|
460 | if (epn.fd [0] == epn.fd [1]) |
|
|
461 | epn.fd [1] = epp->fd [0]; |
447 | |
462 | |
448 | epn.fd [0] = epp->fd [0]; |
463 | epn.fd [0] = epp->fd [0]; |
449 | } |
464 | } |
450 | |
465 | |
451 | *epp = epn; |
466 | *epp = epn; |
… | |
… | |
457 | |
472 | |
458 | static int |
473 | static int |
459 | s_epipe_wait (s_epipe *epp) |
474 | s_epipe_wait (s_epipe *epp) |
460 | { |
475 | { |
461 | dTHX; |
476 | dTHX; |
462 | #ifdef _WIN32 |
477 | #if SCHMORP_H_PREFER_SELECT |
463 | fd_set rfd; |
478 | fd_set rfd; |
464 | int fd = s_epipe_fd (epp); |
479 | int fd = s_epipe_fd (epp); |
465 | |
480 | |
466 | FD_ZERO (&rfd); |
481 | FD_ZERO (&rfd); |
467 | FD_SET (fd, &rfd); |
482 | FD_SET (fd, &rfd); |
… | |
… | |
472 | struct pollfd pfd; |
487 | struct pollfd pfd; |
473 | |
488 | |
474 | pfd.fd = s_epipe_fd (epp); |
489 | pfd.fd = s_epipe_fd (epp); |
475 | pfd.events = POLLIN; |
490 | pfd.events = POLLIN; |
476 | |
491 | |
477 | return poll (&pfd, 1, 0); |
492 | return poll (&pfd, 1, -1); |
478 | #endif |
493 | #endif |
479 | } |
494 | } |
480 | |
495 | |
481 | #endif |
496 | #endif |
482 | |
497 | |