… | |
… | |
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 | |
145 | #ifndef POSIX_MADV_NORMAL |
149 | #ifndef POSIX_MADV_NORMAL |
146 | # define POSIX_MADV_NORMAL 0 |
150 | # define POSIX_MADV_NORMAL 0 |
147 | # define NO_MADVISE 1 |
|
|
148 | #endif |
151 | #endif |
149 | #ifndef POSIX_MADV_SEQUENTIAL |
152 | #ifndef POSIX_MADV_SEQUENTIAL |
150 | # define POSIX_MADV_SEQUENTIAL 0 |
153 | # define POSIX_MADV_SEQUENTIAL 0 |
151 | #endif |
154 | #endif |
152 | #ifndef POSIX_MADV_RANDOM |
155 | #ifndef POSIX_MADV_RANDOM |
… | |
… | |
157 | #endif |
160 | #endif |
158 | #ifndef POSIX_MADV_DONTNEED |
161 | #ifndef POSIX_MADV_DONTNEED |
159 | # define POSIX_MADV_DONTNEED 0 |
162 | # define POSIX_MADV_DONTNEED 0 |
160 | #endif |
163 | #endif |
161 | |
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 | |
162 | #ifndef ST_NODEV |
182 | #ifndef ST_NODEV |
163 | # define ST_NODEV 0 |
183 | # define ST_NODEV 0 |
164 | #endif |
184 | #endif |
165 | #ifndef ST_NOEXEC |
185 | #ifndef ST_NOEXEC |
166 | # define ST_NOEXEC 0 |
186 | # define ST_NOEXEC 0 |
… | |
… | |
188 | #endif |
208 | #endif |
189 | #ifndef ST_RELATIME |
209 | #ifndef ST_RELATIME |
190 | # define ST_RELATIME 0 |
210 | # define ST_RELATIME 0 |
191 | #endif |
211 | #endif |
192 | |
212 | |
193 | #ifndef MCL_CURRENT |
213 | #ifndef S_IFIFO |
194 | # define MCL_CURRENT 0 |
214 | # define S_IFIFO 0 |
195 | #endif |
215 | #endif |
196 | #ifndef MCL_FUTURE |
216 | #ifndef S_IFCHR |
197 | # 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 |
198 | #endif |
236 | #endif |
199 | |
237 | |
200 | #ifndef MAP_ANONYMOUS |
238 | #ifndef MAP_ANONYMOUS |
201 | # ifdef MAP_ANON |
239 | # ifdef MAP_ANON |
202 | # define MAP_ANONYMOUS MAP_ANON |
240 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
216 | #ifndef MAP_POPULATE |
254 | #ifndef MAP_POPULATE |
217 | # define MAP_POPULATE 0 |
255 | # define MAP_POPULATE 0 |
218 | #endif |
256 | #endif |
219 | #ifndef MAP_NONBLOCK |
257 | #ifndef MAP_NONBLOCK |
220 | # 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) |
221 | #endif |
269 | #endif |
222 | |
270 | |
223 | #ifndef PAGESIZE |
271 | #ifndef PAGESIZE |
224 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
272 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
225 | #endif |
273 | #endif |
… | |
… | |
340 | /* do not recreate the result IV from scratch each time */ |
388 | /* do not recreate the result IV from scratch each time */ |
341 | if (expect_true (sv_result_cache)) |
389 | if (expect_true (sv_result_cache)) |
342 | { |
390 | { |
343 | sv_result = sv_result_cache; sv_result_cache = 0; |
391 | sv_result = sv_result_cache; sv_result_cache = 0; |
344 | SvIV_set (sv_result, req->result); |
392 | SvIV_set (sv_result, req->result); |
|
|
393 | SvIOK_only (sv_result); |
345 | } |
394 | } |
346 | else |
395 | else |
347 | { |
396 | { |
348 | sv_result = newSViv (req->result); |
397 | sv_result = newSViv (req->result); |
349 | SvREADONLY_on (sv_result); |
398 | SvREADONLY_on (sv_result); |
… | |
… | |
513 | SvSETMAGIC (req->sv2); |
562 | SvSETMAGIC (req->sv2); |
514 | PUSHs (sv_result); |
563 | PUSHs (sv_result); |
515 | } |
564 | } |
516 | break; |
565 | break; |
517 | |
566 | |
518 | 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 */ |
519 | if (req->result > 0) |
568 | if (req->result > 0) |
520 | SvIV_set (sv_result, 0); |
569 | SvIV_set (sv_result, 0); |
521 | /* FALLTHROUGH */ |
570 | /* FALLTHROUGH */ |
522 | |
571 | |
523 | default: |
572 | default: |
… | |
… | |
623 | /*****************************************************************************/ |
672 | /*****************************************************************************/ |
624 | |
673 | |
625 | #if !_POSIX_MAPPED_FILES |
674 | #if !_POSIX_MAPPED_FILES |
626 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
675 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
627 | # 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 |
628 | #endif |
686 | #endif |
629 | |
687 | |
630 | #define MMAP_MAGIC PERL_MAGIC_ext |
688 | #define MMAP_MAGIC PERL_MAGIC_ext |
631 | |
689 | |
632 | static int |
690 | static int |
… | |
… | |
706 | const_iv (O_RDWR) |
764 | const_iv (O_RDWR) |
707 | const_iv (O_CREAT) |
765 | const_iv (O_CREAT) |
708 | const_iv (O_TRUNC) |
766 | const_iv (O_TRUNC) |
709 | const_iv (O_EXCL) |
767 | const_iv (O_EXCL) |
710 | const_iv (O_APPEND) |
768 | const_iv (O_APPEND) |
711 | #ifndef _WIN32 |
769 | |
712 | const_iv (S_IFIFO) |
770 | const_iv (S_IFIFO) |
713 | #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 | |
714 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
780 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
715 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
781 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
716 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
782 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
717 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
783 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
718 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
784 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
… | |
… | |
735 | const_iv (ST_IMMUTABLE) |
801 | const_iv (ST_IMMUTABLE) |
736 | const_iv (ST_NOATIME) |
802 | const_iv (ST_NOATIME) |
737 | const_iv (ST_NODIRATIME) |
803 | const_iv (ST_NODIRATIME) |
738 | const_iv (ST_RELATIME) |
804 | const_iv (ST_RELATIME) |
739 | |
805 | |
|
|
806 | const_iv (PROT_NONE) |
740 | const_iv (PROT_EXEC) |
807 | const_iv (PROT_EXEC) |
741 | const_iv (PROT_NONE) |
|
|
742 | const_iv (PROT_READ) |
808 | const_iv (PROT_READ) |
743 | const_iv (PROT_WRITE) |
809 | const_iv (PROT_WRITE) |
744 | |
810 | |
745 | /*const_iv (MAP_FIXED)*/ |
811 | /*const_iv (MAP_FIXED)*/ |
746 | const_iv (MAP_PRIVATE) |
812 | const_iv (MAP_PRIVATE) |
… | |
… | |
752 | const_iv (MAP_LOCKED) |
818 | const_iv (MAP_LOCKED) |
753 | const_iv (MAP_NORESERVE) |
819 | const_iv (MAP_NORESERVE) |
754 | const_iv (MAP_POPULATE) |
820 | const_iv (MAP_POPULATE) |
755 | const_iv (MAP_NONBLOCK) |
821 | const_iv (MAP_NONBLOCK) |
756 | |
822 | |
757 | const_iv (MCL_FUTURE) |
823 | const_eio (MCL_FUTURE) |
758 | const_iv (MCL_CURRENT) |
824 | const_eio (MCL_CURRENT) |
759 | |
825 | |
760 | const_eio (MS_ASYNC) |
826 | const_eio (MS_ASYNC) |
761 | const_eio (MS_INVALIDATE) |
827 | const_eio (MS_INVALIDATE) |
762 | const_eio (MS_SYNC) |
828 | const_eio (MS_SYNC) |
763 | |
829 | |
… | |
… | |
837 | CODE: |
903 | CODE: |
838 | max_outstanding = maxreqs; |
904 | max_outstanding = maxreqs; |
839 | |
905 | |
840 | void |
906 | void |
841 | 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) |
842 | PROTOTYPE: $$$;$ |
|
|
843 | PPCODE: |
908 | PPCODE: |
844 | { |
909 | { |
845 | dREQ; |
910 | dREQ; |
846 | |
911 | |
847 | req->type = EIO_OPEN; |
912 | req->type = EIO_OPEN; |
… | |
… | |
853 | REQ_SEND; |
918 | REQ_SEND; |
854 | } |
919 | } |
855 | |
920 | |
856 | void |
921 | void |
857 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
922 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
858 | PROTOTYPE: $;$ |
|
|
859 | ALIAS: |
923 | ALIAS: |
860 | aio_fsync = EIO_FSYNC |
924 | aio_fsync = EIO_FSYNC |
861 | aio_fdatasync = EIO_FDATASYNC |
925 | aio_fdatasync = EIO_FDATASYNC |
862 | PPCODE: |
926 | PPCODE: |
863 | { |
927 | { |
… | |
… | |
871 | REQ_SEND (req); |
935 | REQ_SEND (req); |
872 | } |
936 | } |
873 | |
937 | |
874 | void |
938 | void |
875 | 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) |
876 | PROTOTYPE: $$$$;$ |
|
|
877 | PPCODE: |
940 | PPCODE: |
878 | { |
941 | { |
879 | int fd = s_fileno_croak (fh, 0); |
942 | int fd = s_fileno_croak (fh, 0); |
880 | dREQ; |
943 | dREQ; |
881 | |
944 | |
… | |
… | |
889 | REQ_SEND (req); |
952 | REQ_SEND (req); |
890 | } |
953 | } |
891 | |
954 | |
892 | void |
955 | void |
893 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
956 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
894 | PROTOTYPE: $;$ |
|
|
895 | PPCODE: |
957 | PPCODE: |
896 | { |
958 | { |
897 | 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 */ |
898 | int fd = s_fileno_croak (fh, 0); |
960 | int fd = s_fileno_croak (fh, 0); |
899 | dREQ; |
961 | dREQ; |
… | |
… | |
921 | void |
983 | void |
922 | 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) |
923 | ALIAS: |
985 | ALIAS: |
924 | aio_read = EIO_READ |
986 | aio_read = EIO_READ |
925 | aio_write = EIO_WRITE |
987 | aio_write = EIO_WRITE |
926 | PROTOTYPE: $$$$$;$ |
|
|
927 | PPCODE: |
988 | PPCODE: |
928 | { |
989 | { |
929 | STRLEN svlen; |
990 | STRLEN svlen; |
930 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
991 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
931 | char *svptr = SvPVbyte (data, svlen); |
992 | char *svptr = SvPVbyte (data, svlen); |
… | |
… | |
972 | } |
1033 | } |
973 | } |
1034 | } |
974 | |
1035 | |
975 | void |
1036 | void |
976 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1037 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
977 | PROTOTYPE: $$;$ |
|
|
978 | PPCODE: |
1038 | PPCODE: |
979 | { |
1039 | { |
980 | SV *data; |
1040 | SV *data; |
981 | dREQ; |
1041 | dREQ; |
982 | |
1042 | |
… | |
… | |
987 | REQ_SEND; |
1047 | REQ_SEND; |
988 | } |
1048 | } |
989 | |
1049 | |
990 | void |
1050 | void |
991 | 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) |
992 | PROTOTYPE: $$$$;$ |
|
|
993 | PPCODE: |
1052 | PPCODE: |
994 | { |
1053 | { |
995 | int ifd = s_fileno_croak (in_fh , 0); |
1054 | int ifd = s_fileno_croak (in_fh , 0); |
996 | int ofd = s_fileno_croak (out_fh, 1); |
1055 | int ofd = s_fileno_croak (out_fh, 1); |
997 | dREQ; |
1056 | dREQ; |
… | |
… | |
1007 | REQ_SEND; |
1066 | REQ_SEND; |
1008 | } |
1067 | } |
1009 | |
1068 | |
1010 | void |
1069 | void |
1011 | 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) |
1012 | PROTOTYPE: $$$;$ |
|
|
1013 | PPCODE: |
1071 | PPCODE: |
1014 | { |
1072 | { |
1015 | int fd = s_fileno_croak (fh, 0); |
1073 | int fd = s_fileno_croak (fh, 0); |
1016 | dREQ; |
1074 | dREQ; |
1017 | |
1075 | |
… | |
… | |
1048 | } |
1106 | } |
1049 | |
1107 | |
1050 | REQ_SEND; |
1108 | REQ_SEND; |
1051 | } |
1109 | } |
1052 | |
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 | |
1053 | void |
1127 | void |
1054 | 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) |
1055 | PPCODE: |
1129 | PPCODE: |
1056 | { |
1130 | { |
1057 | dREQ; |
1131 | dREQ; |
… | |
… | |
1218 | void |
1292 | void |
1219 | 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) |
1220 | ALIAS: |
1294 | ALIAS: |
1221 | aio_mtouch = EIO_MTOUCH |
1295 | aio_mtouch = EIO_MTOUCH |
1222 | aio_msync = EIO_MSYNC |
1296 | aio_msync = EIO_MSYNC |
1223 | PROTOTYPE: $$$$;$ |
|
|
1224 | PPCODE: |
1297 | PPCODE: |
1225 | { |
1298 | { |
1226 | STRLEN svlen; |
1299 | STRLEN svlen; |
|
|
1300 | char *svptr = SvPVbyte (data, svlen); |
1227 | UV len = SvUV (length); |
1301 | UV len = SvUV (length); |
1228 | char *svptr = SvPVbyte (data, svlen); |
|
|
1229 | |
1302 | |
1230 | if (offset < 0) |
1303 | if (offset < 0) |
1231 | offset += svlen; |
1304 | offset += svlen; |
1232 | |
1305 | |
1233 | if (offset < 0 || offset > svlen) |
1306 | if (offset < 0 || offset > svlen) |
… | |
… | |
1238 | |
1311 | |
1239 | { |
1312 | { |
1240 | dREQ; |
1313 | dREQ; |
1241 | |
1314 | |
1242 | req->type = ix; |
1315 | req->type = ix; |
1243 | req->size = len; |
|
|
1244 | req->sv2 = SvREFCNT_inc (data); |
1316 | req->sv2 = SvREFCNT_inc (data); |
1245 | req->ptr2 = (char *)svptr + offset; |
1317 | req->ptr2 = (char *)svptr + offset; |
|
|
1318 | req->size = len; |
1246 | req->int1 = flags; |
1319 | req->int1 = flags; |
1247 | |
1320 | |
1248 | REQ_SEND; |
1321 | REQ_SEND; |
1249 | } |
1322 | } |
1250 | } |
1323 | } |
1251 | |
1324 | |
1252 | 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 |
1253 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1367 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1254 | PPCODE: |
1368 | PPCODE: |
1255 | { |
1369 | { |
1256 | dREQ; |
1370 | dREQ; |
1257 | |
1371 | |
… | |
… | |
1261 | REQ_SEND; |
1375 | REQ_SEND; |
1262 | } |
1376 | } |
1263 | |
1377 | |
1264 | void |
1378 | void |
1265 | aio_group (SV *callback=&PL_sv_undef) |
1379 | aio_group (SV *callback=&PL_sv_undef) |
1266 | PROTOTYPE: ;$ |
|
|
1267 | PPCODE: |
1380 | PPCODE: |
1268 | { |
1381 | { |
1269 | dREQ; |
1382 | dREQ; |
1270 | |
1383 | |
1271 | req->type = EIO_GROUP; |
1384 | req->type = EIO_GROUP; |
… | |
… | |
1288 | REQ_SEND; |
1401 | REQ_SEND; |
1289 | } |
1402 | } |
1290 | |
1403 | |
1291 | int |
1404 | int |
1292 | aioreq_pri (int pri = 0) |
1405 | aioreq_pri (int pri = 0) |
1293 | PROTOTYPE: ;$ |
|
|
1294 | CODE: |
1406 | CODE: |
1295 | RETVAL = next_pri; |
1407 | RETVAL = next_pri; |
1296 | if (items > 0) |
1408 | if (items > 0) |
1297 | { |
1409 | { |
1298 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1410 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1310 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1422 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1311 | next_pri = nice; |
1423 | next_pri = nice; |
1312 | |
1424 | |
1313 | void |
1425 | void |
1314 | flush () |
1426 | flush () |
1315 | PROTOTYPE: |
|
|
1316 | CODE: |
1427 | CODE: |
1317 | while (eio_nreqs ()) |
1428 | while (eio_nreqs ()) |
1318 | { |
1429 | { |
1319 | poll_wait (); |
1430 | poll_wait (); |
1320 | poll_cb (); |
1431 | poll_cb (); |
1321 | } |
1432 | } |
1322 | |
1433 | |
1323 | int |
1434 | int |
1324 | poll() |
1435 | poll () |
1325 | PROTOTYPE: |
|
|
1326 | CODE: |
1436 | CODE: |
1327 | poll_wait (); |
1437 | poll_wait (); |
1328 | RETVAL = poll_cb (); |
1438 | RETVAL = poll_cb (); |
1329 | OUTPUT: |
1439 | OUTPUT: |
1330 | RETVAL |
1440 | RETVAL |
1331 | |
1441 | |
1332 | int |
1442 | int |
1333 | poll_fileno() |
1443 | poll_fileno () |
1334 | PROTOTYPE: |
|
|
1335 | CODE: |
1444 | CODE: |
1336 | RETVAL = s_epipe_fd (&respipe); |
1445 | RETVAL = s_epipe_fd (&respipe); |
1337 | OUTPUT: |
1446 | OUTPUT: |
1338 | RETVAL |
1447 | RETVAL |
1339 | |
1448 | |
1340 | int |
1449 | int |
1341 | poll_cb(...) |
1450 | poll_cb (...) |
1342 | PROTOTYPE: |
1451 | PROTOTYPE: |
1343 | CODE: |
1452 | CODE: |
1344 | RETVAL = poll_cb (); |
1453 | RETVAL = poll_cb (); |
1345 | OUTPUT: |
1454 | OUTPUT: |
1346 | RETVAL |
1455 | RETVAL |
1347 | |
1456 | |
1348 | void |
1457 | void |
1349 | poll_wait() |
1458 | poll_wait () |
1350 | PROTOTYPE: |
|
|
1351 | CODE: |
1459 | CODE: |
1352 | poll_wait (); |
1460 | poll_wait (); |
1353 | |
1461 | |
1354 | int |
1462 | int |
1355 | nreqs() |
1463 | nreqs () |
1356 | PROTOTYPE: |
|
|
1357 | CODE: |
1464 | CODE: |
1358 | RETVAL = eio_nreqs (); |
1465 | RETVAL = eio_nreqs (); |
1359 | OUTPUT: |
1466 | OUTPUT: |
1360 | RETVAL |
1467 | RETVAL |
1361 | |
1468 | |
1362 | int |
1469 | int |
1363 | nready() |
1470 | nready () |
1364 | PROTOTYPE: |
|
|
1365 | CODE: |
1471 | CODE: |
1366 | RETVAL = eio_nready (); |
1472 | RETVAL = eio_nready (); |
1367 | OUTPUT: |
1473 | OUTPUT: |
1368 | RETVAL |
1474 | RETVAL |
1369 | |
1475 | |
1370 | int |
1476 | int |
1371 | npending() |
1477 | npending () |
1372 | PROTOTYPE: |
|
|
1373 | CODE: |
1478 | CODE: |
1374 | RETVAL = eio_npending (); |
1479 | RETVAL = eio_npending (); |
1375 | OUTPUT: |
1480 | OUTPUT: |
1376 | RETVAL |
1481 | RETVAL |
1377 | |
1482 | |
1378 | int |
1483 | int |
1379 | nthreads() |
1484 | nthreads () |
1380 | PROTOTYPE: |
|
|
1381 | CODE: |
1485 | CODE: |
1382 | RETVAL = eio_nthreads (); |
1486 | RETVAL = eio_nthreads (); |
1383 | OUTPUT: |
1487 | OUTPUT: |
1384 | RETVAL |
1488 | RETVAL |
1385 | |
1489 | |
1386 | int |
1490 | int |
1387 | 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) |
1388 | PROTOTYPE: $$$$ |
|
|
1389 | CODE: |
1492 | CODE: |
1390 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1391 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1493 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1392 | #else |
|
|
1393 | RETVAL = errno = ENOSYS; /* yes, this is actually correct */ |
|
|
1394 | #endif |
|
|
1395 | OUTPUT: |
1494 | OUTPUT: |
1396 | RETVAL |
1495 | RETVAL |
1397 | |
1496 | |
1398 | ssize_t |
1497 | ssize_t |
1399 | 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) |
1400 | PROTOTYPE: $$$$ |
|
|
1401 | CODE: |
1499 | CODE: |
1402 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1500 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1403 | OUTPUT: |
1501 | OUTPUT: |
1404 | RETVAL |
1502 | RETVAL |
1405 | |
1503 | |
1406 | void |
1504 | void |
1407 | 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) |
1408 | PROTOTYPE: $$$$$;$ |
|
|
1409 | PPCODE: |
1506 | PPCODE: |
1410 | sv_unmagic (scalar, MMAP_MAGIC); |
1507 | sv_unmagic (scalar, MMAP_MAGIC); |
1411 | { |
1508 | { |
1412 | 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; |
1413 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1510 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
… | |
… | |
1436 | XSRETURN_YES; |
1533 | XSRETURN_YES; |
1437 | } |
1534 | } |
1438 | |
1535 | |
1439 | void |
1536 | void |
1440 | munmap (SV *scalar) |
1537 | munmap (SV *scalar) |
1441 | PROTOTYPE: $ |
|
|
1442 | CODE: |
1538 | CODE: |
1443 | sv_unmagic (scalar, MMAP_MAGIC); |
1539 | sv_unmagic (scalar, MMAP_MAGIC); |
1444 | |
1540 | |
1445 | int |
1541 | int |
1446 | madvise (SV *scalar, off_t offset, off_t length, IV advice) |
1542 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
1447 | PROTOTYPE: $$$$ |
1543 | ALIAS: |
|
|
1544 | mprotect = 1 |
1448 | CODE: |
1545 | CODE: |
1449 | { |
1546 | { |
1450 | char *addr = SvPV_nolen (scalar) + offset; |
1547 | STRLEN svlen; |
|
|
1548 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1549 | size_t len = SvUV (length); |
1451 | |
1550 | |
1452 | if (!SvOK (ST (2))) |
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) |
1453 | length = SvCUR (scalar) - offset; |
1558 | len = svlen - offset; |
1454 | |
1559 | |
1455 | if (addr >= SvEND (scalar) || length <= 0) |
1560 | addr = (void *)(((intptr_t)addr) + offset); |
1456 | XSRETURN_EMPTY; |
1561 | eio_page_align (&addr, &len); |
1457 | |
1562 | |
1458 | #if _XOPEN_SOURCE >= 600 && !NO_MADVISE |
1563 | switch (ix) |
|
|
1564 | { |
1459 | RETVAL = posix_madvise (addr, length, advice); |
1565 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
1460 | #else |
1566 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
1461 | RETVAL = errno = ENOSYS; /* yes, this is actually correct */ |
1567 | } |
1462 | #endif |
|
|
1463 | } |
1568 | } |
1464 | OUTPUT: |
1569 | OUTPUT: |
1465 | RETVAL |
1570 | RETVAL |
1466 | |
1571 | |
1467 | int |
1572 | int |
1468 | mlockall (int flags) |
1573 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
1469 | PROTOTYPE: $ |
|
|
1470 | CODE: |
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); |
1471 | #if _POSIX_MEMLOCK |
1591 | #if _POSIX_MEMLOCK_RANGE |
1472 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
1592 | RETVAL = munlock (addr, len); |
1473 | extern int mallopt (int, int); |
|
|
1474 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1475 | #endif |
|
|
1476 | mlockall (flags); |
|
|
1477 | #else |
1593 | #else |
1478 | RETVAL = -1; |
1594 | RETVAL = ((errno = ENOSYS), -1); |
1479 | errno = ENOSYS; |
|
|
1480 | #endif |
1595 | #endif |
|
|
1596 | } |
1481 | OUTPUT: |
1597 | OUTPUT: |
1482 | RETVAL |
1598 | RETVAL |
1483 | |
1599 | |
1484 | int |
1600 | int |
1485 | munlockall () |
1601 | munlockall () |
1486 | PROTOTYPE: |
|
|
1487 | CODE: |
1602 | CODE: |
1488 | #if _POSIX_MEMLOCK |
1603 | #if _POSIX_MEMLOCK |
1489 | munlockall (); |
1604 | munlockall (); |
1490 | #else |
1605 | #else |
1491 | RETVAL = -1; |
1606 | RETVAL = -1; |