… | |
… | |
11 | #include <stddef.h> |
11 | #include <stddef.h> |
12 | #include <stdlib.h> |
12 | #include <stdlib.h> |
13 | #include <errno.h> |
13 | #include <errno.h> |
14 | #include <sys/types.h> |
14 | #include <sys/types.h> |
15 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
16 | #include <sys/statvfs.h> |
|
|
17 | #include <limits.h> |
16 | #include <limits.h> |
18 | #include <fcntl.h> |
17 | #include <fcntl.h> |
19 | #include <sched.h> |
18 | #include <sched.h> |
20 | |
19 | |
21 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
… | |
… | |
47 | # undef unlink |
46 | # undef unlink |
48 | # undef rmdir |
47 | # undef rmdir |
49 | # undef rename |
48 | # undef rename |
50 | # undef lseek |
49 | # undef lseek |
51 | |
50 | |
52 | # define chown(a,b,c) (errno = ENOSYS, -1) |
|
|
53 | # define fchown(a,b,c) (errno = ENOSYS, -1) |
|
|
54 | # define fchmod(a,b) (errno = ENOSYS, -1) |
|
|
55 | # define symlink(a,b) (errno = ENOSYS, -1) |
|
|
56 | # define readlink(a,b,c) (errno = ENOSYS, -1) |
|
|
57 | # define mknod(a,b,c) (errno = ENOSYS, -1) |
|
|
58 | # define truncate(a,b) (errno = ENOSYS, -1) |
|
|
59 | # define ftruncate(fd,o) chsize ((fd), (o)) |
|
|
60 | # define fsync(fd) _commit (fd) |
|
|
61 | # define opendir(fd) (errno = ENOSYS, 0) |
51 | # define opendir(fd) (errno = ENOSYS, 0) |
62 | # define readdir(fd) (errno = ENOSYS, -1) |
52 | # define readdir(fd) (errno = ENOSYS, -1) |
63 | # define closedir(fd) (errno = ENOSYS, -1) |
53 | # define closedir(fd) (errno = ENOSYS, -1) |
64 | # define mkdir(a,b) mkdir (a) |
|
|
65 | |
54 | |
66 | #else |
55 | #else |
67 | |
56 | |
68 | # include <sys/time.h> |
57 | # include <sys/time.h> |
69 | # include <sys/select.h> |
58 | # include <sys/select.h> |
… | |
… | |
120 | |
109 | |
121 | #define EIO_NO_WRAPPERS 1 |
110 | #define EIO_NO_WRAPPERS 1 |
122 | |
111 | |
123 | #include "libeio/config.h" |
112 | #include "libeio/config.h" |
124 | #include "libeio/eio.h" |
113 | #include "libeio/eio.h" |
|
|
114 | |
|
|
115 | /* Linux/others */ |
|
|
116 | #ifndef O_ASYNC |
|
|
117 | # define O_ASYNC 0 |
|
|
118 | #endif |
|
|
119 | #ifndef O_DIRECT |
|
|
120 | # define O_DIRECT 0 |
|
|
121 | #endif |
|
|
122 | #ifndef O_NOATIME |
|
|
123 | # define O_NOATIME 0 |
|
|
124 | #endif |
|
|
125 | |
|
|
126 | /* POSIX */ |
|
|
127 | #ifndef O_CLOEXEC |
|
|
128 | # define O_CLOEXEC 0 |
|
|
129 | #endif |
|
|
130 | #ifndef O_NOFOLLOW |
|
|
131 | # define O_NOFOLLOW 0 |
|
|
132 | #endif |
|
|
133 | #ifndef O_NOCTTY |
|
|
134 | # define O_NOCTTY 0 |
|
|
135 | #endif |
|
|
136 | #ifndef O_NONBLOCK |
|
|
137 | # define O_NONBLOCK 0 |
|
|
138 | #endif |
|
|
139 | #ifndef O_EXEC |
|
|
140 | # define O_EXEC 0 |
|
|
141 | #endif |
|
|
142 | #ifndef O_SEARCH |
|
|
143 | # define O_SEARCH 0 |
|
|
144 | #endif |
|
|
145 | #ifndef O_DIRECTORY |
|
|
146 | # define O_DIRECTORY 0 |
|
|
147 | #endif |
|
|
148 | #ifndef O_DSYNC |
|
|
149 | # define O_DSYNC 0 |
|
|
150 | #endif |
|
|
151 | #ifndef O_RSYNC |
|
|
152 | # define O_RSYNC 0 |
|
|
153 | #endif |
|
|
154 | #ifndef O_SYNC |
|
|
155 | # define O_SYNC 0 |
|
|
156 | #endif |
|
|
157 | #ifndef O_TTY_INIT |
|
|
158 | # define O_TTY_INIT 0 |
|
|
159 | #endif |
125 | |
160 | |
126 | #ifndef POSIX_FADV_NORMAL |
161 | #ifndef POSIX_FADV_NORMAL |
127 | # define POSIX_FADV_NORMAL 0 |
162 | # define POSIX_FADV_NORMAL 0 |
128 | #endif |
163 | #endif |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
164 | #ifndef POSIX_FADV_SEQUENTIAL |
… | |
… | |
539 | case EIO_NOP: |
574 | case EIO_NOP: |
540 | case EIO_BUSY: |
575 | case EIO_BUSY: |
541 | break; |
576 | break; |
542 | |
577 | |
543 | case EIO_READLINK: |
578 | case EIO_READLINK: |
|
|
579 | case EIO_REALPATH: |
544 | if (req->result > 0) |
580 | if (req->result > 0) |
545 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
581 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
546 | break; |
582 | break; |
547 | |
583 | |
548 | case EIO_STAT: |
584 | case EIO_STAT: |
… | |
… | |
620 | grp->sv2 = 0; |
656 | grp->sv2 = 0; |
621 | |
657 | |
622 | eio_grp_cancel (grp); |
658 | eio_grp_cancel (grp); |
623 | } |
659 | } |
624 | |
660 | |
625 | static void |
|
|
626 | create_respipe (void) |
661 | static void create_respipe (void) |
627 | { |
662 | { |
628 | if (s_epipe_renew (&respipe)) |
663 | if (s_epipe_renew (&respipe)) |
629 | croak ("IO::AIO: unable to initialize result pipe"); |
664 | croak ("IO::AIO: unable to initialize result pipe"); |
630 | } |
665 | } |
631 | |
666 | |
… | |
… | |
685 | # define MAP_FIXED 0 |
720 | # define MAP_FIXED 0 |
686 | #endif |
721 | #endif |
687 | |
722 | |
688 | #define MMAP_MAGIC PERL_MAGIC_ext |
723 | #define MMAP_MAGIC PERL_MAGIC_ext |
689 | |
724 | |
690 | static int |
|
|
691 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
725 | static int mmap_free (pTHX_ SV *sv, MAGIC *mg) |
692 | { |
726 | { |
693 | int old_errno = errno; |
727 | int old_errno = errno; |
694 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
728 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
695 | errno = old_errno; |
729 | errno = old_errno; |
696 | |
730 | |
… | |
… | |
712 | 0, 0, 0, 0, mmap_free |
746 | 0, 0, 0, 0, mmap_free |
713 | }; |
747 | }; |
714 | |
748 | |
715 | /*****************************************************************************/ |
749 | /*****************************************************************************/ |
716 | |
750 | |
717 | static SV * |
|
|
718 | get_cb (SV *cb_sv) |
751 | static SV * get_cb (SV *cb_sv) |
719 | { |
752 | { |
720 | SvGETMAGIC (cb_sv); |
753 | SvGETMAGIC (cb_sv); |
721 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
754 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
722 | } |
755 | } |
723 | |
756 | |
… | |
… | |
765 | const_iv (O_CREAT) |
798 | const_iv (O_CREAT) |
766 | const_iv (O_TRUNC) |
799 | const_iv (O_TRUNC) |
767 | const_iv (O_EXCL) |
800 | const_iv (O_EXCL) |
768 | const_iv (O_APPEND) |
801 | const_iv (O_APPEND) |
769 | |
802 | |
|
|
803 | const_iv (O_ASYNC) |
|
|
804 | const_iv (O_DIRECT) |
|
|
805 | const_iv (O_NOATIME) |
|
|
806 | |
|
|
807 | const_iv (O_CLOEXEC) |
|
|
808 | const_iv (O_NOCTTY) |
|
|
809 | const_iv (O_NOFOLLOW) |
|
|
810 | const_iv (O_NONBLOCK) |
|
|
811 | const_iv (O_EXEC) |
|
|
812 | const_iv (O_SEARCH) |
|
|
813 | const_iv (O_DIRECTORY) |
|
|
814 | const_iv (O_DSYNC) |
|
|
815 | const_iv (O_RSYNC) |
|
|
816 | const_iv (O_SYNC) |
|
|
817 | const_iv (O_TTY_INIT) |
|
|
818 | |
770 | const_iv (S_IFIFO) |
819 | const_iv (S_IFIFO) |
771 | const_iv (S_IFCHR) |
820 | const_iv (S_IFCHR) |
772 | const_iv (S_IFBLK) |
821 | const_iv (S_IFBLK) |
773 | const_iv (S_IFLNK) |
822 | const_iv (S_IFLNK) |
774 | const_iv (S_IFREG) |
823 | const_iv (S_IFREG) |
… | |
… | |
831 | |
880 | |
832 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
881 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
833 | const_eio (SYNC_FILE_RANGE_WRITE) |
882 | const_eio (SYNC_FILE_RANGE_WRITE) |
834 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
883 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
835 | |
884 | |
|
|
885 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
886 | |
836 | const_eio (READDIR_DENTS) |
887 | const_eio (READDIR_DENTS) |
837 | const_eio (READDIR_DIRS_FIRST) |
888 | const_eio (READDIR_DIRS_FIRST) |
838 | const_eio (READDIR_STAT_ORDER) |
889 | const_eio (READDIR_STAT_ORDER) |
839 | const_eio (READDIR_FOUND_UNKNOWN) |
890 | const_eio (READDIR_FOUND_UNKNOWN) |
840 | |
891 | |
… | |
… | |
866 | /* atfork child called in fifo order, so before eio's handler */ |
917 | /* atfork child called in fifo order, so before eio's handler */ |
867 | X_THREAD_ATFORK (0, 0, atfork_child); |
918 | X_THREAD_ATFORK (0, 0, atfork_child); |
868 | } |
919 | } |
869 | |
920 | |
870 | void |
921 | void |
871 | max_poll_reqs (int nreqs) |
922 | max_poll_reqs (unsigned int nreqs) |
872 | PROTOTYPE: $ |
923 | PROTOTYPE: $ |
873 | CODE: |
924 | CODE: |
874 | eio_set_max_poll_reqs (nreqs); |
925 | eio_set_max_poll_reqs (nreqs); |
875 | |
926 | |
876 | void |
927 | void |
… | |
… | |
878 | PROTOTYPE: $ |
929 | PROTOTYPE: $ |
879 | CODE: |
930 | CODE: |
880 | eio_set_max_poll_time (nseconds); |
931 | eio_set_max_poll_time (nseconds); |
881 | |
932 | |
882 | void |
933 | void |
883 | min_parallel (int nthreads) |
934 | min_parallel (unsigned int nthreads) |
884 | PROTOTYPE: $ |
935 | PROTOTYPE: $ |
885 | CODE: |
936 | CODE: |
886 | eio_set_min_parallel (nthreads); |
937 | eio_set_min_parallel (nthreads); |
887 | |
938 | |
888 | void |
939 | void |
889 | max_parallel (int nthreads) |
940 | max_parallel (unsigned int nthreads) |
890 | PROTOTYPE: $ |
941 | PROTOTYPE: $ |
891 | CODE: |
942 | CODE: |
892 | eio_set_max_parallel (nthreads); |
943 | eio_set_max_parallel (nthreads); |
893 | |
944 | |
894 | void |
945 | void |
895 | max_idle (int nthreads) |
946 | max_idle (unsigned int nthreads) |
896 | PROTOTYPE: $ |
947 | PROTOTYPE: $ |
897 | CODE: |
948 | CODE: |
898 | eio_set_max_idle (nthreads); |
949 | eio_set_max_idle (nthreads); |
899 | |
950 | |
900 | void |
951 | void |
|
|
952 | idle_timeout (unsigned int seconds) |
|
|
953 | PROTOTYPE: $ |
|
|
954 | CODE: |
|
|
955 | eio_set_idle_timeout (seconds); |
|
|
956 | |
|
|
957 | void |
901 | max_outstanding (int maxreqs) |
958 | max_outstanding (unsigned int maxreqs) |
902 | PROTOTYPE: $ |
959 | PROTOTYPE: $ |
903 | CODE: |
960 | CODE: |
904 | max_outstanding = maxreqs; |
961 | max_outstanding = maxreqs; |
905 | |
962 | |
906 | void |
963 | void |
… | |
… | |
946 | req->sv1 = newSVsv (fh); |
1003 | req->sv1 = newSVsv (fh); |
947 | req->int1 = fd; |
1004 | req->int1 = fd; |
948 | req->offs = offset; |
1005 | req->offs = offset; |
949 | req->size = nbytes; |
1006 | req->size = nbytes; |
950 | req->int2 = flags; |
1007 | req->int2 = flags; |
|
|
1008 | |
|
|
1009 | REQ_SEND (req); |
|
|
1010 | } |
|
|
1011 | |
|
|
1012 | void |
|
|
1013 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
|
|
1014 | PPCODE: |
|
|
1015 | { |
|
|
1016 | int fd = s_fileno_croak (fh, 0); |
|
|
1017 | dREQ; |
|
|
1018 | |
|
|
1019 | req->type = EIO_FALLOCATE; |
|
|
1020 | req->sv1 = newSVsv (fh); |
|
|
1021 | req->int1 = fd; |
|
|
1022 | req->int2 = mode; |
|
|
1023 | req->offs = offset; |
|
|
1024 | req->size = len; |
951 | |
1025 | |
952 | REQ_SEND (req); |
1026 | REQ_SEND (req); |
953 | } |
1027 | } |
954 | |
1028 | |
955 | void |
1029 | void |
… | |
… | |
1033 | } |
1107 | } |
1034 | } |
1108 | } |
1035 | |
1109 | |
1036 | void |
1110 | void |
1037 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1111 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
|
|
1112 | ALIAS: |
|
|
1113 | aio_readlink = EIO_READLINK |
|
|
1114 | aio_realpath = EIO_REALPATH |
1038 | PPCODE: |
1115 | PPCODE: |
1039 | { |
1116 | { |
1040 | SV *data; |
1117 | SV *data; |
1041 | dREQ; |
1118 | dREQ; |
1042 | |
1119 | |
1043 | req->type = EIO_READLINK; |
1120 | req->type = ix; |
1044 | req->sv1 = newSVsv (path); |
1121 | req->sv1 = newSVsv (path); |
1045 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1122 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1046 | |
1123 | |
1047 | REQ_SEND; |
1124 | REQ_SEND; |
1048 | } |
1125 | } |