--- IO-AIO/AIO.xs 2009/07/14 00:32:27 1.152 +++ IO-AIO/AIO.xs 2009/07/15 01:36:04 1.153 @@ -162,7 +162,8 @@ static int next_pri = EIO_PRI_DEFAULT; static int max_outstanding; -static int respipe_osf [2], respipe [2] = { -1, -1 }; +static int respipe_osf [2]; +static s_epipe respipe; static void req_destroy (aio_req req); static void req_cancel (aio_req req); @@ -170,15 +171,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 +442,18 @@ 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]); + respipe_osf [0] = S_TO_SOCKET (respipe.fd [0]); + respipe_osf [1] = S_TO_SOCKET (respipe.fd [1]); } static void poll_wait (void) { - fd_set rfd; - while (eio_nreqs ()) { int size; @@ -504,10 +467,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); } } @@ -1121,7 +1081,7 @@ poll_fileno() PROTOTYPE: CODE: - RETVAL = respipe [0]; + RETVAL = s_epipe_fd (&respipe); OUTPUT: RETVAL