… | |
… | |
31 | # else |
31 | # else |
32 | # error sendfile support requested but not available |
32 | # error sendfile support requested but not available |
33 | # endif |
33 | # endif |
34 | #endif |
34 | #endif |
35 | |
35 | |
|
|
36 | /* used for struct dirent, AIX doesn't provide it */ |
|
|
37 | #ifndef NAME_MAX |
|
|
38 | # define NAME_MAX 4096 |
|
|
39 | #endif |
|
|
40 | |
36 | #if __ia64 |
41 | #if __ia64 |
37 | # define STACKSIZE 65536 |
42 | # define STACKSIZE 65536 |
38 | #else |
43 | #else |
39 | # define STACKSIZE 8192 |
44 | # define STACKSIZE 8192 |
40 | #endif |
45 | #endif |
… | |
… | |
44 | REQ_OPEN, REQ_CLOSE, |
49 | REQ_OPEN, REQ_CLOSE, |
45 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
50 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
46 | REQ_SENDFILE, |
51 | REQ_SENDFILE, |
47 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
52 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
48 | REQ_FSYNC, REQ_FDATASYNC, |
53 | REQ_FSYNC, REQ_FDATASYNC, |
49 | REQ_UNLINK, REQ_RMDIR, |
54 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
50 | REQ_READDIR, |
55 | REQ_READDIR, |
51 | REQ_SYMLINK, |
56 | REQ_LINK, REQ_SYMLINK, |
52 | }; |
57 | }; |
53 | |
58 | |
54 | typedef struct aio_cb { |
59 | typedef struct aio_cb { |
55 | struct aio_cb *volatile next; |
60 | struct aio_cb *volatile next; |
56 | |
61 | |
… | |
… | |
499 | |
504 | |
500 | if (res < 0 && sbytes) |
505 | if (res < 0 && sbytes) |
501 | res = sbytes; |
506 | res = sbytes; |
502 | } |
507 | } |
503 | |
508 | |
|
|
509 | # endif |
504 | # else |
510 | #else |
505 | res = -1; |
511 | res = -1; |
506 | errno = ENOSYS; |
512 | errno = ENOSYS; |
507 | # endif |
|
|
508 | #endif |
513 | #endif |
509 | |
514 | |
510 | if (res < 0 |
515 | if (res < 0 |
511 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
516 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
512 | #if __solaris |
517 | #if __solaris |
… | |
… | |
517 | { |
522 | { |
518 | /* emulate sendfile. this is a major pain in the ass */ |
523 | /* emulate sendfile. this is a major pain in the ass */ |
519 | char buf[4096]; |
524 | char buf[4096]; |
520 | res = 0; |
525 | res = 0; |
521 | |
526 | |
522 | for (;;) |
527 | while (count) |
523 | { |
528 | { |
524 | ssize_t cnt; |
529 | ssize_t cnt; |
525 | |
530 | |
526 | cnt = pread (ifd, buf, 4096, offset); |
531 | cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset); |
527 | |
532 | |
528 | if (cnt <= 0) |
533 | if (cnt <= 0) |
529 | { |
534 | { |
530 | if (cnt && !res) res = -1; |
535 | if (cnt && !res) res = -1; |
531 | break; |
536 | break; |
… | |
… | |
539 | break; |
544 | break; |
540 | } |
545 | } |
541 | |
546 | |
542 | offset += cnt; |
547 | offset += cnt; |
543 | res += cnt; |
548 | res += cnt; |
|
|
549 | count -= cnt; |
544 | } |
550 | } |
545 | } |
551 | } |
546 | |
552 | |
547 | return res; |
553 | return res; |
548 | } |
554 | } |
… | |
… | |
659 | |
665 | |
660 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
666 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
661 | case REQ_CLOSE: req->result = close (req->fd); break; |
667 | case REQ_CLOSE: req->result = close (req->fd); break; |
662 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
668 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
663 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
669 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
|
|
670 | case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break; |
|
|
671 | case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break; |
664 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
672 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
665 | |
673 | |
666 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
674 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
667 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
675 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
668 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
676 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
… | |
… | |
779 | create_pipe (); |
787 | create_pipe (); |
780 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
788 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
781 | } |
789 | } |
782 | |
790 | |
783 | void |
791 | void |
784 | min_parallel(nthreads) |
792 | min_parallel (nthreads) |
785 | int nthreads |
793 | int nthreads |
786 | PROTOTYPE: $ |
794 | PROTOTYPE: $ |
787 | |
795 | |
788 | void |
796 | void |
789 | max_parallel(nthreads) |
797 | max_parallel (nthreads) |
790 | int nthreads |
798 | int nthreads |
791 | PROTOTYPE: $ |
799 | PROTOTYPE: $ |
792 | |
800 | |
793 | int |
801 | int |
794 | max_outstanding(nreqs) |
802 | max_outstanding (nreqs) |
795 | int nreqs |
803 | int nreqs |
796 | PROTOTYPE: $ |
804 | PROTOTYPE: $ |
797 | CODE: |
805 | CODE: |
798 | RETVAL = max_outstanding; |
806 | RETVAL = max_outstanding; |
799 | max_outstanding = nreqs; |
807 | max_outstanding = nreqs; |
800 | |
808 | |
801 | void |
809 | void |
802 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
810 | aio_open (pathname,flags,mode,callback=&PL_sv_undef) |
803 | SV * pathname |
811 | SV * pathname |
804 | int flags |
812 | int flags |
805 | int mode |
813 | int mode |
806 | SV * callback |
814 | SV * callback |
807 | PROTOTYPE: $$$;$ |
815 | PROTOTYPE: $$$;$ |
… | |
… | |
817 | |
825 | |
818 | send_req (req); |
826 | send_req (req); |
819 | } |
827 | } |
820 | |
828 | |
821 | void |
829 | void |
822 | aio_close(fh,callback=&PL_sv_undef) |
830 | aio_close (fh,callback=&PL_sv_undef) |
823 | SV * fh |
831 | SV * fh |
824 | SV * callback |
832 | SV * callback |
825 | PROTOTYPE: $;$ |
833 | PROTOTYPE: $;$ |
826 | ALIAS: |
834 | ALIAS: |
827 | aio_close = REQ_CLOSE |
835 | aio_close = REQ_CLOSE |
… | |
… | |
837 | |
845 | |
838 | send_req (req); |
846 | send_req (req); |
839 | } |
847 | } |
840 | |
848 | |
841 | void |
849 | void |
842 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
850 | aio_read (fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
843 | SV * fh |
851 | SV * fh |
844 | UV offset |
852 | UV offset |
845 | UV length |
853 | UV length |
846 | SV * data |
854 | SV * data |
847 | UV dataoffset |
855 | UV dataoffset |
… | |
… | |
901 | send_req (req); |
909 | send_req (req); |
902 | } |
910 | } |
903 | } |
911 | } |
904 | |
912 | |
905 | void |
913 | void |
906 | aio_sendfile(out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) |
914 | aio_sendfile (out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) |
907 | SV * out_fh |
915 | SV * out_fh |
908 | SV * in_fh |
916 | SV * in_fh |
909 | UV in_offset |
917 | UV in_offset |
910 | UV length |
918 | UV length |
911 | SV * callback |
919 | SV * callback |
… | |
… | |
924 | |
932 | |
925 | send_req (req); |
933 | send_req (req); |
926 | } |
934 | } |
927 | |
935 | |
928 | void |
936 | void |
929 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
937 | aio_readahead (fh,offset,length,callback=&PL_sv_undef) |
930 | SV * fh |
938 | SV * fh |
931 | UV offset |
939 | UV offset |
932 | IV length |
940 | IV length |
933 | SV * callback |
941 | SV * callback |
934 | PROTOTYPE: $$$;$ |
942 | PROTOTYPE: $$$;$ |
… | |
… | |
944 | |
952 | |
945 | send_req (req); |
953 | send_req (req); |
946 | } |
954 | } |
947 | |
955 | |
948 | void |
956 | void |
949 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
957 | aio_stat (fh_or_path,callback=&PL_sv_undef) |
950 | SV * fh_or_path |
958 | SV * fh_or_path |
951 | SV * callback |
959 | SV * callback |
952 | ALIAS: |
960 | ALIAS: |
953 | aio_stat = REQ_STAT |
961 | aio_stat = REQ_STAT |
954 | aio_lstat = REQ_LSTAT |
962 | aio_lstat = REQ_LSTAT |
… | |
… | |
978 | |
986 | |
979 | send_req (req); |
987 | send_req (req); |
980 | } |
988 | } |
981 | |
989 | |
982 | void |
990 | void |
983 | aio_unlink(pathname,callback=&PL_sv_undef) |
991 | aio_unlink (pathname,callback=&PL_sv_undef) |
984 | SV * pathname |
992 | SV * pathname |
985 | SV * callback |
993 | SV * callback |
986 | ALIAS: |
994 | ALIAS: |
987 | aio_unlink = REQ_UNLINK |
995 | aio_unlink = REQ_UNLINK |
988 | aio_rmdir = REQ_RMDIR |
996 | aio_rmdir = REQ_RMDIR |
|
|
997 | aio_readdir = REQ_READDIR |
989 | CODE: |
998 | CODE: |
990 | { |
999 | { |
991 | dREQ; |
1000 | dREQ; |
992 | |
1001 | |
993 | req->type = ix; |
1002 | req->type = ix; |
… | |
… | |
996 | |
1005 | |
997 | send_req (req); |
1006 | send_req (req); |
998 | } |
1007 | } |
999 | |
1008 | |
1000 | void |
1009 | void |
1001 | aio_symlink(oldpath,newpath,callback=&PL_sv_undef) |
1010 | aio_link (oldpath,newpath,callback=&PL_sv_undef) |
1002 | SV * oldpath |
1011 | SV * oldpath |
1003 | SV * newpath |
1012 | SV * newpath |
1004 | SV * callback |
1013 | SV * callback |
|
|
1014 | ALIAS: |
|
|
1015 | aio_link = REQ_LINK |
|
|
1016 | aio_symlink = REQ_SYMLINK |
|
|
1017 | aio_rename = REQ_RENAME |
1005 | CODE: |
1018 | CODE: |
1006 | { |
1019 | { |
1007 | dREQ; |
1020 | dREQ; |
1008 | |
1021 | |
1009 | req->type = REQ_SYMLINK; |
1022 | req->type = ix; |
1010 | req->fh = newSVsv (oldpath); |
1023 | req->fh = newSVsv (oldpath); |
1011 | req->data2ptr = SvPVbyte_nolen (req->fh); |
1024 | req->data2ptr = SvPVbyte_nolen (req->fh); |
1012 | req->data = newSVsv (newpath); |
1025 | req->data = newSVsv (newpath); |
1013 | req->dataptr = SvPVbyte_nolen (req->data); |
1026 | req->dataptr = SvPVbyte_nolen (req->data); |
1014 | |
1027 | |
1015 | send_req (req); |
1028 | send_req (req); |
1016 | } |
1029 | } |
1017 | |
1030 | |
1018 | void |
1031 | void |
1019 | aio_readdir(pathname,callback=&PL_sv_undef) |
|
|
1020 | SV * pathname |
|
|
1021 | SV * callback |
|
|
1022 | CODE: |
|
|
1023 | { |
|
|
1024 | dREQ; |
|
|
1025 | |
|
|
1026 | req->type = REQ_READDIR; |
|
|
1027 | req->data = newSVsv (pathname); |
|
|
1028 | req->dataptr = SvPVbyte_nolen (req->data); |
|
|
1029 | |
|
|
1030 | send_req (req); |
|
|
1031 | } |
|
|
1032 | |
|
|
1033 | void |
|
|
1034 | flush() |
1032 | flush () |
1035 | PROTOTYPE: |
1033 | PROTOTYPE: |
1036 | CODE: |
1034 | CODE: |
1037 | while (nreqs) |
1035 | while (nreqs) |
1038 | { |
1036 | { |
1039 | poll_wait (); |
1037 | poll_wait (); |