… | |
… | |
337 | #endif |
337 | #endif |
338 | |
338 | |
339 | typedef struct { |
339 | typedef struct { |
340 | int fd[2]; /* read, write fd, might be equal */ |
340 | int fd[2]; /* read, write fd, might be equal */ |
341 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
341 | int len; /* write length (1 pipe/socket, 8 eventfd) */ |
342 | volatile sig_atomic_t sent; |
|
|
343 | } s_epipe; |
342 | } s_epipe; |
344 | |
343 | |
345 | static int |
344 | static int |
346 | s_epipe_new (s_epipe *epp) |
345 | s_epipe_new (s_epipe *epp) |
347 | { |
346 | { |
… | |
… | |
368 | } |
367 | } |
369 | |
368 | |
370 | ep.len = 1; |
369 | ep.len = 1; |
371 | } |
370 | } |
372 | |
371 | |
373 | ep.sent = 0; |
|
|
374 | *epp = ep; |
372 | *epp = ep; |
375 | return 0; |
373 | return 0; |
376 | } |
374 | } |
377 | |
375 | |
378 | static void |
376 | static void |
… | |
… | |
387 | } |
385 | } |
388 | |
386 | |
389 | static void |
387 | static void |
390 | s_epipe_signal (s_epipe *epp) |
388 | s_epipe_signal (s_epipe *epp) |
391 | { |
389 | { |
392 | if (epp->sent) |
|
|
393 | return; |
|
|
394 | |
|
|
395 | epp->sent = 1; |
|
|
396 | { |
|
|
397 | #ifdef _WIN32 |
390 | #ifdef _WIN32 |
398 | /* perl overrides send with a function that crashes in other threads. |
391 | /* perl overrides send with a function that crashes in other threads. |
399 | * unfortunately, it overrides it with an argument-less macro, so |
392 | * unfortunately, it overrides it with an argument-less macro, so |
400 | * there is no way to force usage of the real send function. |
393 | * there is no way to force usage of the real send function. |
401 | * incompetent windows programmers - is this redundant? |
394 | * incompetent windows programmers - is this redundant? |
402 | */ |
395 | */ |
403 | DWORD dummy; |
396 | DWORD dummy; |
404 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
397 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
405 | #else |
398 | #else |
406 | static uint64_t counter = 1; |
399 | static uint64_t counter = 1; |
407 | /* some modules accept fd's from outside, support eventfd here */ |
400 | /* some modules accept fd's from outside, support eventfd here */ |
408 | if (write (epp->fd [1], &counter, epp->len) < 0 |
401 | if (write (epp->fd [1], &counter, epp->len) < 0 |
409 | && errno == EINVAL |
402 | && errno == EINVAL |
410 | && epp->len != 8) |
403 | && epp->len != 8) |
411 | write (epp->fd [1], &counter, (epp->len = 8)); |
404 | write (epp->fd [1], &counter, (epp->len = 8)); |
412 | #endif |
405 | #endif |
413 | } |
|
|
414 | } |
406 | } |
415 | |
407 | |
416 | static void |
408 | static void |
417 | s_epipe_drain (s_epipe *epp) |
409 | s_epipe_drain (s_epipe *epp) |
418 | { |
410 | { |
419 | char buf [9]; |
411 | char buf [9]; |
420 | |
412 | |
|
|
413 | fprintf (stderr, "drain\n");//D |
421 | #ifdef _WIN32 |
414 | #ifdef _WIN32 |
422 | recv (epp->fd [0], buf, sizeof (buf), 0); |
415 | recv (epp->fd [0], buf, sizeof (buf), 0); |
423 | #else |
416 | #else |
424 | read (epp->fd [0], buf, sizeof (buf)); |
417 | read (epp->fd [0], buf, sizeof (buf)); |
425 | #endif |
418 | #endif |
426 | |
|
|
427 | epp->sent = 0; |
|
|
428 | } |
419 | } |
429 | |
420 | |
430 | /* like new, but dups over old */ |
421 | /* like new, but dups over old */ |
431 | static int |
422 | static int |
432 | s_epipe_renew (s_epipe *epp) |
423 | s_epipe_renew (s_epipe *epp) |