1 | #define PERL_NO_GET_CONTEXT |
|
|
2 | |
|
|
3 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
4 | #include "perl.h" |
2 | #include "perl.h" |
5 | #include "XSUB.h" |
3 | #include "XSUB.h" |
6 | |
4 | |
7 | #include <sys/types.h> |
5 | #include <sys/types.h> |
… | |
… | |
77 | |
75 | |
78 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
76 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
79 | } |
77 | } |
80 | |
78 | |
81 | static int |
79 | static int |
82 | poll_cb (pTHX) |
80 | poll_cb () |
83 | { |
81 | { |
84 | dSP; |
82 | dSP; |
85 | int count = 0; |
83 | int count = 0; |
86 | aio_req req; |
84 | aio_req req; |
87 | |
85 | |
… | |
… | |
150 | |
148 | |
151 | PUSHMARK (SP); |
149 | PUSHMARK (SP); |
152 | XPUSHs (fh); |
150 | XPUSHs (fh); |
153 | } |
151 | } |
154 | |
152 | |
|
|
153 | if (SvOK (req->callback)) |
|
|
154 | { |
155 | PUTBACK; |
155 | PUTBACK; |
156 | call_sv (req->callback, G_VOID | G_EVAL); |
156 | call_sv (req->callback, G_VOID | G_EVAL); |
157 | SPAGAIN; |
157 | SPAGAIN; |
|
|
158 | } |
158 | |
159 | |
159 | if (req->callback) |
160 | if (req->callback) |
160 | SvREFCNT_dec (req->callback); |
161 | SvREFCNT_dec (req->callback); |
161 | |
162 | |
162 | errno = errorno; |
163 | errno = errorno; |
… | |
… | |
227 | |
228 | |
228 | send_req (req); |
229 | send_req (req); |
229 | } |
230 | } |
230 | |
231 | |
231 | static void |
232 | static void |
232 | read_write (pTHX_ |
|
|
233 | int dowrite, int fd, off_t offset, size_t length, |
233 | read_write (int dowrite, int fd, off_t offset, size_t length, |
234 | SV *data, STRLEN dataoffset, SV *callback) |
234 | SV *data, STRLEN dataoffset, SV *callback) |
235 | { |
235 | { |
236 | aio_req req; |
236 | aio_req req; |
237 | STRLEN svlen; |
237 | STRLEN svlen; |
238 | char *svptr = SvPV (data, svlen); |
238 | char *svptr = SvPV (data, svlen); |
… | |
… | |
364 | return 0; |
364 | return 0; |
365 | } |
365 | } |
366 | |
366 | |
367 | MODULE = IO::AIO PACKAGE = IO::AIO |
367 | MODULE = IO::AIO PACKAGE = IO::AIO |
368 | |
368 | |
|
|
369 | PROTOTYPES: ENABLE |
|
|
370 | |
369 | BOOT: |
371 | BOOT: |
370 | { |
372 | { |
371 | if (pipe (respipe)) |
373 | if (pipe (respipe)) |
372 | croak ("unable to initialize result pipe"); |
374 | croak ("unable to initialize result pipe"); |
373 | |
375 | |
… | |
… | |
400 | } |
402 | } |
401 | |
403 | |
402 | while (started > nthreads) |
404 | while (started > nthreads) |
403 | { |
405 | { |
404 | poll_wait (); |
406 | poll_wait (); |
405 | poll_cb (aTHX); |
407 | poll_cb (); |
406 | } |
408 | } |
407 | } |
409 | } |
408 | |
410 | |
409 | int |
411 | int |
410 | max_outstanding(nreqs) |
412 | max_outstanding(nreqs) |
… | |
… | |
413 | CODE: |
415 | CODE: |
414 | RETVAL = max_outstanding; |
416 | RETVAL = max_outstanding; |
415 | max_outstanding = nreqs; |
417 | max_outstanding = nreqs; |
416 | |
418 | |
417 | void |
419 | void |
418 | aio_open(pathname,flags,mode,callback) |
420 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
419 | SV * pathname |
421 | SV * pathname |
420 | int flags |
422 | int flags |
421 | int mode |
423 | int mode |
422 | SV * callback |
424 | SV * callback |
423 | PROTOTYPE: $$$$ |
425 | PROTOTYPE: $$$;$ |
424 | CODE: |
426 | CODE: |
425 | { |
427 | { |
426 | aio_req req; |
428 | aio_req req; |
427 | |
429 | |
428 | Newz (0, req, 1, aio_cb); |
430 | Newz (0, req, 1, aio_cb); |
… | |
… | |
439 | |
441 | |
440 | send_req (req); |
442 | send_req (req); |
441 | } |
443 | } |
442 | |
444 | |
443 | void |
445 | void |
444 | aio_close(fh,callback) |
446 | aio_close(fh,callback=&PL_sv_undef) |
445 | InputStream fh |
447 | InputStream fh |
446 | SV * callback |
448 | SV * callback |
447 | PROTOTYPE: $$ |
449 | PROTOTYPE: $;$ |
448 | ALIAS: |
450 | ALIAS: |
449 | aio_close = REQ_CLOSE |
451 | aio_close = REQ_CLOSE |
450 | aio_fsync = REQ_FSYNC |
452 | aio_fsync = REQ_FSYNC |
451 | aio_fdatasync = REQ_FDATASYNC |
453 | aio_fdatasync = REQ_FDATASYNC |
452 | CODE: |
454 | CODE: |
… | |
… | |
464 | |
466 | |
465 | send_req (req); |
467 | send_req (req); |
466 | } |
468 | } |
467 | |
469 | |
468 | void |
470 | void |
469 | aio_read(fh,offset,length,data,dataoffset,callback) |
471 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
470 | InputStream fh |
472 | InputStream fh |
471 | UV offset |
473 | UV offset |
472 | IV length |
474 | IV length |
473 | SV * data |
475 | SV * data |
474 | IV dataoffset |
476 | IV dataoffset |
475 | SV * callback |
477 | SV * callback |
476 | PROTOTYPE: $$$$$$ |
478 | PROTOTYPE: $$$$$;$ |
477 | CODE: |
479 | CODE: |
478 | read_write (aTHX_ 0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
480 | read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
479 | |
481 | |
480 | void |
482 | void |
481 | aio_write(fh,offset,length,data,dataoffset,callback) |
483 | aio_write(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
482 | OutputStream fh |
484 | OutputStream fh |
483 | UV offset |
485 | UV offset |
484 | IV length |
486 | IV length |
485 | SV * data |
487 | SV * data |
486 | IV dataoffset |
488 | IV dataoffset |
487 | SV * callback |
489 | SV * callback |
488 | PROTOTYPE: $$$$$$ |
490 | PROTOTYPE: $$$$$;$ |
489 | CODE: |
491 | CODE: |
490 | read_write (aTHX_ 1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
492 | read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
491 | |
493 | |
492 | void |
494 | void |
493 | aio_readahead(fh,offset,length,callback) |
495 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
494 | InputStream fh |
496 | InputStream fh |
495 | UV offset |
497 | UV offset |
496 | IV length |
498 | IV length |
497 | SV * callback |
499 | SV * callback |
498 | PROTOTYPE: $$$$ |
500 | PROTOTYPE: $$$;$ |
499 | CODE: |
501 | CODE: |
500 | { |
502 | { |
501 | aio_req req; |
503 | aio_req req; |
502 | |
504 | |
503 | if (length < 0) |
505 | if (length < 0) |
… | |
… | |
516 | |
518 | |
517 | send_req (req); |
519 | send_req (req); |
518 | } |
520 | } |
519 | |
521 | |
520 | void |
522 | void |
521 | aio_stat(fh_or_path,callback) |
523 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
522 | SV * fh_or_path |
524 | SV * fh_or_path |
523 | SV * callback |
525 | SV * callback |
524 | PROTOTYPE: $$ |
|
|
525 | ALIAS: |
526 | ALIAS: |
|
|
527 | aio_stat = REQ_STAT |
526 | aio_lstat = 1 |
528 | aio_lstat = REQ_LSTAT |
527 | CODE: |
529 | CODE: |
528 | { |
530 | { |
529 | aio_req req; |
531 | aio_req req; |
530 | |
532 | |
531 | Newz (0, req, 1, aio_cb); |
533 | Newz (0, req, 1, aio_cb); |
… | |
… | |
538 | if (!req->statdata) |
540 | if (!req->statdata) |
539 | croak ("out of memory during aio_req->statdata allocation"); |
541 | croak ("out of memory during aio_req->statdata allocation"); |
540 | |
542 | |
541 | if (SvPOK (fh_or_path)) |
543 | if (SvPOK (fh_or_path)) |
542 | { |
544 | { |
543 | req->type = ix ? REQ_LSTAT : REQ_STAT; |
545 | req->type = ix; |
544 | req->data = newSVsv (fh_or_path); |
546 | req->data = newSVsv (fh_or_path); |
545 | req->dataptr = SvPV_nolen (req->data); |
547 | req->dataptr = SvPV_nolen (req->data); |
546 | } |
548 | } |
547 | else |
549 | else |
548 | { |
550 | { |
… | |
… | |
554 | |
556 | |
555 | send_req (req); |
557 | send_req (req); |
556 | } |
558 | } |
557 | |
559 | |
558 | void |
560 | void |
559 | aio_unlink(pathname,callback) |
561 | aio_unlink(pathname,callback=&PL_sv_undef) |
560 | SV * pathname |
562 | SV * pathname |
561 | SV * callback |
563 | SV * callback |
562 | PROTOTYPE: $$ |
|
|
563 | CODE: |
564 | CODE: |
564 | { |
565 | { |
565 | aio_req req; |
566 | aio_req req; |
566 | |
567 | |
567 | Newz (0, req, 1, aio_cb); |
568 | Newz (0, req, 1, aio_cb); |
… | |
… | |
575 | req->callback = SvREFCNT_inc (callback); |
576 | req->callback = SvREFCNT_inc (callback); |
576 | |
577 | |
577 | send_req (req); |
578 | send_req (req); |
578 | } |
579 | } |
579 | |
580 | |
|
|
581 | void |
|
|
582 | flush() |
|
|
583 | PROTOTYPE: |
|
|
584 | CODE: |
|
|
585 | while (nreqs) |
|
|
586 | { |
|
|
587 | poll_wait (); |
|
|
588 | poll_cb (); |
|
|
589 | } |
|
|
590 | |
|
|
591 | void |
|
|
592 | poll() |
|
|
593 | PROTOTYPE: |
|
|
594 | CODE: |
|
|
595 | if (nreqs) |
|
|
596 | { |
|
|
597 | poll_wait (); |
|
|
598 | poll_cb (); |
|
|
599 | } |
|
|
600 | |
580 | int |
601 | int |
581 | poll_fileno() |
602 | poll_fileno() |
582 | PROTOTYPE: |
603 | PROTOTYPE: |
583 | CODE: |
604 | CODE: |
584 | RETVAL = respipe [0]; |
605 | RETVAL = respipe [0]; |
… | |
… | |
587 | |
608 | |
588 | int |
609 | int |
589 | poll_cb(...) |
610 | poll_cb(...) |
590 | PROTOTYPE: |
611 | PROTOTYPE: |
591 | CODE: |
612 | CODE: |
592 | RETVAL = poll_cb (aTHX); |
613 | RETVAL = poll_cb (); |
593 | OUTPUT: |
614 | OUTPUT: |
594 | RETVAL |
615 | RETVAL |
595 | |
616 | |
596 | void |
617 | void |
597 | poll_wait() |
618 | poll_wait() |