… | |
… | |
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; |
… | |
… | |
667 | grp->sv2 = 0; |
668 | grp->sv2 = 0; |
668 | |
669 | |
669 | eio_grp_cancel (grp); |
670 | eio_grp_cancel (grp); |
670 | } |
671 | } |
671 | |
672 | |
672 | static void |
|
|
673 | create_respipe (void) |
673 | static void create_respipe (void) |
674 | { |
674 | { |
675 | if (s_epipe_renew (&respipe)) |
675 | if (s_epipe_renew (&respipe)) |
676 | croak ("IO::AIO: unable to initialize result pipe"); |
676 | croak ("IO::AIO: unable to initialize result pipe"); |
677 | } |
677 | } |
678 | |
678 | |
… | |
… | |
732 | # define MAP_FIXED 0 |
732 | # define MAP_FIXED 0 |
733 | #endif |
733 | #endif |
734 | |
734 | |
735 | #define MMAP_MAGIC PERL_MAGIC_ext |
735 | #define MMAP_MAGIC PERL_MAGIC_ext |
736 | |
736 | |
737 | static int |
|
|
738 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
737 | static int mmap_free (pTHX_ SV *sv, MAGIC *mg) |
739 | { |
738 | { |
740 | int old_errno = errno; |
739 | int old_errno = errno; |
741 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
740 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
742 | errno = old_errno; |
741 | errno = old_errno; |
743 | |
742 | |
… | |
… | |
759 | 0, 0, 0, 0, mmap_free |
758 | 0, 0, 0, 0, mmap_free |
760 | }; |
759 | }; |
761 | |
760 | |
762 | /*****************************************************************************/ |
761 | /*****************************************************************************/ |
763 | |
762 | |
764 | static SV * |
|
|
765 | get_cb (SV *cb_sv) |
763 | static SV * get_cb (SV *cb_sv) |
766 | { |
764 | { |
767 | SvGETMAGIC (cb_sv); |
765 | SvGETMAGIC (cb_sv); |
768 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
766 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
769 | } |
767 | } |
770 | |
768 | |
… | |
… | |
894 | |
892 | |
895 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
893 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
896 | const_eio (SYNC_FILE_RANGE_WRITE) |
894 | const_eio (SYNC_FILE_RANGE_WRITE) |
897 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
895 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
898 | |
896 | |
|
|
897 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
898 | |
899 | const_eio (READDIR_DENTS) |
899 | const_eio (READDIR_DENTS) |
900 | const_eio (READDIR_DIRS_FIRST) |
900 | const_eio (READDIR_DIRS_FIRST) |
901 | const_eio (READDIR_STAT_ORDER) |
901 | const_eio (READDIR_STAT_ORDER) |
902 | const_eio (READDIR_FOUND_UNKNOWN) |
902 | const_eio (READDIR_FOUND_UNKNOWN) |
903 | |
903 | |
… | |
… | |
1020 | |
1020 | |
1021 | REQ_SEND (req); |
1021 | REQ_SEND (req); |
1022 | } |
1022 | } |
1023 | |
1023 | |
1024 | 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 |
1025 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1042 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1026 | PPCODE: |
1043 | PPCODE: |
1027 | { |
1044 | { |
1028 | 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 */ |
1029 | int fd = s_fileno_croak (fh, 0); |
1046 | int fd = s_fileno_croak (fh, 0); |
1030 | dREQ; |
1047 | dREQ; |
1031 | |
1048 | |
1032 | if (close_pipe < 0) |
1049 | if (expect_false (close_fd < 0)) |
1033 | { |
1050 | { |
|
|
1051 | #ifdef _WIN32 |
|
|
1052 | close_fd = _open_osfhandle (socket (AF_INET, SOCK_STREAM, 0), 0); |
|
|
1053 | #else |
1034 | int pipefd [2]; |
1054 | int pipefd [2]; |
1035 | |
1055 | |
1036 | if (pipe (pipefd) < 0 |
1056 | if (pipe (pipefd) < 0 |
1037 | || close (pipefd [1]) < 0 |
1057 | || close (pipefd [1]) < 0 |
1038 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1058 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1039 | abort (); /*D*/ |
1059 | abort (); /*D*/ |
1040 | |
1060 | |
1041 | close_pipe = pipefd [0]; |
1061 | close_fd = pipefd [0]; |
|
|
1062 | #endif |
1042 | } |
1063 | } |
1043 | |
1064 | |
1044 | req->type = EIO_DUP2; |
1065 | req->type = EIO_DUP2; |
1045 | req->int1 = close_pipe; |
1066 | req->int1 = close_fd; |
1046 | req->sv2 = newSVsv (fh); |
1067 | req->sv2 = newSVsv (fh); |
1047 | req->int2 = fd; |
1068 | req->int2 = fd; |
1048 | |
1069 | |
1049 | REQ_SEND (req); |
1070 | REQ_SEND (req); |
1050 | } |
1071 | } |