--- cvsroot/EV/schmorp.h 2009/07/15 16:58:53 1.4 +++ cvsroot/EV/schmorp.h 2009/08/09 13:30:41 1.7 @@ -6,6 +6,7 @@ */ #include +#include #ifndef _WIN32 # include @@ -21,6 +22,10 @@ && (PERL_VERSION > (b) \ || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) +#ifndef PERL_MAGIC_ext +# define PERL_MAGIC_ext '~' +#endif + #if !PERL_VERSION_ATLEAST (5,6,0) # ifndef PL_ppaddr # define PL_ppaddr ppaddr @@ -210,6 +215,8 @@ static int s_pipe (int filedes [2]) { + dTHX; + struct sockaddr_in addr = { 0 }; int addr_size = sizeof (addr); struct sockaddr_in adr2; @@ -338,7 +345,6 @@ typedef struct { int fd[2]; /* read, write fd, might be equal */ int len; /* write length (1 pipe/socket, 8 eventfd) */ - volatile sig_atomic_t sent; } s_epipe; static int @@ -361,6 +367,8 @@ if (s_fd_prepare (ep.fd [0]) || s_fd_prepare (ep.fd [1])) { + dTHX; + close (ep.fd [0]); close (ep.fd [1]); return -1; @@ -369,7 +377,6 @@ ep.len = 1; } - ep.sent = 0; *epp = ep; return 0; } @@ -377,6 +384,8 @@ static void s_epipe_destroy (s_epipe *epp) { + dTHX; + close (epp->fd [0]); if (epp->fd [1] != epp->fd [0]) @@ -388,29 +397,28 @@ static void s_epipe_signal (s_epipe *epp) { - if (epp->sent) - return; - - epp->sent = 1; - { #ifdef _WIN32 - /* perl overrides send with a function that crashes in other threads. - * unfortunately, it overrides it with an argument-less macro, so - * there is no way to force usage of the real send function. - * incompetent windows programmers - is this redundant? - */ - DWORD dummy; - WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); + /* perl overrides send with a function that crashes in other threads. + * unfortunately, it overrides it with an argument-less macro, so + * there is no way to force usage of the real send function. + * incompetent windows programmers - is this redundant? + */ + DWORD dummy; + WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); #else - static uint64_t counter = 1; - write (epp->fd [1], &counter, epp->len); + static uint64_t counter = 1; + /* some modules accept fd's from outside, support eventfd here */ + if (write (epp->fd [1], &counter, epp->len) < 0 + && errno == EINVAL + && epp->len != 8) + write (epp->fd [1], &counter, (epp->len = 8)); #endif - } } static void s_epipe_drain (s_epipe *epp) { + dTHX; char buf [9]; #ifdef _WIN32 @@ -418,14 +426,13 @@ #else read (epp->fd [0], buf, sizeof (buf)); #endif - - epp->sent = 0; } /* like new, but dups over old */ static int s_epipe_renew (s_epipe *epp) { + dTHX; s_epipe epn; if (epp->fd [1] != epp->fd [0]) @@ -455,6 +462,7 @@ static int s_epipe_wait (s_epipe *epp) { + dTHX; #ifdef _WIN32 fd_set rfd; int fd = s_epipe_fd (epp); @@ -470,7 +478,7 @@ pfd.fd = s_epipe_fd (epp); pfd.events = POLLIN; - return poll (&pfd, 1, 0); + return poll (&pfd, 1, -1); #endif }