… | |
… | |
6 | #include <sys/stat.h> |
6 | #include <sys/stat.h> |
7 | #include <unistd.h> |
7 | #include <unistd.h> |
8 | #include <fcntl.h> |
8 | #include <fcntl.h> |
9 | #include <signal.h> |
9 | #include <signal.h> |
10 | #include <sched.h> |
10 | #include <sched.h> |
11 | #include <endian.h> |
|
|
12 | |
11 | |
13 | #include <pthread.h> |
12 | #include <pthread.h> |
14 | #include <sys/syscall.h> |
13 | #include <sys/syscall.h> |
15 | |
14 | |
16 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
15 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
… | |
… | |
148 | |
147 | |
149 | PUSHMARK (SP); |
148 | PUSHMARK (SP); |
150 | XPUSHs (fh); |
149 | XPUSHs (fh); |
151 | } |
150 | } |
152 | |
151 | |
|
|
152 | if (SvOK (req->callback)) |
|
|
153 | { |
153 | PUTBACK; |
154 | PUTBACK; |
154 | call_sv (req->callback, G_VOID | G_EVAL); |
155 | call_sv (req->callback, G_VOID | G_EVAL); |
155 | SPAGAIN; |
156 | SPAGAIN; |
|
|
157 | } |
156 | |
158 | |
157 | if (req->callback) |
159 | if (req->callback) |
158 | SvREFCNT_dec (req->callback); |
160 | SvREFCNT_dec (req->callback); |
159 | |
161 | |
160 | errno = errorno; |
162 | errno = errorno; |
… | |
… | |
361 | return 0; |
363 | return 0; |
362 | } |
364 | } |
363 | |
365 | |
364 | MODULE = IO::AIO PACKAGE = IO::AIO |
366 | MODULE = IO::AIO PACKAGE = IO::AIO |
365 | |
367 | |
|
|
368 | PROTOTYPES: ENABLE |
|
|
369 | |
366 | BOOT: |
370 | BOOT: |
367 | { |
371 | { |
368 | if (pipe (respipe)) |
372 | if (pipe (respipe)) |
369 | croak ("unable to initialize result pipe"); |
373 | croak ("unable to initialize result pipe"); |
370 | |
374 | |
… | |
… | |
410 | CODE: |
414 | CODE: |
411 | RETVAL = max_outstanding; |
415 | RETVAL = max_outstanding; |
412 | max_outstanding = nreqs; |
416 | max_outstanding = nreqs; |
413 | |
417 | |
414 | void |
418 | void |
415 | aio_open(pathname,flags,mode,callback) |
419 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
416 | SV * pathname |
420 | SV * pathname |
417 | int flags |
421 | int flags |
418 | int mode |
422 | int mode |
419 | SV * callback |
423 | SV * callback |
420 | PROTOTYPE: $$$$ |
424 | PROTOTYPE: $$$;$ |
421 | CODE: |
425 | CODE: |
422 | { |
426 | { |
423 | aio_req req; |
427 | aio_req req; |
424 | |
428 | |
425 | Newz (0, req, 1, aio_cb); |
429 | Newz (0, req, 1, aio_cb); |
… | |
… | |
436 | |
440 | |
437 | send_req (req); |
441 | send_req (req); |
438 | } |
442 | } |
439 | |
443 | |
440 | void |
444 | void |
441 | aio_close(fh,callback) |
445 | aio_close(fh,callback=&PL_sv_undef) |
442 | InputStream fh |
446 | InputStream fh |
443 | SV * callback |
447 | SV * callback |
444 | PROTOTYPE: $$ |
448 | PROTOTYPE: $;$ |
445 | ALIAS: |
449 | ALIAS: |
446 | aio_close = REQ_CLOSE |
450 | aio_close = REQ_CLOSE |
447 | aio_fsync = REQ_FSYNC |
451 | aio_fsync = REQ_FSYNC |
448 | aio_fdatasync = REQ_FDATASYNC |
452 | aio_fdatasync = REQ_FDATASYNC |
449 | CODE: |
453 | CODE: |
… | |
… | |
461 | |
465 | |
462 | send_req (req); |
466 | send_req (req); |
463 | } |
467 | } |
464 | |
468 | |
465 | void |
469 | void |
466 | aio_read(fh,offset,length,data,dataoffset,callback) |
470 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
467 | InputStream fh |
471 | InputStream fh |
468 | UV offset |
472 | UV offset |
469 | IV length |
473 | IV length |
470 | SV * data |
474 | SV * data |
471 | IV dataoffset |
475 | IV dataoffset |
472 | SV * callback |
476 | SV * callback |
473 | PROTOTYPE: $$$$$$ |
477 | PROTOTYPE: $$$$$;$ |
474 | CODE: |
478 | CODE: |
475 | read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
479 | read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
476 | |
480 | |
477 | void |
481 | void |
478 | aio_write(fh,offset,length,data,dataoffset,callback) |
482 | aio_write(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
479 | OutputStream fh |
483 | OutputStream fh |
480 | UV offset |
484 | UV offset |
481 | IV length |
485 | IV length |
482 | SV * data |
486 | SV * data |
483 | IV dataoffset |
487 | IV dataoffset |
484 | SV * callback |
488 | SV * callback |
485 | PROTOTYPE: $$$$$$ |
489 | PROTOTYPE: $$$$$;$ |
486 | CODE: |
490 | CODE: |
487 | read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
491 | read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
488 | |
492 | |
489 | void |
493 | void |
490 | aio_readahead(fh,offset,length,callback) |
494 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
491 | InputStream fh |
495 | InputStream fh |
492 | UV offset |
496 | UV offset |
493 | IV length |
497 | IV length |
494 | SV * callback |
498 | SV * callback |
495 | PROTOTYPE: $$$$ |
499 | PROTOTYPE: $$$;$ |
496 | CODE: |
500 | CODE: |
497 | { |
501 | { |
498 | aio_req req; |
502 | aio_req req; |
499 | |
503 | |
500 | if (length < 0) |
504 | if (length < 0) |
… | |
… | |
513 | |
517 | |
514 | send_req (req); |
518 | send_req (req); |
515 | } |
519 | } |
516 | |
520 | |
517 | void |
521 | void |
518 | aio_stat(fh_or_path,callback) |
522 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
519 | SV * fh_or_path |
523 | SV * fh_or_path |
520 | SV * callback |
524 | SV * callback |
521 | PROTOTYPE: $$ |
|
|
522 | ALIAS: |
525 | ALIAS: |
|
|
526 | aio_stat = REQ_STAT |
523 | aio_lstat = 1 |
527 | aio_lstat = REQ_LSTAT |
524 | CODE: |
528 | CODE: |
525 | { |
529 | { |
526 | aio_req req; |
530 | aio_req req; |
527 | |
531 | |
528 | Newz (0, req, 1, aio_cb); |
532 | Newz (0, req, 1, aio_cb); |
… | |
… | |
535 | if (!req->statdata) |
539 | if (!req->statdata) |
536 | croak ("out of memory during aio_req->statdata allocation"); |
540 | croak ("out of memory during aio_req->statdata allocation"); |
537 | |
541 | |
538 | if (SvPOK (fh_or_path)) |
542 | if (SvPOK (fh_or_path)) |
539 | { |
543 | { |
540 | req->type = ix ? REQ_LSTAT : REQ_STAT; |
544 | req->type = ix; |
541 | req->data = newSVsv (fh_or_path); |
545 | req->data = newSVsv (fh_or_path); |
542 | req->dataptr = SvPV_nolen (req->data); |
546 | req->dataptr = SvPV_nolen (req->data); |
543 | } |
547 | } |
544 | else |
548 | else |
545 | { |
549 | { |
… | |
… | |
551 | |
555 | |
552 | send_req (req); |
556 | send_req (req); |
553 | } |
557 | } |
554 | |
558 | |
555 | void |
559 | void |
556 | aio_unlink(pathname,callback) |
560 | aio_unlink(pathname,callback=&PL_sv_undef) |
557 | SV * pathname |
561 | SV * pathname |
558 | SV * callback |
562 | SV * callback |
559 | PROTOTYPE: $$ |
|
|
560 | CODE: |
563 | CODE: |
561 | { |
564 | { |
562 | aio_req req; |
565 | aio_req req; |
563 | |
566 | |
564 | Newz (0, req, 1, aio_cb); |
567 | Newz (0, req, 1, aio_cb); |
… | |
… | |
582 | { |
585 | { |
583 | poll_wait (); |
586 | poll_wait (); |
584 | poll_cb (); |
587 | poll_cb (); |
585 | } |
588 | } |
586 | |
589 | |
|
|
590 | void |
|
|
591 | poll() |
|
|
592 | PROTOTYPE: |
|
|
593 | CODE: |
|
|
594 | if (nreqs) |
|
|
595 | { |
|
|
596 | poll_wait (); |
|
|
597 | poll_cb (); |
|
|
598 | } |
|
|
599 | |
587 | int |
600 | int |
588 | poll_fileno() |
601 | poll_fileno() |
589 | PROTOTYPE: |
602 | PROTOTYPE: |
590 | CODE: |
603 | CODE: |
591 | RETVAL = respipe [0]; |
604 | RETVAL = respipe [0]; |