… | |
… | |
3 | #include <errno.h> |
3 | #include <errno.h> |
4 | |
4 | |
5 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
6 | #include "perl.h" |
6 | #include "perl.h" |
7 | #include "XSUB.h" |
7 | #include "XSUB.h" |
|
|
8 | |
|
|
9 | #include "schmorp.h" |
8 | |
10 | |
9 | #include <stddef.h> |
11 | #include <stddef.h> |
10 | #include <stdlib.h> |
12 | #include <stdlib.h> |
11 | #include <errno.h> |
13 | #include <errno.h> |
12 | #include <sys/types.h> |
14 | #include <sys/types.h> |
… | |
… | |
568 | req_submit (req); \ |
570 | req_submit (req); \ |
569 | SPAGAIN; \ |
571 | SPAGAIN; \ |
570 | \ |
572 | \ |
571 | if (GIMME_V != G_VOID) \ |
573 | if (GIMME_V != G_VOID) \ |
572 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
574 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
573 | |
|
|
574 | static int |
|
|
575 | extract_fd (SV *fh, int wr) |
|
|
576 | { |
|
|
577 | int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); |
|
|
578 | |
|
|
579 | if (fd < 0) |
|
|
580 | croak ("illegal fh argument, either not an OS file or read/write mode mismatch"); |
|
|
581 | |
|
|
582 | return fd; |
|
|
583 | } |
|
|
584 | |
575 | |
585 | MODULE = IO::AIO PACKAGE = IO::AIO |
576 | MODULE = IO::AIO PACKAGE = IO::AIO |
586 | |
577 | |
587 | PROTOTYPES: ENABLE |
578 | PROTOTYPES: ENABLE |
588 | |
579 | |
… | |
… | |
702 | ALIAS: |
693 | ALIAS: |
703 | aio_fsync = EIO_FSYNC |
694 | aio_fsync = EIO_FSYNC |
704 | aio_fdatasync = EIO_FDATASYNC |
695 | aio_fdatasync = EIO_FDATASYNC |
705 | PPCODE: |
696 | PPCODE: |
706 | { |
697 | { |
707 | int fd = extract_fd (fh, 0); |
698 | int fd = s_fileno_croak (fh, 0); |
708 | dREQ; |
699 | dREQ; |
709 | |
700 | |
710 | req->type = ix; |
701 | req->type = ix; |
711 | req->sv1 = newSVsv (fh); |
702 | req->sv1 = newSVsv (fh); |
712 | req->int1 = fd; |
703 | req->int1 = fd; |
… | |
… | |
717 | void |
708 | void |
718 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
709 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
719 | PROTOTYPE: $$$$;$ |
710 | PROTOTYPE: $$$$;$ |
720 | PPCODE: |
711 | PPCODE: |
721 | { |
712 | { |
722 | int fd = extract_fd (fh, 0); |
713 | int fd = s_fileno_croak (fh, 0); |
723 | dREQ; |
714 | dREQ; |
724 | |
715 | |
725 | req->type = EIO_SYNC_FILE_RANGE; |
716 | req->type = EIO_SYNC_FILE_RANGE; |
726 | req->sv1 = newSVsv (fh); |
717 | req->sv1 = newSVsv (fh); |
727 | req->int1 = fd; |
718 | req->int1 = fd; |
… | |
… | |
736 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
727 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
737 | PROTOTYPE: $;$ |
728 | PROTOTYPE: $;$ |
738 | PPCODE: |
729 | PPCODE: |
739 | { |
730 | { |
740 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
731 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
741 | int fd = extract_fd (fh, 0); |
732 | int fd = s_fileno_croak (fh, 0); |
742 | dREQ; |
733 | dREQ; |
743 | |
734 | |
744 | if (close_pipe < 0) |
735 | if (close_pipe < 0) |
745 | { |
736 | { |
746 | int pipefd [2]; |
737 | int pipefd [2]; |
… | |
… | |
768 | aio_write = EIO_WRITE |
759 | aio_write = EIO_WRITE |
769 | PROTOTYPE: $$$$$;$ |
760 | PROTOTYPE: $$$$$;$ |
770 | PPCODE: |
761 | PPCODE: |
771 | { |
762 | { |
772 | STRLEN svlen; |
763 | STRLEN svlen; |
773 | int fd = extract_fd (fh, ix == EIO_WRITE); |
764 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
774 | char *svptr = SvPVbyte (data, svlen); |
765 | char *svptr = SvPVbyte (data, svlen); |
775 | UV len = SvUV (length); |
766 | UV len = SvUV (length); |
776 | |
767 | |
777 | if (dataoffset < 0) |
768 | if (dataoffset < 0) |
778 | dataoffset += svlen; |
769 | dataoffset += svlen; |
… | |
… | |
833 | void |
824 | void |
834 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
825 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
835 | PROTOTYPE: $$$$;$ |
826 | PROTOTYPE: $$$$;$ |
836 | PPCODE: |
827 | PPCODE: |
837 | { |
828 | { |
838 | int ifd = extract_fd (in_fh , 0); |
829 | int ifd = s_fileno_croak (in_fh , 0); |
839 | int ofd = extract_fd (out_fh, 0); |
830 | int ofd = s_fileno_croak (out_fh, 1); |
840 | dREQ; |
831 | dREQ; |
841 | |
832 | |
842 | req->type = EIO_SENDFILE; |
833 | req->type = EIO_SENDFILE; |
843 | req->sv1 = newSVsv (out_fh); |
834 | req->sv1 = newSVsv (out_fh); |
844 | req->int1 = ofd; |
835 | req->int1 = ofd; |
… | |
… | |
853 | void |
844 | void |
854 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
845 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
855 | PROTOTYPE: $$$;$ |
846 | PROTOTYPE: $$$;$ |
856 | PPCODE: |
847 | PPCODE: |
857 | { |
848 | { |
858 | int fd = extract_fd (fh, 0); |
849 | int fd = s_fileno_croak (fh, 0); |
859 | dREQ; |
850 | dREQ; |
860 | |
851 | |
861 | req->type = EIO_READAHEAD; |
852 | req->type = EIO_READAHEAD; |
862 | req->sv1 = newSVsv (fh); |
853 | req->sv1 = newSVsv (fh); |
863 | req->int1 = fd; |
854 | req->int1 = fd; |
… | |
… | |
1193 | |
1184 | |
1194 | int |
1185 | int |
1195 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1186 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1196 | PROTOTYPE: $$$$ |
1187 | PROTOTYPE: $$$$ |
1197 | CODE: |
1188 | CODE: |
1198 | { |
|
|
1199 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
1189 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
1200 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1190 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1201 | #else |
1191 | #else |
1202 | RETVAL = errno = ENOSYS; |
1192 | RETVAL = errno = ENOSYS; |
1203 | #endif |
1193 | #endif |
1204 | } |
|
|
1205 | OUTPUT: |
1194 | OUTPUT: |
1206 | RETVAL |
1195 | RETVAL |
1207 | |
1196 | |
1208 | ssize_t |
1197 | ssize_t |
1209 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1198 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |