1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
|
|
5 | #define _XOPEN_SOURCE 500 |
|
|
6 | |
5 | #include <sys/types.h> |
7 | #include <sys/types.h> |
6 | #include <sys/stat.h> |
8 | #include <sys/stat.h> |
|
|
9 | |
7 | #include <unistd.h> |
10 | #include <unistd.h> |
8 | #include <fcntl.h> |
11 | #include <fcntl.h> |
9 | #include <signal.h> |
12 | #include <signal.h> |
10 | #include <sched.h> |
13 | #include <sched.h> |
11 | #include <endian.h> |
14 | #if __linux |
|
|
15 | #include <sys/syscall.h> |
|
|
16 | #endif |
12 | |
17 | |
13 | #include <pthread.h> |
18 | #include <pthread.h> |
14 | #include <sys/syscall.h> |
|
|
15 | |
19 | |
16 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
20 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
17 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
21 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
18 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
22 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
19 | |
23 | |
… | |
… | |
148 | |
152 | |
149 | PUSHMARK (SP); |
153 | PUSHMARK (SP); |
150 | XPUSHs (fh); |
154 | XPUSHs (fh); |
151 | } |
155 | } |
152 | |
156 | |
|
|
157 | if (SvOK (req->callback)) |
|
|
158 | { |
153 | PUTBACK; |
159 | PUTBACK; |
154 | call_sv (req->callback, G_VOID | G_EVAL); |
160 | call_sv (req->callback, G_VOID | G_EVAL); |
155 | SPAGAIN; |
161 | SPAGAIN; |
|
|
162 | } |
156 | |
163 | |
157 | if (req->callback) |
164 | if (req->callback) |
158 | SvREFCNT_dec (req->callback); |
165 | SvREFCNT_dec (req->callback); |
159 | |
166 | |
160 | errno = errorno; |
167 | errno = errorno; |
… | |
… | |
306 | |
313 | |
307 | type = req->type; |
314 | type = req->type; |
308 | |
315 | |
309 | switch (type) |
316 | switch (type) |
310 | { |
317 | { |
311 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset); break; |
318 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
312 | case REQ_WRITE: req->result = pwrite64 (req->fd, req->dataptr, req->length, req->offset); break; |
319 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
313 | #if SYS_readahead |
320 | #if SYS_readahead |
314 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
321 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
315 | #else |
322 | #else |
316 | case REQ_READAHEAD: req->result = -1; errno = ENOSYS; break; |
323 | case REQ_READAHEAD: req->result = -1; errno = ENOSYS; break; |
317 | #endif |
324 | #endif |
… | |
… | |
361 | return 0; |
368 | return 0; |
362 | } |
369 | } |
363 | |
370 | |
364 | MODULE = IO::AIO PACKAGE = IO::AIO |
371 | MODULE = IO::AIO PACKAGE = IO::AIO |
365 | |
372 | |
|
|
373 | PROTOTYPES: ENABLE |
|
|
374 | |
366 | BOOT: |
375 | BOOT: |
367 | { |
376 | { |
368 | if (pipe (respipe)) |
377 | if (pipe (respipe)) |
369 | croak ("unable to initialize result pipe"); |
378 | croak ("unable to initialize result pipe"); |
370 | |
379 | |
… | |
… | |
410 | CODE: |
419 | CODE: |
411 | RETVAL = max_outstanding; |
420 | RETVAL = max_outstanding; |
412 | max_outstanding = nreqs; |
421 | max_outstanding = nreqs; |
413 | |
422 | |
414 | void |
423 | void |
415 | aio_open(pathname,flags,mode,callback) |
424 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
416 | SV * pathname |
425 | SV * pathname |
417 | int flags |
426 | int flags |
418 | int mode |
427 | int mode |
419 | SV * callback |
428 | SV * callback |
420 | PROTOTYPE: $$$$ |
429 | PROTOTYPE: $$$;$ |
421 | CODE: |
430 | CODE: |
422 | { |
431 | { |
423 | aio_req req; |
432 | aio_req req; |
424 | |
433 | |
425 | Newz (0, req, 1, aio_cb); |
434 | Newz (0, req, 1, aio_cb); |
… | |
… | |
436 | |
445 | |
437 | send_req (req); |
446 | send_req (req); |
438 | } |
447 | } |
439 | |
448 | |
440 | void |
449 | void |
441 | aio_close(fh,callback) |
450 | aio_close(fh,callback=&PL_sv_undef) |
442 | InputStream fh |
451 | InputStream fh |
443 | SV * callback |
452 | SV * callback |
444 | PROTOTYPE: $$ |
453 | PROTOTYPE: $;$ |
445 | ALIAS: |
454 | ALIAS: |
446 | aio_close = REQ_CLOSE |
455 | aio_close = REQ_CLOSE |
447 | aio_fsync = REQ_FSYNC |
456 | aio_fsync = REQ_FSYNC |
448 | aio_fdatasync = REQ_FDATASYNC |
457 | aio_fdatasync = REQ_FDATASYNC |
449 | CODE: |
458 | CODE: |
… | |
… | |
461 | |
470 | |
462 | send_req (req); |
471 | send_req (req); |
463 | } |
472 | } |
464 | |
473 | |
465 | void |
474 | void |
466 | aio_read(fh,offset,length,data,dataoffset,callback) |
475 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
467 | InputStream fh |
476 | InputStream fh |
468 | UV offset |
477 | UV offset |
469 | IV length |
478 | IV length |
470 | SV * data |
479 | SV * data |
471 | IV dataoffset |
480 | IV dataoffset |
472 | SV * callback |
481 | SV * callback |
473 | PROTOTYPE: $$$$$$ |
482 | PROTOTYPE: $$$$$;$ |
474 | CODE: |
483 | CODE: |
475 | read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
484 | read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
476 | |
485 | |
477 | void |
486 | void |
478 | aio_write(fh,offset,length,data,dataoffset,callback) |
487 | aio_write(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
479 | OutputStream fh |
488 | OutputStream fh |
480 | UV offset |
489 | UV offset |
481 | IV length |
490 | IV length |
482 | SV * data |
491 | SV * data |
483 | IV dataoffset |
492 | IV dataoffset |
484 | SV * callback |
493 | SV * callback |
485 | PROTOTYPE: $$$$$$ |
494 | PROTOTYPE: $$$$$;$ |
486 | CODE: |
495 | CODE: |
487 | read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
496 | read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
488 | |
497 | |
489 | void |
498 | void |
490 | aio_readahead(fh,offset,length,callback) |
499 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
491 | InputStream fh |
500 | InputStream fh |
492 | UV offset |
501 | UV offset |
493 | IV length |
502 | IV length |
494 | SV * callback |
503 | SV * callback |
495 | PROTOTYPE: $$$$ |
504 | PROTOTYPE: $$$;$ |
496 | CODE: |
505 | CODE: |
497 | { |
506 | { |
498 | aio_req req; |
507 | aio_req req; |
499 | |
508 | |
500 | if (length < 0) |
509 | if (length < 0) |
… | |
… | |
513 | |
522 | |
514 | send_req (req); |
523 | send_req (req); |
515 | } |
524 | } |
516 | |
525 | |
517 | void |
526 | void |
518 | aio_stat(fh_or_path,callback) |
527 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
519 | SV * fh_or_path |
528 | SV * fh_or_path |
520 | SV * callback |
529 | SV * callback |
521 | PROTOTYPE: $$ |
|
|
522 | ALIAS: |
530 | ALIAS: |
|
|
531 | aio_stat = REQ_STAT |
523 | aio_lstat = 1 |
532 | aio_lstat = REQ_LSTAT |
524 | CODE: |
533 | CODE: |
525 | { |
534 | { |
526 | aio_req req; |
535 | aio_req req; |
527 | |
536 | |
528 | Newz (0, req, 1, aio_cb); |
537 | Newz (0, req, 1, aio_cb); |
… | |
… | |
535 | if (!req->statdata) |
544 | if (!req->statdata) |
536 | croak ("out of memory during aio_req->statdata allocation"); |
545 | croak ("out of memory during aio_req->statdata allocation"); |
537 | |
546 | |
538 | if (SvPOK (fh_or_path)) |
547 | if (SvPOK (fh_or_path)) |
539 | { |
548 | { |
540 | req->type = ix ? REQ_LSTAT : REQ_STAT; |
549 | req->type = ix; |
541 | req->data = newSVsv (fh_or_path); |
550 | req->data = newSVsv (fh_or_path); |
542 | req->dataptr = SvPV_nolen (req->data); |
551 | req->dataptr = SvPV_nolen (req->data); |
543 | } |
552 | } |
544 | else |
553 | else |
545 | { |
554 | { |
… | |
… | |
551 | |
560 | |
552 | send_req (req); |
561 | send_req (req); |
553 | } |
562 | } |
554 | |
563 | |
555 | void |
564 | void |
556 | aio_unlink(pathname,callback) |
565 | aio_unlink(pathname,callback=&PL_sv_undef) |
557 | SV * pathname |
566 | SV * pathname |
558 | SV * callback |
567 | SV * callback |
559 | PROTOTYPE: $$ |
|
|
560 | CODE: |
568 | CODE: |
561 | { |
569 | { |
562 | aio_req req; |
570 | aio_req req; |
563 | |
571 | |
564 | Newz (0, req, 1, aio_cb); |
572 | Newz (0, req, 1, aio_cb); |