… | |
… | |
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 | |
… | |
… | |
327 | } |
331 | } |
328 | |
332 | |
329 | #endif |
333 | #endif |
330 | |
334 | |
331 | #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 |
332 | /* 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 */ |
333 | # include <stdint.h> |
338 | # include <stdint.h> |
334 | # ifdef __cplusplus |
339 | # ifdef __cplusplus |
335 | extern "C" { |
340 | extern "C" { |
336 | # endif |
341 | # endif |
… | |
… | |
404 | * incompetent windows programmers - is this redundant? |
409 | * incompetent windows programmers - is this redundant? |
405 | */ |
410 | */ |
406 | DWORD dummy; |
411 | DWORD dummy; |
407 | 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); |
408 | #else |
413 | #else |
|
|
414 | # if SCHMORP_H_HAVE_EVENTFD |
409 | static uint64_t counter = 1; |
415 | static uint64_t counter = 1; |
|
|
416 | # else |
|
|
417 | static char counter [8]; |
|
|
418 | # endif |
410 | /* some modules accept fd's from outside, support eventfd here */ |
419 | /* some modules accept fd's from outside, support eventfd here */ |
411 | if (write (epp->fd [1], &counter, epp->len) < 0 |
420 | if (write (epp->fd [1], &counter, epp->len) < 0 |
412 | && errno == EINVAL |
421 | && errno == EINVAL |
413 | && epp->len != 8) |
422 | && epp->len != 8) |
414 | write (epp->fd [1], &counter, (epp->len = 8)); |
423 | write (epp->fd [1], &counter, (epp->len = 8)); |
… | |
… | |
444 | if (epp->len) |
453 | if (epp->len) |
445 | { |
454 | { |
446 | if (dup2 (epn.fd [0], epp->fd [0]) < 0) |
455 | if (dup2 (epn.fd [0], epp->fd [0]) < 0) |
447 | croak ("unable to dup over old event pipe"); /* should not croak */ |
456 | croak ("unable to dup over old event pipe"); /* should not croak */ |
448 | |
457 | |
449 | if (epp->fd [1] != epp->fd [0]) |
|
|
450 | 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]; |
451 | |
462 | |
452 | epn.fd [0] = epp->fd [0]; |
463 | epn.fd [0] = epp->fd [0]; |
453 | } |
464 | } |
454 | |
465 | |
455 | *epp = epn; |
466 | *epp = epn; |
… | |
… | |
461 | |
472 | |
462 | static int |
473 | static int |
463 | s_epipe_wait (s_epipe *epp) |
474 | s_epipe_wait (s_epipe *epp) |
464 | { |
475 | { |
465 | dTHX; |
476 | dTHX; |
466 | #ifdef _WIN32 |
477 | #if SCHMORP_H_PREFER_SELECT |
467 | fd_set rfd; |
478 | fd_set rfd; |
468 | int fd = s_epipe_fd (epp); |
479 | int fd = s_epipe_fd (epp); |
469 | |
480 | |
470 | FD_ZERO (&rfd); |
481 | FD_ZERO (&rfd); |
471 | FD_SET (fd, &rfd); |
482 | FD_SET (fd, &rfd); |