… | |
… | |
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> |
… | |
… | |
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" |
125 | |
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 |
|
|
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 |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
165 | # define POSIX_FADV_SEQUENTIAL 0 |
… | |
… | |
206 | #ifndef ST_NODIRATIME |
241 | #ifndef ST_NODIRATIME |
207 | # define ST_NODIRATIME 0 |
242 | # define ST_NODIRATIME 0 |
208 | #endif |
243 | #endif |
209 | #ifndef ST_RELATIME |
244 | #ifndef ST_RELATIME |
210 | # define ST_RELATIME 0 |
245 | # define ST_RELATIME 0 |
|
|
246 | #endif |
|
|
247 | |
|
|
248 | #ifndef S_IFIFO |
|
|
249 | # define S_IFIFO 0 |
|
|
250 | #endif |
|
|
251 | #ifndef S_IFCHR |
|
|
252 | # define S_IFCHR 0 |
|
|
253 | #endif |
|
|
254 | #ifndef S_IFBLK |
|
|
255 | # define S_IFBLK 0 |
|
|
256 | #endif |
|
|
257 | #ifndef S_IFLNK |
|
|
258 | # define S_IFLNK 0 |
|
|
259 | #endif |
|
|
260 | #ifndef S_IFREG |
|
|
261 | # define S_IFREG 0 |
|
|
262 | #endif |
|
|
263 | #ifndef S_IFDIR |
|
|
264 | # define S_IFDIR 0 |
|
|
265 | #endif |
|
|
266 | #ifndef S_IFWHT |
|
|
267 | # define S_IFWHT 0 |
|
|
268 | #endif |
|
|
269 | #ifndef S_IFSOCK |
|
|
270 | # define S_IFSOCK 0 |
211 | #endif |
271 | #endif |
212 | |
272 | |
213 | #ifndef MAP_ANONYMOUS |
273 | #ifndef MAP_ANONYMOUS |
214 | # ifdef MAP_ANON |
274 | # ifdef MAP_ANON |
215 | # define MAP_ANONYMOUS MAP_ANON |
275 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
229 | #ifndef MAP_POPULATE |
289 | #ifndef MAP_POPULATE |
230 | # define MAP_POPULATE 0 |
290 | # define MAP_POPULATE 0 |
231 | #endif |
291 | #endif |
232 | #ifndef MAP_NONBLOCK |
292 | #ifndef MAP_NONBLOCK |
233 | # define MAP_NONBLOCK 0 |
293 | # define MAP_NONBLOCK 0 |
|
|
294 | #endif |
|
|
295 | |
|
|
296 | #ifndef makedev |
|
|
297 | # define makedev(maj,min) (((maj) << 8) | (min)) |
|
|
298 | #endif |
|
|
299 | #ifndef major |
|
|
300 | # define major(dev) ((dev) >> 8) |
|
|
301 | #endif |
|
|
302 | #ifndef minor |
|
|
303 | # define minor(dev) ((dev) & 0xff) |
234 | #endif |
304 | #endif |
235 | |
305 | |
236 | #ifndef PAGESIZE |
306 | #ifndef PAGESIZE |
237 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
307 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
238 | #endif |
308 | #endif |
… | |
… | |
504 | case EIO_NOP: |
574 | case EIO_NOP: |
505 | case EIO_BUSY: |
575 | case EIO_BUSY: |
506 | break; |
576 | break; |
507 | |
577 | |
508 | case EIO_READLINK: |
578 | case EIO_READLINK: |
|
|
579 | case EIO_REALPATH: |
509 | if (req->result > 0) |
580 | if (req->result > 0) |
510 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
581 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
511 | break; |
582 | break; |
512 | |
583 | |
513 | case EIO_STAT: |
584 | case EIO_STAT: |
… | |
… | |
585 | grp->sv2 = 0; |
656 | grp->sv2 = 0; |
586 | |
657 | |
587 | eio_grp_cancel (grp); |
658 | eio_grp_cancel (grp); |
588 | } |
659 | } |
589 | |
660 | |
590 | static void |
|
|
591 | create_respipe (void) |
661 | static void create_respipe (void) |
592 | { |
662 | { |
593 | if (s_epipe_renew (&respipe)) |
663 | if (s_epipe_renew (&respipe)) |
594 | croak ("IO::AIO: unable to initialize result pipe"); |
664 | croak ("IO::AIO: unable to initialize result pipe"); |
595 | } |
665 | } |
596 | |
666 | |
… | |
… | |
650 | # define MAP_FIXED 0 |
720 | # define MAP_FIXED 0 |
651 | #endif |
721 | #endif |
652 | |
722 | |
653 | #define MMAP_MAGIC PERL_MAGIC_ext |
723 | #define MMAP_MAGIC PERL_MAGIC_ext |
654 | |
724 | |
655 | static int |
|
|
656 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
725 | static int mmap_free (pTHX_ SV *sv, MAGIC *mg) |
657 | { |
726 | { |
658 | int old_errno = errno; |
727 | int old_errno = errno; |
659 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
728 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
660 | errno = old_errno; |
729 | errno = old_errno; |
661 | |
730 | |
… | |
… | |
677 | 0, 0, 0, 0, mmap_free |
746 | 0, 0, 0, 0, mmap_free |
678 | }; |
747 | }; |
679 | |
748 | |
680 | /*****************************************************************************/ |
749 | /*****************************************************************************/ |
681 | |
750 | |
682 | static SV * |
|
|
683 | get_cb (SV *cb_sv) |
751 | static SV * get_cb (SV *cb_sv) |
684 | { |
752 | { |
685 | SvGETMAGIC (cb_sv); |
753 | SvGETMAGIC (cb_sv); |
686 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
754 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
687 | } |
755 | } |
688 | |
756 | |
… | |
… | |
729 | const_iv (O_RDWR) |
797 | const_iv (O_RDWR) |
730 | const_iv (O_CREAT) |
798 | const_iv (O_CREAT) |
731 | const_iv (O_TRUNC) |
799 | const_iv (O_TRUNC) |
732 | const_iv (O_EXCL) |
800 | const_iv (O_EXCL) |
733 | const_iv (O_APPEND) |
801 | const_iv (O_APPEND) |
734 | #ifndef _WIN32 |
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 | |
735 | const_iv (S_IFIFO) |
819 | const_iv (S_IFIFO) |
736 | #endif |
820 | const_iv (S_IFCHR) |
|
|
821 | const_iv (S_IFBLK) |
|
|
822 | const_iv (S_IFLNK) |
|
|
823 | const_iv (S_IFREG) |
|
|
824 | const_iv (S_IFDIR) |
|
|
825 | const_iv (S_IFWHT) |
|
|
826 | const_iv (S_IFSOCK) |
|
|
827 | const_iv (S_IFMT) |
|
|
828 | |
737 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
829 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
738 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
830 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
739 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
831 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
740 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
832 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
741 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
833 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
… | |
… | |
788 | |
880 | |
789 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
881 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
790 | const_eio (SYNC_FILE_RANGE_WRITE) |
882 | const_eio (SYNC_FILE_RANGE_WRITE) |
791 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
883 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
792 | |
884 | |
|
|
885 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
886 | |
793 | const_eio (READDIR_DENTS) |
887 | const_eio (READDIR_DENTS) |
794 | const_eio (READDIR_DIRS_FIRST) |
888 | const_eio (READDIR_DIRS_FIRST) |
795 | const_eio (READDIR_STAT_ORDER) |
889 | const_eio (READDIR_STAT_ORDER) |
796 | const_eio (READDIR_FOUND_UNKNOWN) |
890 | const_eio (READDIR_FOUND_UNKNOWN) |
797 | |
891 | |
… | |
… | |
823 | /* atfork child called in fifo order, so before eio's handler */ |
917 | /* atfork child called in fifo order, so before eio's handler */ |
824 | X_THREAD_ATFORK (0, 0, atfork_child); |
918 | X_THREAD_ATFORK (0, 0, atfork_child); |
825 | } |
919 | } |
826 | |
920 | |
827 | void |
921 | void |
828 | max_poll_reqs (int nreqs) |
922 | max_poll_reqs (unsigned int nreqs) |
829 | PROTOTYPE: $ |
923 | PROTOTYPE: $ |
830 | CODE: |
924 | CODE: |
831 | eio_set_max_poll_reqs (nreqs); |
925 | eio_set_max_poll_reqs (nreqs); |
832 | |
926 | |
833 | void |
927 | void |
… | |
… | |
835 | PROTOTYPE: $ |
929 | PROTOTYPE: $ |
836 | CODE: |
930 | CODE: |
837 | eio_set_max_poll_time (nseconds); |
931 | eio_set_max_poll_time (nseconds); |
838 | |
932 | |
839 | void |
933 | void |
840 | min_parallel (int nthreads) |
934 | min_parallel (unsigned int nthreads) |
841 | PROTOTYPE: $ |
935 | PROTOTYPE: $ |
842 | CODE: |
936 | CODE: |
843 | eio_set_min_parallel (nthreads); |
937 | eio_set_min_parallel (nthreads); |
844 | |
938 | |
845 | void |
939 | void |
846 | max_parallel (int nthreads) |
940 | max_parallel (unsigned int nthreads) |
847 | PROTOTYPE: $ |
941 | PROTOTYPE: $ |
848 | CODE: |
942 | CODE: |
849 | eio_set_max_parallel (nthreads); |
943 | eio_set_max_parallel (nthreads); |
850 | |
944 | |
851 | void |
945 | void |
852 | max_idle (int nthreads) |
946 | max_idle (unsigned int nthreads) |
853 | PROTOTYPE: $ |
947 | PROTOTYPE: $ |
854 | CODE: |
948 | CODE: |
855 | eio_set_max_idle (nthreads); |
949 | eio_set_max_idle (nthreads); |
856 | |
950 | |
857 | void |
951 | void |
|
|
952 | idle_timeout (unsigned int seconds) |
|
|
953 | PROTOTYPE: $ |
|
|
954 | CODE: |
|
|
955 | eio_set_idle_timeout (seconds); |
|
|
956 | |
|
|
957 | void |
858 | max_outstanding (int maxreqs) |
958 | max_outstanding (unsigned int maxreqs) |
859 | PROTOTYPE: $ |
959 | PROTOTYPE: $ |
860 | CODE: |
960 | CODE: |
861 | max_outstanding = maxreqs; |
961 | max_outstanding = maxreqs; |
862 | |
962 | |
863 | void |
963 | void |
… | |
… | |
903 | req->sv1 = newSVsv (fh); |
1003 | req->sv1 = newSVsv (fh); |
904 | req->int1 = fd; |
1004 | req->int1 = fd; |
905 | req->offs = offset; |
1005 | req->offs = offset; |
906 | req->size = nbytes; |
1006 | req->size = nbytes; |
907 | 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; |
908 | |
1025 | |
909 | REQ_SEND (req); |
1026 | REQ_SEND (req); |
910 | } |
1027 | } |
911 | |
1028 | |
912 | void |
1029 | void |
… | |
… | |
990 | } |
1107 | } |
991 | } |
1108 | } |
992 | |
1109 | |
993 | void |
1110 | void |
994 | 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 |
995 | PPCODE: |
1115 | PPCODE: |
996 | { |
1116 | { |
997 | SV *data; |
1117 | SV *data; |
998 | dREQ; |
1118 | dREQ; |
999 | |
1119 | |
1000 | req->type = EIO_READLINK; |
1120 | req->type = ix; |
1001 | req->sv1 = newSVsv (path); |
1121 | req->sv1 = newSVsv (path); |
1002 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1122 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1003 | |
1123 | |
1004 | REQ_SEND; |
1124 | REQ_SEND; |
1005 | } |
1125 | } |
… | |
… | |
1063 | } |
1183 | } |
1064 | |
1184 | |
1065 | REQ_SEND; |
1185 | REQ_SEND; |
1066 | } |
1186 | } |
1067 | |
1187 | |
|
|
1188 | UV |
|
|
1189 | major (UV dev) |
|
|
1190 | ALIAS: |
|
|
1191 | minor = 1 |
|
|
1192 | CODE: |
|
|
1193 | RETVAL = ix ? major (dev) : minor (dev); |
|
|
1194 | OUTPUT: |
|
|
1195 | RETVAL |
|
|
1196 | |
|
|
1197 | UV |
|
|
1198 | makedev (UV maj, UV min) |
|
|
1199 | CODE: |
|
|
1200 | RETVAL = makedev (maj, min); |
|
|
1201 | OUTPUT: |
|
|
1202 | RETVAL |
|
|
1203 | |
1068 | void |
1204 | void |
1069 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1205 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1070 | PPCODE: |
1206 | PPCODE: |
1071 | { |
1207 | { |
1072 | dREQ; |
1208 | dREQ; |