… | |
… | |
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 |
22 | # include <sys/mman.h> |
21 | # include <sys/mman.h> |
23 | #endif |
22 | #endif |
24 | |
23 | |
25 | /* perl namespace pollution */ |
24 | /* perl namespace pollution */ |
26 | #undef VERSION |
25 | #undef VERSION |
|
|
26 | |
|
|
27 | /* perl stupidly overrides readdir and maybe others */ |
|
|
28 | /* with thread-unsafe versions, imagine that :( */ |
|
|
29 | #undef readdir |
|
|
30 | #undef opendir |
|
|
31 | #undef closedir |
27 | |
32 | |
28 | #ifdef _WIN32 |
33 | #ifdef _WIN32 |
29 | |
34 | |
30 | # define EIO_STRUCT_DIRENT Direntry_t |
35 | # define EIO_STRUCT_DIRENT Direntry_t |
31 | # undef malloc |
36 | # undef malloc |
… | |
… | |
35 | # undef open |
40 | # undef open |
36 | # undef read |
41 | # undef read |
37 | # undef write |
42 | # undef write |
38 | # undef send |
43 | # undef send |
39 | # undef recv |
44 | # undef recv |
40 | # undef stat |
45 | # undef lstat |
41 | # undef fstat |
|
|
42 | # define lstat stat |
|
|
43 | # undef truncate |
46 | # undef truncate |
44 | # undef ftruncate |
47 | # undef ftruncate |
45 | # undef open |
48 | # undef open |
|
|
49 | # undef link |
46 | # undef close |
50 | # undef close |
47 | # undef unlink |
51 | # undef unlink |
|
|
52 | # undef mkdir |
48 | # undef rmdir |
53 | # undef rmdir |
49 | # undef rename |
54 | # undef rename |
50 | # undef lseek |
55 | # undef lseek |
|
|
56 | # undef opendir |
|
|
57 | # undef readdir |
|
|
58 | # undef closedir |
|
|
59 | # undef chmod |
|
|
60 | # undef fchmod |
51 | |
61 | |
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) |
62 | # define opendir(fd) EIO_ERRNO (ENOSYS, 0) |
62 | # define readdir(fd) (errno = ENOSYS, -1) |
63 | # define readdir(fd) EIO_ENOSYS () |
63 | # define closedir(fd) (errno = ENOSYS, -1) |
64 | # define closedir(fd) EIO_ENOSYS () |
64 | # define mkdir(a,b) mkdir (a) |
|
|
65 | |
65 | |
66 | #else |
66 | #else |
67 | |
67 | |
68 | # include <sys/time.h> |
68 | # include <sys/time.h> |
69 | # include <sys/select.h> |
69 | # include <sys/select.h> |
70 | # include <unistd.h> |
70 | # include <unistd.h> |
71 | # include <utime.h> |
71 | # include <utime.h> |
72 | # include <signal.h> |
72 | # include <signal.h> |
73 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
74 | |
73 | |
75 | #endif |
74 | #endif |
76 | |
|
|
77 | /* perl stupidly overrides readdir and maybe others */ |
|
|
78 | /* with thread-unsafe versions, imagine that :( */ |
|
|
79 | #undef readdir |
|
|
80 | #undef opendir |
|
|
81 | #undef closedir |
|
|
82 | |
75 | |
83 | #define EIO_STRUCT_STAT Stat_t |
76 | #define EIO_STRUCT_STAT Stat_t |
84 | |
77 | |
85 | /* use NV for 32 bit perls as it allows larger offsets */ |
78 | /* use NV for 32 bit perls as it allows larger offsets */ |
86 | #if IVSIZE >= 8 |
79 | #if IVSIZE >= 8 |
… | |
… | |
223 | #endif |
216 | #endif |
224 | #ifndef PROT_EXEC |
217 | #ifndef PROT_EXEC |
225 | # define PROT_EXEC 0 |
218 | # define PROT_EXEC 0 |
226 | #endif |
219 | #endif |
227 | |
220 | |
|
|
221 | #ifndef ST_RDONLY |
|
|
222 | # define ST_RDONLY 0 |
|
|
223 | #endif |
|
|
224 | #ifndef ST_NOSUID |
|
|
225 | # define ST_NOSUID 0 |
|
|
226 | #endif |
228 | #ifndef ST_NODEV |
227 | #ifndef ST_NODEV |
229 | # define ST_NODEV 0 |
228 | # define ST_NODEV 0 |
230 | #endif |
229 | #endif |
231 | #ifndef ST_NOEXEC |
230 | #ifndef ST_NOEXEC |
232 | # define ST_NOEXEC 0 |
231 | # define ST_NOEXEC 0 |
… | |
… | |
541 | case EIO_STATVFS: |
540 | case EIO_STATVFS: |
542 | case EIO_FSTATVFS: |
541 | case EIO_FSTATVFS: |
543 | { |
542 | { |
544 | SV *rv = &PL_sv_undef; |
543 | SV *rv = &PL_sv_undef; |
545 | |
544 | |
|
|
545 | #ifndef _WIN32 |
546 | if (req->result >= 0) |
546 | if (req->result >= 0) |
547 | { |
547 | { |
548 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
548 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
549 | HV *hv = newHV (); |
549 | HV *hv = newHV (); |
550 | |
550 | |
… | |
… | |
560 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
560 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
561 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
561 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
562 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
562 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
563 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
563 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
564 | } |
564 | } |
|
|
565 | #endif |
565 | |
566 | |
566 | PUSHs (rv); |
567 | PUSHs (rv); |
567 | } |
568 | } |
568 | |
569 | |
569 | break; |
570 | break; |
… | |
… | |
585 | case EIO_NOP: |
586 | case EIO_NOP: |
586 | case EIO_BUSY: |
587 | case EIO_BUSY: |
587 | break; |
588 | break; |
588 | |
589 | |
589 | case EIO_READLINK: |
590 | case EIO_READLINK: |
|
|
591 | case EIO_REALPATH: |
590 | if (req->result > 0) |
592 | if (req->result > 0) |
591 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
593 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
592 | break; |
594 | break; |
593 | |
595 | |
594 | case EIO_STAT: |
596 | case EIO_STAT: |
… | |
… | |
666 | grp->sv2 = 0; |
668 | grp->sv2 = 0; |
667 | |
669 | |
668 | eio_grp_cancel (grp); |
670 | eio_grp_cancel (grp); |
669 | } |
671 | } |
670 | |
672 | |
671 | static void |
|
|
672 | create_respipe (void) |
673 | static void create_respipe (void) |
673 | { |
674 | { |
674 | if (s_epipe_renew (&respipe)) |
675 | if (s_epipe_renew (&respipe)) |
675 | croak ("IO::AIO: unable to initialize result pipe"); |
676 | croak ("IO::AIO: unable to initialize result pipe"); |
676 | } |
677 | } |
677 | |
678 | |
… | |
… | |
731 | # define MAP_FIXED 0 |
732 | # define MAP_FIXED 0 |
732 | #endif |
733 | #endif |
733 | |
734 | |
734 | #define MMAP_MAGIC PERL_MAGIC_ext |
735 | #define MMAP_MAGIC PERL_MAGIC_ext |
735 | |
736 | |
736 | static int |
|
|
737 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
737 | static int mmap_free (pTHX_ SV *sv, MAGIC *mg) |
738 | { |
738 | { |
739 | int old_errno = errno; |
739 | int old_errno = errno; |
740 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
740 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
741 | errno = old_errno; |
741 | errno = old_errno; |
742 | |
742 | |
… | |
… | |
758 | 0, 0, 0, 0, mmap_free |
758 | 0, 0, 0, 0, mmap_free |
759 | }; |
759 | }; |
760 | |
760 | |
761 | /*****************************************************************************/ |
761 | /*****************************************************************************/ |
762 | |
762 | |
763 | static SV * |
|
|
764 | get_cb (SV *cb_sv) |
763 | static SV * get_cb (SV *cb_sv) |
765 | { |
764 | { |
766 | SvGETMAGIC (cb_sv); |
765 | SvGETMAGIC (cb_sv); |
767 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
766 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
768 | } |
767 | } |
769 | |
768 | |
… | |
… | |
893 | |
892 | |
894 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
893 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
895 | const_eio (SYNC_FILE_RANGE_WRITE) |
894 | const_eio (SYNC_FILE_RANGE_WRITE) |
896 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
895 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
897 | |
896 | |
|
|
897 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
898 | |
898 | const_eio (READDIR_DENTS) |
899 | const_eio (READDIR_DENTS) |
899 | const_eio (READDIR_DIRS_FIRST) |
900 | const_eio (READDIR_DIRS_FIRST) |
900 | const_eio (READDIR_STAT_ORDER) |
901 | const_eio (READDIR_STAT_ORDER) |
901 | const_eio (READDIR_FOUND_UNKNOWN) |
902 | const_eio (READDIR_FOUND_UNKNOWN) |
902 | |
903 | |
… | |
… | |
1019 | |
1020 | |
1020 | REQ_SEND (req); |
1021 | REQ_SEND (req); |
1021 | } |
1022 | } |
1022 | |
1023 | |
1023 | void |
1024 | void |
|
|
1025 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
|
|
1026 | PPCODE: |
|
|
1027 | { |
|
|
1028 | int fd = s_fileno_croak (fh, 0); |
|
|
1029 | dREQ; |
|
|
1030 | |
|
|
1031 | req->type = EIO_FALLOCATE; |
|
|
1032 | req->sv1 = newSVsv (fh); |
|
|
1033 | req->int1 = fd; |
|
|
1034 | req->int2 = mode; |
|
|
1035 | req->offs = offset; |
|
|
1036 | req->size = len; |
|
|
1037 | |
|
|
1038 | REQ_SEND (req); |
|
|
1039 | } |
|
|
1040 | |
|
|
1041 | void |
1024 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1042 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1025 | PPCODE: |
1043 | PPCODE: |
1026 | { |
1044 | { |
1027 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
1045 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
1028 | int fd = s_fileno_croak (fh, 0); |
1046 | int fd = s_fileno_croak (fh, 0); |
1029 | dREQ; |
1047 | dREQ; |
1030 | |
1048 | |
1031 | if (close_pipe < 0) |
1049 | if (expect_false (close_fd < 0)) |
1032 | { |
1050 | { |
|
|
1051 | #ifdef _WIN32 |
|
|
1052 | close_fd = _open_osfhandle (socket (AF_INET, SOCK_STREAM, 0), 0); |
|
|
1053 | #else |
1033 | int pipefd [2]; |
1054 | int pipefd [2]; |
1034 | |
1055 | |
1035 | if (pipe (pipefd) < 0 |
1056 | if (pipe (pipefd) < 0 |
1036 | || close (pipefd [1]) < 0 |
1057 | || close (pipefd [1]) < 0 |
1037 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1058 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1038 | abort (); /*D*/ |
1059 | abort (); /*D*/ |
1039 | |
1060 | |
1040 | close_pipe = pipefd [0]; |
1061 | close_fd = pipefd [0]; |
|
|
1062 | #endif |
1041 | } |
1063 | } |
1042 | |
1064 | |
1043 | req->type = EIO_DUP2; |
1065 | req->type = EIO_DUP2; |
1044 | req->int1 = close_pipe; |
1066 | req->int1 = close_fd; |
1045 | req->sv2 = newSVsv (fh); |
1067 | req->sv2 = newSVsv (fh); |
1046 | req->int2 = fd; |
1068 | req->int2 = fd; |
1047 | |
1069 | |
1048 | REQ_SEND (req); |
1070 | REQ_SEND (req); |
1049 | } |
1071 | } |
… | |
… | |
1101 | } |
1123 | } |
1102 | } |
1124 | } |
1103 | |
1125 | |
1104 | void |
1126 | void |
1105 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1127 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
|
|
1128 | ALIAS: |
|
|
1129 | aio_readlink = EIO_READLINK |
|
|
1130 | aio_realpath = EIO_REALPATH |
1106 | PPCODE: |
1131 | PPCODE: |
1107 | { |
1132 | { |
1108 | SV *data; |
1133 | SV *data; |
1109 | dREQ; |
1134 | dREQ; |
1110 | |
1135 | |
1111 | req->type = EIO_READLINK; |
1136 | req->type = ix; |
1112 | req->sv1 = newSVsv (path); |
1137 | req->sv1 = newSVsv (path); |
1113 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1138 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1114 | |
1139 | |
1115 | REQ_SEND; |
1140 | REQ_SEND; |
1116 | } |
1141 | } |