--- IO-AIO/AIO.xs 2009/07/14 00:13:36 1.151 +++ IO-AIO/AIO.xs 2009/07/15 01:39:15 1.154 @@ -162,7 +162,7 @@ static int next_pri = EIO_PRI_DEFAULT; static int max_outstanding; -static int respipe_osf [2], respipe [2] = { -1, -1 }; +static s_epipe respipe; static void req_destroy (aio_req req); static void req_cancel (aio_req req); @@ -170,15 +170,13 @@ static void want_poll (void) { /* write a dummy byte to the pipe so fh becomes ready */ - respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); + s_epipe_signal (&respipe); } static void done_poll (void) { /* read any signals sent by the worker threads */ - char buf [4]; - while (respipe_read (respipe [0], buf, 4) == 4) - ; + s_epipe_drain (&respipe); } /* must be called at most once */ @@ -443,54 +441,15 @@ eio_grp_cancel (grp); } -#ifdef USE_SOCKETS_AS_HANDLES -# define TO_SOCKET(x) (win32_get_osfhandle (x)) -#else -# define TO_SOCKET(x) (x) -#endif - static void create_respipe (void) { - int old_readfd = respipe [0]; - - if (respipe [1] >= 0) - respipe_close (TO_SOCKET (respipe [1])); - -#ifdef _WIN32 - if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) -#else - if (pipe (respipe)) -#endif + if (s_epipe_renew (&respipe)) croak ("unable to initialize result pipe"); - - if (old_readfd >= 0) - { - if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) - croak ("unable to initialize result pipe(2)"); - - respipe_close (respipe [0]); - respipe [0] = old_readfd; - } - -#ifdef _WIN32 - int arg = 1; - if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) - || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) -#else - if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) - || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) -#endif - croak ("unable to initialize result pipe(3)"); - - respipe_osf [0] = TO_SOCKET (respipe [0]); - respipe_osf [1] = TO_SOCKET (respipe [1]); } static void poll_wait (void) { - fd_set rfd; - while (eio_nreqs ()) { int size; @@ -504,10 +463,7 @@ etp_maybe_start_thread (); - FD_ZERO (&rfd); - FD_SET (respipe [0], &rfd); - - PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); + s_epipe_wait (&respipe); } } @@ -535,19 +491,8 @@ static SV * get_cb (SV *cb_sv) { - HV *st; - GV *gvp; - CV *cv; - - if (!SvOK (cb_sv)) - return 0; - - cv = sv_2cv (cb_sv, &st, &gvp, 0); - - if (!cv) - croak ("IO::AIO callback must be undef or a CODE reference"); - - return (SV *)cv; + SvGETMAGIC (cb_sv); + return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; } #define dREQ \ @@ -1132,7 +1077,7 @@ poll_fileno() PROTOTYPE: CODE: - RETVAL = respipe [0]; + RETVAL = s_epipe_fd (&respipe); OUTPUT: RETVAL @@ -1223,7 +1168,7 @@ if (items > 1) { - SV *cb_cv = get_cb (callback); + SV *cb_cv =get_cb (callback); SvREFCNT_dec (req->callback); req->callback = SvREFCNT_inc (cb_cv);