… | |
… | |
160 | |
160 | |
161 | static SV *on_next_submit; |
161 | static SV *on_next_submit; |
162 | static int next_pri = EIO_PRI_DEFAULT; |
162 | static int next_pri = EIO_PRI_DEFAULT; |
163 | static int max_outstanding; |
163 | static int max_outstanding; |
164 | |
164 | |
165 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
165 | static int respipe_osf [2]; |
|
|
166 | static s_epipe respipe; |
166 | |
167 | |
167 | static void req_destroy (aio_req req); |
168 | static void req_destroy (aio_req req); |
168 | static void req_cancel (aio_req req); |
169 | static void req_cancel (aio_req req); |
169 | |
170 | |
170 | static void want_poll (void) |
171 | static void want_poll (void) |
171 | { |
172 | { |
172 | /* write a dummy byte to the pipe so fh becomes ready */ |
173 | /* write a dummy byte to the pipe so fh becomes ready */ |
173 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
174 | s_epipe_signal (&respipe); |
174 | } |
175 | } |
175 | |
176 | |
176 | static void done_poll (void) |
177 | static void done_poll (void) |
177 | { |
178 | { |
178 | /* read any signals sent by the worker threads */ |
179 | /* read any signals sent by the worker threads */ |
179 | char buf [4]; |
180 | s_epipe_drain (&respipe); |
180 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
181 | ; |
|
|
182 | } |
181 | } |
183 | |
182 | |
184 | /* must be called at most once */ |
183 | /* must be called at most once */ |
185 | static SV *req_sv (aio_req req, const char *klass) |
184 | static SV *req_sv (aio_req req, const char *klass) |
186 | { |
185 | { |
… | |
… | |
441 | grp->sv2 = 0; |
440 | grp->sv2 = 0; |
442 | |
441 | |
443 | eio_grp_cancel (grp); |
442 | eio_grp_cancel (grp); |
444 | } |
443 | } |
445 | |
444 | |
446 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
447 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
448 | #else |
|
|
449 | # define TO_SOCKET(x) (x) |
|
|
450 | #endif |
|
|
451 | |
|
|
452 | static void |
445 | static void |
453 | create_respipe (void) |
446 | create_respipe (void) |
454 | { |
447 | { |
455 | int old_readfd = respipe [0]; |
|
|
456 | |
|
|
457 | if (respipe [1] >= 0) |
|
|
458 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
459 | |
|
|
460 | #ifdef _WIN32 |
|
|
461 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
462 | #else |
|
|
463 | if (pipe (respipe)) |
448 | if (s_epipe_renew (&respipe)) |
464 | #endif |
|
|
465 | croak ("unable to initialize result pipe"); |
449 | croak ("unable to initialize result pipe"); |
466 | |
450 | |
467 | if (old_readfd >= 0) |
|
|
468 | { |
|
|
469 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
470 | croak ("unable to initialize result pipe(2)"); |
|
|
471 | |
|
|
472 | respipe_close (respipe [0]); |
|
|
473 | respipe [0] = old_readfd; |
|
|
474 | } |
|
|
475 | |
|
|
476 | #ifdef _WIN32 |
|
|
477 | int arg = 1; |
|
|
478 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
479 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
480 | #else |
|
|
481 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
482 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
483 | #endif |
|
|
484 | croak ("unable to initialize result pipe(3)"); |
|
|
485 | |
|
|
486 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
451 | respipe_osf [0] = S_TO_SOCKET (respipe.fd [0]); |
487 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
452 | respipe_osf [1] = S_TO_SOCKET (respipe.fd [1]); |
488 | } |
453 | } |
489 | |
454 | |
490 | static void poll_wait (void) |
455 | static void poll_wait (void) |
491 | { |
456 | { |
492 | fd_set rfd; |
|
|
493 | |
|
|
494 | while (eio_nreqs ()) |
457 | while (eio_nreqs ()) |
495 | { |
458 | { |
496 | int size; |
459 | int size; |
497 | |
460 | |
498 | X_LOCK (reslock); |
461 | X_LOCK (reslock); |
… | |
… | |
502 | if (size) |
465 | if (size) |
503 | return; |
466 | return; |
504 | |
467 | |
505 | etp_maybe_start_thread (); |
468 | etp_maybe_start_thread (); |
506 | |
469 | |
507 | FD_ZERO (&rfd); |
470 | s_epipe_wait (&respipe); |
508 | FD_SET (respipe [0], &rfd); |
|
|
509 | |
|
|
510 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
511 | } |
471 | } |
512 | } |
472 | } |
513 | |
473 | |
514 | static int poll_cb (void) |
474 | static int poll_cb (void) |
515 | { |
475 | { |
… | |
… | |
1119 | |
1079 | |
1120 | int |
1080 | int |
1121 | poll_fileno() |
1081 | poll_fileno() |
1122 | PROTOTYPE: |
1082 | PROTOTYPE: |
1123 | CODE: |
1083 | CODE: |
1124 | RETVAL = respipe [0]; |
1084 | RETVAL = s_epipe_fd (&respipe); |
1125 | OUTPUT: |
1085 | OUTPUT: |
1126 | RETVAL |
1086 | RETVAL |
1127 | |
1087 | |
1128 | int |
1088 | int |
1129 | poll_cb(...) |
1089 | poll_cb(...) |