… | |
… | |
16 | #include <sys/statvfs.h> |
16 | #include <sys/statvfs.h> |
17 | #include <limits.h> |
17 | #include <limits.h> |
18 | #include <fcntl.h> |
18 | #include <fcntl.h> |
19 | #include <sched.h> |
19 | #include <sched.h> |
20 | |
20 | |
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
21 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
22 | # include <sys/mman.h> |
22 | # include <sys/mman.h> |
23 | #endif |
23 | #endif |
24 | |
24 | |
25 | /* perl namespace pollution */ |
25 | /* perl namespace pollution */ |
26 | #undef VERSION |
26 | #undef VERSION |
… | |
… | |
118 | STRLEN stroffset; \ |
118 | STRLEN stroffset; \ |
119 | SV *self; |
119 | SV *self; |
120 | |
120 | |
121 | #define EIO_NO_WRAPPERS 1 |
121 | #define EIO_NO_WRAPPERS 1 |
122 | |
122 | |
|
|
123 | #include "libeio/config.h" |
123 | #include "libeio/eio.h" |
124 | #include "libeio/eio.h" |
124 | |
125 | |
125 | #ifndef POSIX_FADV_NORMAL |
126 | #ifndef POSIX_FADV_NORMAL |
126 | # define POSIX_FADV_NORMAL 0 |
127 | # define POSIX_FADV_NORMAL 0 |
127 | # define NO_FADVISE 1 |
|
|
128 | #endif |
128 | #endif |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
131 | #endif |
131 | #endif |
132 | #ifndef POSIX_FADV_RANDOM |
132 | #ifndef POSIX_FADV_RANDOM |
… | |
… | |
140 | #endif |
140 | #endif |
141 | #ifndef POSIX_FADV_DONTNEED |
141 | #ifndef POSIX_FADV_DONTNEED |
142 | # define POSIX_FADV_DONTNEED 0 |
142 | # define POSIX_FADV_DONTNEED 0 |
143 | #endif |
143 | #endif |
144 | |
144 | |
|
|
145 | #if !HAVE_POSIX_FADVISE |
|
|
146 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
|
|
147 | #endif |
|
|
148 | |
|
|
149 | #ifndef POSIX_MADV_NORMAL |
|
|
150 | # define POSIX_MADV_NORMAL 0 |
|
|
151 | #endif |
|
|
152 | #ifndef POSIX_MADV_SEQUENTIAL |
|
|
153 | # define POSIX_MADV_SEQUENTIAL 0 |
|
|
154 | #endif |
|
|
155 | #ifndef POSIX_MADV_RANDOM |
|
|
156 | # define POSIX_MADV_RANDOM 0 |
|
|
157 | #endif |
|
|
158 | #ifndef POSIX_MADV_WILLNEED |
|
|
159 | # define POSIX_MADV_WILLNEED 0 |
|
|
160 | #endif |
|
|
161 | #ifndef POSIX_MADV_DONTNEED |
|
|
162 | # define POSIX_MADV_DONTNEED 0 |
|
|
163 | #endif |
|
|
164 | |
|
|
165 | #if !HAVE_POSIX_MADVISE |
|
|
166 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
|
|
167 | #endif |
|
|
168 | |
|
|
169 | #ifndef PROT_NONE |
|
|
170 | # define PROT_NONE 0 |
|
|
171 | #endif |
|
|
172 | #ifndef PROT_READ |
|
|
173 | # define PROT_READ 0 |
|
|
174 | #endif |
|
|
175 | #ifndef PROT_WRITE |
|
|
176 | # define PROT_READ 0 |
|
|
177 | #endif |
|
|
178 | #ifndef PROT_EXEC |
|
|
179 | # define PROT_EXEC 0 |
|
|
180 | #endif |
|
|
181 | |
145 | #ifndef ST_NODEV |
182 | #ifndef ST_NODEV |
146 | # define ST_NODEV 0 |
183 | # define ST_NODEV 0 |
147 | #endif |
184 | #endif |
148 | #ifndef ST_NOEXEC |
185 | #ifndef ST_NOEXEC |
149 | # define ST_NOEXEC 0 |
186 | # define ST_NOEXEC 0 |
… | |
… | |
171 | #endif |
208 | #endif |
172 | #ifndef ST_RELATIME |
209 | #ifndef ST_RELATIME |
173 | # define ST_RELATIME 0 |
210 | # define ST_RELATIME 0 |
174 | #endif |
211 | #endif |
175 | |
212 | |
176 | #ifndef MCL_CURRENT |
213 | #ifndef S_IFIFO |
177 | # define MCL_CURRENT 0 |
214 | # define S_IFIFO 0 |
178 | #endif |
215 | #endif |
179 | #ifndef MCL_FUTURE |
216 | #ifndef S_IFCHR |
180 | # define MCL_FUTURE 0 |
217 | # define S_IFCHR 0 |
|
|
218 | #endif |
|
|
219 | #ifndef S_IFBLK |
|
|
220 | # define S_IFBLK 0 |
|
|
221 | #endif |
|
|
222 | #ifndef S_IFLNK |
|
|
223 | # define S_IFLNK 0 |
|
|
224 | #endif |
|
|
225 | #ifndef S_IFREG |
|
|
226 | # define S_IFREG 0 |
|
|
227 | #endif |
|
|
228 | #ifndef S_IFDIR |
|
|
229 | # define S_IFDIR 0 |
|
|
230 | #endif |
|
|
231 | #ifndef S_IFWHT |
|
|
232 | # define S_IFWHT 0 |
|
|
233 | #endif |
|
|
234 | #ifndef S_IFSOCK |
|
|
235 | # define S_IFSOCK 0 |
181 | #endif |
236 | #endif |
182 | |
237 | |
183 | #ifndef MAP_ANONYMOUS |
238 | #ifndef MAP_ANONYMOUS |
184 | # ifdef MAP_ANON |
239 | # ifdef MAP_ANON |
185 | # define MAP_ANONYMOUS MAP_ANON |
240 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
199 | #ifndef MAP_POPULATE |
254 | #ifndef MAP_POPULATE |
200 | # define MAP_POPULATE 0 |
255 | # define MAP_POPULATE 0 |
201 | #endif |
256 | #endif |
202 | #ifndef MAP_NONBLOCK |
257 | #ifndef MAP_NONBLOCK |
203 | # define MAP_NONBLOCK 0 |
258 | # define MAP_NONBLOCK 0 |
|
|
259 | #endif |
|
|
260 | |
|
|
261 | #ifndef makedev |
|
|
262 | # define makedev(maj,min) (((maj) << 8) | (min)) |
|
|
263 | #endif |
|
|
264 | #ifndef major |
|
|
265 | # define major(dev) ((dev) >> 8) |
|
|
266 | #endif |
|
|
267 | #ifndef minor |
|
|
268 | # define minor(dev) ((dev) & 0xff) |
204 | #endif |
269 | #endif |
205 | |
270 | |
206 | #ifndef PAGESIZE |
271 | #ifndef PAGESIZE |
207 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
272 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
208 | #endif |
273 | #endif |
… | |
… | |
323 | /* do not recreate the result IV from scratch each time */ |
388 | /* do not recreate the result IV from scratch each time */ |
324 | if (expect_true (sv_result_cache)) |
389 | if (expect_true (sv_result_cache)) |
325 | { |
390 | { |
326 | sv_result = sv_result_cache; sv_result_cache = 0; |
391 | sv_result = sv_result_cache; sv_result_cache = 0; |
327 | SvIV_set (sv_result, req->result); |
392 | SvIV_set (sv_result, req->result); |
|
|
393 | SvIOK_only (sv_result); |
328 | } |
394 | } |
329 | else |
395 | else |
330 | { |
396 | { |
331 | sv_result = newSViv (req->result); |
397 | sv_result = newSViv (req->result); |
332 | SvREADONLY_on (sv_result); |
398 | SvREADONLY_on (sv_result); |
… | |
… | |
496 | SvSETMAGIC (req->sv2); |
562 | SvSETMAGIC (req->sv2); |
497 | PUSHs (sv_result); |
563 | PUSHs (sv_result); |
498 | } |
564 | } |
499 | break; |
565 | break; |
500 | |
566 | |
501 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
567 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
502 | if (req->result > 0) |
568 | if (req->result > 0) |
503 | SvIV_set (sv_result, 0); |
569 | SvIV_set (sv_result, 0); |
504 | /* FALLTHROUGH */ |
570 | /* FALLTHROUGH */ |
505 | |
571 | |
506 | default: |
572 | default: |
… | |
… | |
606 | /*****************************************************************************/ |
672 | /*****************************************************************************/ |
607 | |
673 | |
608 | #if !_POSIX_MAPPED_FILES |
674 | #if !_POSIX_MAPPED_FILES |
609 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
675 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
610 | # define munmap(addr,length) (errno = ENOSYS, -1) |
676 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
677 | #endif |
|
|
678 | |
|
|
679 | #if !_POSIX_MEMORY_PROTECTION |
|
|
680 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
681 | # define PROT_NONE 0 |
|
|
682 | # define PROT_WRITE 0 |
|
|
683 | # define MAP_PRIVATE 0 |
|
|
684 | # define MAP_SHARED 0 |
|
|
685 | # define MAP_FIXED 0 |
611 | #endif |
686 | #endif |
612 | |
687 | |
613 | #define MMAP_MAGIC PERL_MAGIC_ext |
688 | #define MMAP_MAGIC PERL_MAGIC_ext |
614 | |
689 | |
615 | static int |
690 | static int |
… | |
… | |
689 | const_iv (O_RDWR) |
764 | const_iv (O_RDWR) |
690 | const_iv (O_CREAT) |
765 | const_iv (O_CREAT) |
691 | const_iv (O_TRUNC) |
766 | const_iv (O_TRUNC) |
692 | const_iv (O_EXCL) |
767 | const_iv (O_EXCL) |
693 | const_iv (O_APPEND) |
768 | const_iv (O_APPEND) |
694 | #ifndef _WIN32 |
769 | |
695 | const_iv (S_IFIFO) |
770 | const_iv (S_IFIFO) |
696 | #endif |
771 | const_iv (S_IFCHR) |
|
|
772 | const_iv (S_IFBLK) |
|
|
773 | const_iv (S_IFLNK) |
|
|
774 | const_iv (S_IFREG) |
|
|
775 | const_iv (S_IFDIR) |
|
|
776 | const_iv (S_IFWHT) |
|
|
777 | const_iv (S_IFSOCK) |
|
|
778 | const_iv (S_IFMT) |
|
|
779 | |
697 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
780 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
698 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
781 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
699 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
782 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
700 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
783 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
701 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
784 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
702 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
785 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
|
|
786 | |
|
|
787 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
788 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
789 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
790 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
791 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
703 | |
792 | |
704 | const_iv (ST_RDONLY) |
793 | const_iv (ST_RDONLY) |
705 | const_iv (ST_NOSUID) |
794 | const_iv (ST_NOSUID) |
706 | const_iv (ST_NODEV) |
795 | const_iv (ST_NODEV) |
707 | const_iv (ST_NOEXEC) |
796 | const_iv (ST_NOEXEC) |
… | |
… | |
712 | const_iv (ST_IMMUTABLE) |
801 | const_iv (ST_IMMUTABLE) |
713 | const_iv (ST_NOATIME) |
802 | const_iv (ST_NOATIME) |
714 | const_iv (ST_NODIRATIME) |
803 | const_iv (ST_NODIRATIME) |
715 | const_iv (ST_RELATIME) |
804 | const_iv (ST_RELATIME) |
716 | |
805 | |
|
|
806 | const_iv (PROT_NONE) |
717 | const_iv (PROT_EXEC) |
807 | const_iv (PROT_EXEC) |
718 | const_iv (PROT_NONE) |
|
|
719 | const_iv (PROT_READ) |
808 | const_iv (PROT_READ) |
720 | const_iv (PROT_WRITE) |
809 | const_iv (PROT_WRITE) |
721 | |
810 | |
722 | /*const_iv (MAP_FIXED)*/ |
811 | /*const_iv (MAP_FIXED)*/ |
723 | const_iv (MAP_PRIVATE) |
812 | const_iv (MAP_PRIVATE) |
… | |
… | |
729 | const_iv (MAP_LOCKED) |
818 | const_iv (MAP_LOCKED) |
730 | const_iv (MAP_NORESERVE) |
819 | const_iv (MAP_NORESERVE) |
731 | const_iv (MAP_POPULATE) |
820 | const_iv (MAP_POPULATE) |
732 | const_iv (MAP_NONBLOCK) |
821 | const_iv (MAP_NONBLOCK) |
733 | |
822 | |
734 | const_iv (MCL_FUTURE) |
823 | const_eio (MCL_FUTURE) |
735 | const_iv (MCL_CURRENT) |
824 | const_eio (MCL_CURRENT) |
736 | |
825 | |
737 | const_eio (MS_ASYNC) |
826 | const_eio (MS_ASYNC) |
738 | const_eio (MS_INVALIDATE) |
827 | const_eio (MS_INVALIDATE) |
739 | const_eio (MS_SYNC) |
828 | const_eio (MS_SYNC) |
740 | |
829 | |
… | |
… | |
814 | CODE: |
903 | CODE: |
815 | max_outstanding = maxreqs; |
904 | max_outstanding = maxreqs; |
816 | |
905 | |
817 | void |
906 | void |
818 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
907 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
819 | PROTOTYPE: $$$;$ |
|
|
820 | PPCODE: |
908 | PPCODE: |
821 | { |
909 | { |
822 | dREQ; |
910 | dREQ; |
823 | |
911 | |
824 | req->type = EIO_OPEN; |
912 | req->type = EIO_OPEN; |
… | |
… | |
830 | REQ_SEND; |
918 | REQ_SEND; |
831 | } |
919 | } |
832 | |
920 | |
833 | void |
921 | void |
834 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
922 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
835 | PROTOTYPE: $;$ |
|
|
836 | ALIAS: |
923 | ALIAS: |
837 | aio_fsync = EIO_FSYNC |
924 | aio_fsync = EIO_FSYNC |
838 | aio_fdatasync = EIO_FDATASYNC |
925 | aio_fdatasync = EIO_FDATASYNC |
839 | PPCODE: |
926 | PPCODE: |
840 | { |
927 | { |
… | |
… | |
848 | REQ_SEND (req); |
935 | REQ_SEND (req); |
849 | } |
936 | } |
850 | |
937 | |
851 | void |
938 | void |
852 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
939 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
853 | PROTOTYPE: $$$$;$ |
|
|
854 | PPCODE: |
940 | PPCODE: |
855 | { |
941 | { |
856 | int fd = s_fileno_croak (fh, 0); |
942 | int fd = s_fileno_croak (fh, 0); |
857 | dREQ; |
943 | dREQ; |
858 | |
944 | |
… | |
… | |
866 | REQ_SEND (req); |
952 | REQ_SEND (req); |
867 | } |
953 | } |
868 | |
954 | |
869 | void |
955 | void |
870 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
956 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
871 | PROTOTYPE: $;$ |
|
|
872 | PPCODE: |
957 | PPCODE: |
873 | { |
958 | { |
874 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
959 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
875 | int fd = s_fileno_croak (fh, 0); |
960 | int fd = s_fileno_croak (fh, 0); |
876 | dREQ; |
961 | dREQ; |
… | |
… | |
898 | void |
983 | void |
899 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
984 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
900 | ALIAS: |
985 | ALIAS: |
901 | aio_read = EIO_READ |
986 | aio_read = EIO_READ |
902 | aio_write = EIO_WRITE |
987 | aio_write = EIO_WRITE |
903 | PROTOTYPE: $$$$$;$ |
|
|
904 | PPCODE: |
988 | PPCODE: |
905 | { |
989 | { |
906 | STRLEN svlen; |
990 | STRLEN svlen; |
907 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
991 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
908 | char *svptr = SvPVbyte (data, svlen); |
992 | char *svptr = SvPVbyte (data, svlen); |
… | |
… | |
949 | } |
1033 | } |
950 | } |
1034 | } |
951 | |
1035 | |
952 | void |
1036 | void |
953 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1037 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
954 | PROTOTYPE: $$;$ |
|
|
955 | PPCODE: |
1038 | PPCODE: |
956 | { |
1039 | { |
957 | SV *data; |
1040 | SV *data; |
958 | dREQ; |
1041 | dREQ; |
959 | |
1042 | |
… | |
… | |
964 | REQ_SEND; |
1047 | REQ_SEND; |
965 | } |
1048 | } |
966 | |
1049 | |
967 | void |
1050 | void |
968 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1051 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
969 | PROTOTYPE: $$$$;$ |
|
|
970 | PPCODE: |
1052 | PPCODE: |
971 | { |
1053 | { |
972 | int ifd = s_fileno_croak (in_fh , 0); |
1054 | int ifd = s_fileno_croak (in_fh , 0); |
973 | int ofd = s_fileno_croak (out_fh, 1); |
1055 | int ofd = s_fileno_croak (out_fh, 1); |
974 | dREQ; |
1056 | dREQ; |
… | |
… | |
984 | REQ_SEND; |
1066 | REQ_SEND; |
985 | } |
1067 | } |
986 | |
1068 | |
987 | void |
1069 | void |
988 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1070 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
989 | PROTOTYPE: $$$;$ |
|
|
990 | PPCODE: |
1071 | PPCODE: |
991 | { |
1072 | { |
992 | int fd = s_fileno_croak (fh, 0); |
1073 | int fd = s_fileno_croak (fh, 0); |
993 | dREQ; |
1074 | dREQ; |
994 | |
1075 | |
… | |
… | |
1025 | } |
1106 | } |
1026 | |
1107 | |
1027 | REQ_SEND; |
1108 | REQ_SEND; |
1028 | } |
1109 | } |
1029 | |
1110 | |
|
|
1111 | UV |
|
|
1112 | major (UV dev) |
|
|
1113 | ALIAS: |
|
|
1114 | minor = 1 |
|
|
1115 | CODE: |
|
|
1116 | RETVAL = ix ? major (dev) : minor (dev); |
|
|
1117 | OUTPUT: |
|
|
1118 | RETVAL |
|
|
1119 | |
|
|
1120 | UV |
|
|
1121 | makedev (UV maj, UV min) |
|
|
1122 | CODE: |
|
|
1123 | RETVAL = makedev (maj, min); |
|
|
1124 | OUTPUT: |
|
|
1125 | RETVAL |
|
|
1126 | |
1030 | void |
1127 | void |
1031 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1128 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1032 | PPCODE: |
1129 | PPCODE: |
1033 | { |
1130 | { |
1034 | dREQ; |
1131 | dREQ; |
… | |
… | |
1195 | void |
1292 | void |
1196 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1293 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1197 | ALIAS: |
1294 | ALIAS: |
1198 | aio_mtouch = EIO_MTOUCH |
1295 | aio_mtouch = EIO_MTOUCH |
1199 | aio_msync = EIO_MSYNC |
1296 | aio_msync = EIO_MSYNC |
1200 | PROTOTYPE: $$$$;$ |
|
|
1201 | PPCODE: |
1297 | PPCODE: |
1202 | { |
1298 | { |
1203 | STRLEN svlen; |
1299 | STRLEN svlen; |
|
|
1300 | char *svptr = SvPVbyte (data, svlen); |
1204 | UV len = SvUV (length); |
1301 | UV len = SvUV (length); |
1205 | char *svptr = SvPVbyte (data, svlen); |
|
|
1206 | |
1302 | |
1207 | if (offset < 0) |
1303 | if (offset < 0) |
1208 | offset += svlen; |
1304 | offset += svlen; |
1209 | |
1305 | |
1210 | if (offset < 0 || offset > svlen) |
1306 | if (offset < 0 || offset > svlen) |
… | |
… | |
1215 | |
1311 | |
1216 | { |
1312 | { |
1217 | dREQ; |
1313 | dREQ; |
1218 | |
1314 | |
1219 | req->type = ix; |
1315 | req->type = ix; |
1220 | req->size = len; |
|
|
1221 | req->sv2 = SvREFCNT_inc (data); |
1316 | req->sv2 = SvREFCNT_inc (data); |
1222 | req->ptr2 = (char *)svptr + offset; |
1317 | req->ptr2 = (char *)svptr + offset; |
|
|
1318 | req->size = len; |
1223 | req->int1 = flags; |
1319 | req->int1 = flags; |
1224 | |
1320 | |
1225 | REQ_SEND; |
1321 | REQ_SEND; |
1226 | } |
1322 | } |
1227 | } |
1323 | } |
1228 | |
1324 | |
1229 | void |
1325 | void |
|
|
1326 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1327 | PPCODE: |
|
|
1328 | { |
|
|
1329 | STRLEN svlen; |
|
|
1330 | char *svptr = SvPVbyte (data, svlen); |
|
|
1331 | UV len = SvUV (length); |
|
|
1332 | |
|
|
1333 | if (offset < 0) |
|
|
1334 | offset += svlen; |
|
|
1335 | |
|
|
1336 | if (offset < 0 || offset > svlen) |
|
|
1337 | croak ("offset outside of scalar"); |
|
|
1338 | |
|
|
1339 | if (!SvOK (length) || len + offset > svlen) |
|
|
1340 | len = svlen - offset; |
|
|
1341 | |
|
|
1342 | { |
|
|
1343 | dREQ; |
|
|
1344 | |
|
|
1345 | req->type = EIO_MLOCK; |
|
|
1346 | req->sv2 = SvREFCNT_inc (data); |
|
|
1347 | req->ptr2 = (char *)svptr + offset; |
|
|
1348 | req->size = len; |
|
|
1349 | |
|
|
1350 | REQ_SEND; |
|
|
1351 | } |
|
|
1352 | } |
|
|
1353 | |
|
|
1354 | void |
|
|
1355 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1356 | PPCODE: |
|
|
1357 | { |
|
|
1358 | dREQ; |
|
|
1359 | |
|
|
1360 | req->type = EIO_MLOCKALL; |
|
|
1361 | req->int1 = flags; |
|
|
1362 | |
|
|
1363 | REQ_SEND; |
|
|
1364 | } |
|
|
1365 | |
|
|
1366 | void |
1230 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1367 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1231 | PPCODE: |
1368 | PPCODE: |
1232 | { |
1369 | { |
1233 | dREQ; |
1370 | dREQ; |
1234 | |
1371 | |
… | |
… | |
1238 | REQ_SEND; |
1375 | REQ_SEND; |
1239 | } |
1376 | } |
1240 | |
1377 | |
1241 | void |
1378 | void |
1242 | aio_group (SV *callback=&PL_sv_undef) |
1379 | aio_group (SV *callback=&PL_sv_undef) |
1243 | PROTOTYPE: ;$ |
|
|
1244 | PPCODE: |
1380 | PPCODE: |
1245 | { |
1381 | { |
1246 | dREQ; |
1382 | dREQ; |
1247 | |
1383 | |
1248 | req->type = EIO_GROUP; |
1384 | req->type = EIO_GROUP; |
… | |
… | |
1265 | REQ_SEND; |
1401 | REQ_SEND; |
1266 | } |
1402 | } |
1267 | |
1403 | |
1268 | int |
1404 | int |
1269 | aioreq_pri (int pri = 0) |
1405 | aioreq_pri (int pri = 0) |
1270 | PROTOTYPE: ;$ |
|
|
1271 | CODE: |
1406 | CODE: |
1272 | RETVAL = next_pri; |
1407 | RETVAL = next_pri; |
1273 | if (items > 0) |
1408 | if (items > 0) |
1274 | { |
1409 | { |
1275 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1410 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1287 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1422 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1288 | next_pri = nice; |
1423 | next_pri = nice; |
1289 | |
1424 | |
1290 | void |
1425 | void |
1291 | flush () |
1426 | flush () |
1292 | PROTOTYPE: |
|
|
1293 | CODE: |
1427 | CODE: |
1294 | while (eio_nreqs ()) |
1428 | while (eio_nreqs ()) |
1295 | { |
1429 | { |
1296 | poll_wait (); |
1430 | poll_wait (); |
1297 | poll_cb (); |
1431 | poll_cb (); |
1298 | } |
1432 | } |
1299 | |
1433 | |
1300 | int |
1434 | int |
1301 | poll() |
1435 | poll () |
1302 | PROTOTYPE: |
|
|
1303 | CODE: |
1436 | CODE: |
1304 | poll_wait (); |
1437 | poll_wait (); |
1305 | RETVAL = poll_cb (); |
1438 | RETVAL = poll_cb (); |
1306 | OUTPUT: |
1439 | OUTPUT: |
1307 | RETVAL |
1440 | RETVAL |
1308 | |
1441 | |
1309 | int |
1442 | int |
1310 | poll_fileno() |
1443 | poll_fileno () |
1311 | PROTOTYPE: |
|
|
1312 | CODE: |
1444 | CODE: |
1313 | RETVAL = s_epipe_fd (&respipe); |
1445 | RETVAL = s_epipe_fd (&respipe); |
1314 | OUTPUT: |
1446 | OUTPUT: |
1315 | RETVAL |
1447 | RETVAL |
1316 | |
1448 | |
1317 | int |
1449 | int |
1318 | poll_cb(...) |
1450 | poll_cb (...) |
1319 | PROTOTYPE: |
1451 | PROTOTYPE: |
1320 | CODE: |
1452 | CODE: |
1321 | RETVAL = poll_cb (); |
1453 | RETVAL = poll_cb (); |
1322 | OUTPUT: |
1454 | OUTPUT: |
1323 | RETVAL |
1455 | RETVAL |
1324 | |
1456 | |
1325 | void |
1457 | void |
1326 | poll_wait() |
1458 | poll_wait () |
1327 | PROTOTYPE: |
|
|
1328 | CODE: |
1459 | CODE: |
1329 | poll_wait (); |
1460 | poll_wait (); |
1330 | |
1461 | |
1331 | int |
1462 | int |
1332 | nreqs() |
1463 | nreqs () |
1333 | PROTOTYPE: |
|
|
1334 | CODE: |
1464 | CODE: |
1335 | RETVAL = eio_nreqs (); |
1465 | RETVAL = eio_nreqs (); |
1336 | OUTPUT: |
1466 | OUTPUT: |
1337 | RETVAL |
1467 | RETVAL |
1338 | |
1468 | |
1339 | int |
1469 | int |
1340 | nready() |
1470 | nready () |
1341 | PROTOTYPE: |
|
|
1342 | CODE: |
1471 | CODE: |
1343 | RETVAL = eio_nready (); |
1472 | RETVAL = eio_nready (); |
1344 | OUTPUT: |
1473 | OUTPUT: |
1345 | RETVAL |
1474 | RETVAL |
1346 | |
1475 | |
1347 | int |
1476 | int |
1348 | npending() |
1477 | npending () |
1349 | PROTOTYPE: |
|
|
1350 | CODE: |
1478 | CODE: |
1351 | RETVAL = eio_npending (); |
1479 | RETVAL = eio_npending (); |
1352 | OUTPUT: |
1480 | OUTPUT: |
1353 | RETVAL |
1481 | RETVAL |
1354 | |
1482 | |
1355 | int |
1483 | int |
1356 | nthreads() |
1484 | nthreads () |
1357 | PROTOTYPE: |
|
|
1358 | CODE: |
1485 | CODE: |
1359 | RETVAL = eio_nthreads (); |
1486 | RETVAL = eio_nthreads (); |
1360 | OUTPUT: |
1487 | OUTPUT: |
1361 | RETVAL |
1488 | RETVAL |
1362 | |
1489 | |
1363 | int |
1490 | int |
1364 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1491 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1365 | PROTOTYPE: $$$$ |
|
|
1366 | CODE: |
1492 | CODE: |
1367 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1368 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1493 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1369 | #else |
|
|
1370 | RETVAL = errno = ENOSYS; /* yes, this is actually correct */ |
|
|
1371 | #endif |
|
|
1372 | OUTPUT: |
1494 | OUTPUT: |
1373 | RETVAL |
1495 | RETVAL |
1374 | |
1496 | |
1375 | ssize_t |
1497 | ssize_t |
1376 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1498 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1377 | PROTOTYPE: $$$$ |
|
|
1378 | CODE: |
1499 | CODE: |
1379 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1500 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1380 | OUTPUT: |
1501 | OUTPUT: |
1381 | RETVAL |
1502 | RETVAL |
1382 | |
1503 | |
1383 | void |
1504 | void |
1384 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1505 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1385 | PROTOTYPE: $$$$$;$ |
|
|
1386 | PPCODE: |
1506 | PPCODE: |
1387 | sv_unmagic (scalar, MMAP_MAGIC); |
1507 | sv_unmagic (scalar, MMAP_MAGIC); |
1388 | { |
1508 | { |
1389 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1509 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1390 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1510 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
… | |
… | |
1413 | XSRETURN_YES; |
1533 | XSRETURN_YES; |
1414 | } |
1534 | } |
1415 | |
1535 | |
1416 | void |
1536 | void |
1417 | munmap (SV *scalar) |
1537 | munmap (SV *scalar) |
1418 | PROTOTYPE: $ |
|
|
1419 | CODE: |
1538 | CODE: |
1420 | sv_unmagic (scalar, MMAP_MAGIC); |
1539 | sv_unmagic (scalar, MMAP_MAGIC); |
1421 | |
1540 | |
1422 | int |
1541 | int |
1423 | mlockall (int flags) |
1542 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
1424 | PROTOTYPE: $ |
1543 | ALIAS: |
|
|
1544 | mprotect = 1 |
1425 | CODE: |
1545 | CODE: |
|
|
1546 | { |
|
|
1547 | STRLEN svlen; |
|
|
1548 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1549 | size_t len = SvUV (length); |
|
|
1550 | |
|
|
1551 | if (offset < 0) |
|
|
1552 | offset += svlen; |
|
|
1553 | |
|
|
1554 | if (offset < 0 || offset > svlen) |
|
|
1555 | croak ("offset outside of scalar"); |
|
|
1556 | |
|
|
1557 | if (!SvOK (length) || len + offset > svlen) |
|
|
1558 | len = svlen - offset; |
|
|
1559 | |
|
|
1560 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1561 | eio_page_align (&addr, &len); |
|
|
1562 | |
|
|
1563 | switch (ix) |
|
|
1564 | { |
|
|
1565 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
|
|
1566 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
|
|
1567 | } |
|
|
1568 | } |
|
|
1569 | OUTPUT: |
|
|
1570 | RETVAL |
|
|
1571 | |
|
|
1572 | int |
|
|
1573 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
|
|
1574 | CODE: |
|
|
1575 | { |
|
|
1576 | STRLEN svlen; |
|
|
1577 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1578 | size_t len = SvUV (length); |
|
|
1579 | |
|
|
1580 | if (offset < 0) |
|
|
1581 | offset += svlen; |
|
|
1582 | |
|
|
1583 | if (offset < 0 || offset > svlen) |
|
|
1584 | croak ("offset outside of scalar"); |
|
|
1585 | |
|
|
1586 | if (!SvOK (length) || len + offset > svlen) |
|
|
1587 | len = svlen - offset; |
|
|
1588 | |
|
|
1589 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1590 | eio_page_align (&addr, &len); |
1426 | #if _POSIX_MEMLOCK |
1591 | #if _POSIX_MEMLOCK_RANGE |
1427 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
1592 | RETVAL = munlock (addr, len); |
1428 | extern int mallopt (int, int); |
|
|
1429 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1430 | #endif |
|
|
1431 | mlockall (flags); |
|
|
1432 | #else |
1593 | #else |
1433 | RETVAL = -1; |
1594 | RETVAL = ((errno = ENOSYS), -1); |
1434 | errno = ENOSYS; |
|
|
1435 | #endif |
1595 | #endif |
|
|
1596 | } |
1436 | OUTPUT: |
1597 | OUTPUT: |
1437 | RETVAL |
1598 | RETVAL |
1438 | |
1599 | |
1439 | int |
1600 | int |
1440 | munlockall () |
1601 | munlockall () |
1441 | PROTOTYPE: |
|
|
1442 | CODE: |
1602 | CODE: |
1443 | #if _POSIX_MEMLOCK |
1603 | #if _POSIX_MEMLOCK |
1444 | munlockall (); |
1604 | munlockall (); |
1445 | #else |
1605 | #else |
1446 | RETVAL = -1; |
1606 | RETVAL = -1; |