… | |
… | |
357 | || fcntl (fd, F_SETFD, FD_CLOEXEC); |
357 | || fcntl (fd, F_SETFD, FD_CLOEXEC); |
358 | } |
358 | } |
359 | |
359 | |
360 | #endif |
360 | #endif |
361 | |
361 | |
|
|
362 | #if HAVE_EVENTFD |
|
|
363 | # include <sys/eventfd.h> |
|
|
364 | #else |
362 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
365 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
363 | # define SCHMORP_H_HAVE_EVENTFD 1 |
366 | # define SCHMORP_H_HAVE_EVENTFD 1 |
364 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
367 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
365 | # include <stdint.h> |
368 | # include <stdint.h> |
366 | # ifdef __cplusplus |
369 | # ifdef __cplusplus |
367 | extern "C" { |
370 | extern "C" { |
368 | # endif |
371 | # endif |
369 | int eventfd (unsigned int initval, int flags); |
372 | int eventfd (unsigned int initval, int flags); |
370 | # ifdef __cplusplus |
373 | # ifdef __cplusplus |
371 | } |
374 | } |
372 | # endif |
375 | # endif |
373 | #else |
376 | # else |
374 | # define eventfd(initval,flags) -1 |
377 | # define eventfd(initval,flags) -1 |
|
|
378 | # endif |
375 | #endif |
379 | #endif |
376 | |
380 | |
377 | typedef struct { |
381 | typedef struct { |
378 | int fd[2]; /* read, write fd, might be equal */ |
382 | int fd[2]; /* read, write fd, might be equal */ |
379 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
383 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
… | |
… | |
436 | * incompetent windows programmers - is this redundant? |
440 | * incompetent windows programmers - is this redundant? |
437 | */ |
441 | */ |
438 | DWORD dummy; |
442 | DWORD dummy; |
439 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
443 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
440 | #else |
444 | #else |
441 | # if SCHMORP_H_HAVE_EVENTFD |
|
|
442 | static uint64_t counter = 1; |
445 | static uint64_t counter = 1; |
443 | # else |
|
|
444 | static char counter [8]; |
|
|
445 | # endif |
|
|
446 | /* some modules accept fd's from outside, support eventfd here */ |
446 | /* some modules accept fd's from outside, support eventfd here */ |
447 | if (write (epp->fd [1], &counter, epp->len) < 0 |
447 | if (write (epp->fd [1], &counter, epp->len) < 0 |
448 | && errno == EINVAL |
448 | && errno == EINVAL |
449 | && epp->len != 8) |
449 | && epp->len != 8) |
450 | write (epp->fd [1], &counter, (epp->len = 8)); |
450 | write (epp->fd [1], &counter, (epp->len = 8)); |