… | |
… | |
214 | dSP; |
214 | dSP; |
215 | |
215 | |
216 | if (req->flags & FLAG_SV2_RO_OFF) |
216 | if (req->flags & FLAG_SV2_RO_OFF) |
217 | SvREADONLY_off (req->sv2); |
217 | SvREADONLY_off (req->sv2); |
218 | |
218 | |
219 | if (!EIO_CANCELLED (req) && SvOK (req->callback)) |
219 | if (!EIO_CANCELLED (req) && req->callback) |
220 | { |
220 | { |
221 | ENTER; |
221 | ENTER; |
222 | SAVETMPS; |
222 | SAVETMPS; |
223 | PUSHMARK (SP); |
223 | PUSHMARK (SP); |
224 | EXTEND (SP, 1); |
224 | EXTEND (SP, 1); |
… | |
… | |
461 | static void atfork_child (void) |
461 | static void atfork_child (void) |
462 | { |
462 | { |
463 | create_respipe (); |
463 | create_respipe (); |
464 | } |
464 | } |
465 | |
465 | |
|
|
466 | static SV * |
|
|
467 | get_cb (SV *cb_sv) |
|
|
468 | { |
|
|
469 | HV *st; |
|
|
470 | GV *gvp; |
|
|
471 | CV *cv; |
|
|
472 | |
|
|
473 | if (!SvOK (cb_sv)) |
|
|
474 | return 0; |
|
|
475 | |
|
|
476 | cv = sv_2cv (cb_sv, &st, &gvp, 0); |
|
|
477 | |
|
|
478 | if (!cv) |
|
|
479 | croak ("IO::AIO watcher callback must be undef or a CODE reference"); |
|
|
480 | |
|
|
481 | return (SV *)cv; |
|
|
482 | } |
|
|
483 | |
466 | #define dREQ \ |
484 | #define dREQ \ |
|
|
485 | SV *cb_cv; \ |
467 | aio_req req; \ |
486 | aio_req req; \ |
468 | int req_pri = next_pri; \ |
487 | int req_pri = next_pri; \ |
469 | next_pri = EIO_PRI_DEFAULT; \ |
488 | next_pri = EIO_PRI_DEFAULT; \ |
470 | \ |
489 | \ |
471 | if (SvOK (callback) && !SvROK (callback)) \ |
490 | cb_cv = get_cb (callback); \ |
472 | croak ("callback must be undef or of reference type"); \ |
|
|
473 | \ |
491 | \ |
474 | Newz (0, req, 1, eio_req); \ |
492 | Newz (0, req, 1, eio_req); \ |
475 | if (!req) \ |
493 | if (!req) \ |
476 | croak ("out of memory during eio_req allocation"); \ |
494 | croak ("out of memory during eio_req allocation"); \ |
477 | \ |
495 | \ |
478 | req->callback = newSVsv (callback); \ |
496 | req->callback = SvREFCNT_inc (cb_cv); \ |
479 | req->pri = req_pri |
497 | req->pri = req_pri |
480 | |
498 | |
481 | #define REQ_SEND \ |
499 | #define REQ_SEND \ |
482 | PUTBACK; \ |
500 | PUTBACK; \ |
483 | req_submit (req); \ |
501 | req_submit (req); \ |
… | |
… | |
1038 | CODE: |
1056 | CODE: |
1039 | eio_cancel (req); |
1057 | eio_cancel (req); |
1040 | |
1058 | |
1041 | void |
1059 | void |
1042 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1060 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1043 | CODE: |
1061 | PPCODE: |
|
|
1062 | { |
|
|
1063 | if (GIMME_V != G_VOID) |
|
|
1064 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
|
|
1065 | |
|
|
1066 | if (items > 1) |
|
|
1067 | { |
|
|
1068 | SV *cb_cv = get_cb (callback); |
|
|
1069 | |
1044 | SvREFCNT_dec (req->callback); |
1070 | SvREFCNT_dec (req->callback); |
1045 | req->callback = newSVsv (callback); |
1071 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
1072 | } |
|
|
1073 | } |
1046 | |
1074 | |
1047 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1075 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1048 | |
1076 | |
1049 | void |
1077 | void |
1050 | add (aio_req grp, ...) |
1078 | add (aio_req grp, ...) |