… | |
… | |
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 |
… | |
… | |
121 | #define EIO_NO_WRAPPERS 1 |
121 | #define EIO_NO_WRAPPERS 1 |
122 | |
122 | |
123 | #include "libeio/config.h" |
123 | #include "libeio/config.h" |
124 | #include "libeio/eio.h" |
124 | #include "libeio/eio.h" |
125 | |
125 | |
|
|
126 | /* Linux/others */ |
|
|
127 | #ifndef O_ASYNC |
|
|
128 | # define O_ASYNC 0 |
|
|
129 | #endif |
|
|
130 | #ifndef O_DIRECT |
|
|
131 | # define O_DIRECT 0 |
|
|
132 | #endif |
|
|
133 | #ifndef O_NOATIME |
|
|
134 | # define O_NOATIME 0 |
|
|
135 | #endif |
|
|
136 | |
|
|
137 | /* POSIX */ |
|
|
138 | #ifndef O_CLOEXEC |
|
|
139 | # define O_CLOEXEC 0 |
|
|
140 | #endif |
|
|
141 | #ifndef O_NOFOLLOW |
|
|
142 | # define O_NOFOLLOW 0 |
|
|
143 | #endif |
|
|
144 | #ifndef O_NOCTTY |
|
|
145 | # define O_NOCTTY 0 |
|
|
146 | #endif |
|
|
147 | #ifndef O_NONBLOCK |
|
|
148 | # define O_NONBLOCK 0 |
|
|
149 | #endif |
|
|
150 | #ifndef O_EXEC |
|
|
151 | # define O_EXEC 0 |
|
|
152 | #endif |
|
|
153 | #ifndef O_SEARCH |
|
|
154 | # define O_SEARCH 0 |
|
|
155 | #endif |
|
|
156 | #ifndef O_DIRECTORY |
|
|
157 | # define O_DIRECTORY 0 |
|
|
158 | #endif |
|
|
159 | #ifndef O_DSYNC |
|
|
160 | # define O_DSYNC 0 |
|
|
161 | #endif |
|
|
162 | #ifndef O_RSYNC |
|
|
163 | # define O_RSYNC 0 |
|
|
164 | #endif |
|
|
165 | #ifndef O_SYNC |
|
|
166 | # define O_SYNC 0 |
|
|
167 | #endif |
|
|
168 | #ifndef O_TTY_INIT |
|
|
169 | # define O_TTY_INIT 0 |
|
|
170 | #endif |
|
|
171 | |
126 | #ifndef POSIX_FADV_NORMAL |
172 | #ifndef POSIX_FADV_NORMAL |
127 | # define POSIX_FADV_NORMAL 0 |
173 | # define POSIX_FADV_NORMAL 0 |
128 | #endif |
174 | #endif |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
175 | #ifndef POSIX_FADV_SEQUENTIAL |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
176 | # define POSIX_FADV_SEQUENTIAL 0 |
… | |
… | |
206 | #ifndef ST_NODIRATIME |
252 | #ifndef ST_NODIRATIME |
207 | # define ST_NODIRATIME 0 |
253 | # define ST_NODIRATIME 0 |
208 | #endif |
254 | #endif |
209 | #ifndef ST_RELATIME |
255 | #ifndef ST_RELATIME |
210 | # define ST_RELATIME 0 |
256 | # define ST_RELATIME 0 |
|
|
257 | #endif |
|
|
258 | |
|
|
259 | #ifndef S_IFIFO |
|
|
260 | # define S_IFIFO 0 |
|
|
261 | #endif |
|
|
262 | #ifndef S_IFCHR |
|
|
263 | # define S_IFCHR 0 |
|
|
264 | #endif |
|
|
265 | #ifndef S_IFBLK |
|
|
266 | # define S_IFBLK 0 |
|
|
267 | #endif |
|
|
268 | #ifndef S_IFLNK |
|
|
269 | # define S_IFLNK 0 |
|
|
270 | #endif |
|
|
271 | #ifndef S_IFREG |
|
|
272 | # define S_IFREG 0 |
|
|
273 | #endif |
|
|
274 | #ifndef S_IFDIR |
|
|
275 | # define S_IFDIR 0 |
|
|
276 | #endif |
|
|
277 | #ifndef S_IFWHT |
|
|
278 | # define S_IFWHT 0 |
|
|
279 | #endif |
|
|
280 | #ifndef S_IFSOCK |
|
|
281 | # define S_IFSOCK 0 |
211 | #endif |
282 | #endif |
212 | |
283 | |
213 | #ifndef MAP_ANONYMOUS |
284 | #ifndef MAP_ANONYMOUS |
214 | # ifdef MAP_ANON |
285 | # ifdef MAP_ANON |
215 | # define MAP_ANONYMOUS MAP_ANON |
286 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
229 | #ifndef MAP_POPULATE |
300 | #ifndef MAP_POPULATE |
230 | # define MAP_POPULATE 0 |
301 | # define MAP_POPULATE 0 |
231 | #endif |
302 | #endif |
232 | #ifndef MAP_NONBLOCK |
303 | #ifndef MAP_NONBLOCK |
233 | # define MAP_NONBLOCK 0 |
304 | # define MAP_NONBLOCK 0 |
|
|
305 | #endif |
|
|
306 | |
|
|
307 | #ifndef makedev |
|
|
308 | # define makedev(maj,min) (((maj) << 8) | (min)) |
|
|
309 | #endif |
|
|
310 | #ifndef major |
|
|
311 | # define major(dev) ((dev) >> 8) |
|
|
312 | #endif |
|
|
313 | #ifndef minor |
|
|
314 | # define minor(dev) ((dev) & 0xff) |
234 | #endif |
315 | #endif |
235 | |
316 | |
236 | #ifndef PAGESIZE |
317 | #ifndef PAGESIZE |
237 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
318 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
238 | #endif |
319 | #endif |
… | |
… | |
353 | /* do not recreate the result IV from scratch each time */ |
434 | /* do not recreate the result IV from scratch each time */ |
354 | if (expect_true (sv_result_cache)) |
435 | if (expect_true (sv_result_cache)) |
355 | { |
436 | { |
356 | sv_result = sv_result_cache; sv_result_cache = 0; |
437 | sv_result = sv_result_cache; sv_result_cache = 0; |
357 | SvIV_set (sv_result, req->result); |
438 | SvIV_set (sv_result, req->result); |
|
|
439 | SvIOK_only (sv_result); |
358 | } |
440 | } |
359 | else |
441 | else |
360 | { |
442 | { |
361 | sv_result = newSViv (req->result); |
443 | sv_result = newSViv (req->result); |
362 | SvREADONLY_on (sv_result); |
444 | SvREADONLY_on (sv_result); |
… | |
… | |
526 | SvSETMAGIC (req->sv2); |
608 | SvSETMAGIC (req->sv2); |
527 | PUSHs (sv_result); |
609 | PUSHs (sv_result); |
528 | } |
610 | } |
529 | break; |
611 | break; |
530 | |
612 | |
531 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
613 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
532 | if (req->result > 0) |
614 | if (req->result > 0) |
533 | SvIV_set (sv_result, 0); |
615 | SvIV_set (sv_result, 0); |
534 | /* FALLTHROUGH */ |
616 | /* FALLTHROUGH */ |
535 | |
617 | |
536 | default: |
618 | default: |
… | |
… | |
636 | /*****************************************************************************/ |
718 | /*****************************************************************************/ |
637 | |
719 | |
638 | #if !_POSIX_MAPPED_FILES |
720 | #if !_POSIX_MAPPED_FILES |
639 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
721 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
640 | # define munmap(addr,length) (errno = ENOSYS, -1) |
722 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
723 | #endif |
|
|
724 | |
|
|
725 | #if !_POSIX_MEMORY_PROTECTION |
641 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
726 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
642 | # define PROT_NONE 0 |
727 | # define PROT_NONE 0 |
643 | # define PROT_WRITE 0 |
728 | # define PROT_WRITE 0 |
644 | # define MAP_PRIVATE 0 |
729 | # define MAP_PRIVATE 0 |
645 | # define MAP_SHARED 0 |
730 | # define MAP_SHARED 0 |
… | |
… | |
725 | const_iv (O_RDWR) |
810 | const_iv (O_RDWR) |
726 | const_iv (O_CREAT) |
811 | const_iv (O_CREAT) |
727 | const_iv (O_TRUNC) |
812 | const_iv (O_TRUNC) |
728 | const_iv (O_EXCL) |
813 | const_iv (O_EXCL) |
729 | const_iv (O_APPEND) |
814 | const_iv (O_APPEND) |
730 | #ifndef _WIN32 |
815 | |
|
|
816 | const_iv (O_ASYNC) |
|
|
817 | const_iv (O_DIRECT) |
|
|
818 | const_iv (O_NOATIME) |
|
|
819 | |
|
|
820 | const_iv (O_CLOEXEC) |
|
|
821 | const_iv (O_NOCTTY) |
|
|
822 | const_iv (O_NOFOLLOW) |
|
|
823 | const_iv (O_NONBLOCK) |
|
|
824 | const_iv (O_EXEC) |
|
|
825 | const_iv (O_SEARCH) |
|
|
826 | const_iv (O_DIRECTORY) |
|
|
827 | const_iv (O_DSYNC) |
|
|
828 | const_iv (O_RSYNC) |
|
|
829 | const_iv (O_SYNC) |
|
|
830 | const_iv (O_TTY_INIT) |
|
|
831 | |
731 | const_iv (S_IFIFO) |
832 | const_iv (S_IFIFO) |
732 | #endif |
833 | const_iv (S_IFCHR) |
|
|
834 | const_iv (S_IFBLK) |
|
|
835 | const_iv (S_IFLNK) |
|
|
836 | const_iv (S_IFREG) |
|
|
837 | const_iv (S_IFDIR) |
|
|
838 | const_iv (S_IFWHT) |
|
|
839 | const_iv (S_IFSOCK) |
|
|
840 | const_iv (S_IFMT) |
|
|
841 | |
733 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
842 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
734 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
843 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
735 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
844 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
736 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
845 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
737 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
846 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
… | |
… | |
819 | /* atfork child called in fifo order, so before eio's handler */ |
928 | /* atfork child called in fifo order, so before eio's handler */ |
820 | X_THREAD_ATFORK (0, 0, atfork_child); |
929 | X_THREAD_ATFORK (0, 0, atfork_child); |
821 | } |
930 | } |
822 | |
931 | |
823 | void |
932 | void |
824 | max_poll_reqs (int nreqs) |
933 | max_poll_reqs (unsigned int nreqs) |
825 | PROTOTYPE: $ |
934 | PROTOTYPE: $ |
826 | CODE: |
935 | CODE: |
827 | eio_set_max_poll_reqs (nreqs); |
936 | eio_set_max_poll_reqs (nreqs); |
828 | |
937 | |
829 | void |
938 | void |
… | |
… | |
831 | PROTOTYPE: $ |
940 | PROTOTYPE: $ |
832 | CODE: |
941 | CODE: |
833 | eio_set_max_poll_time (nseconds); |
942 | eio_set_max_poll_time (nseconds); |
834 | |
943 | |
835 | void |
944 | void |
836 | min_parallel (int nthreads) |
945 | min_parallel (unsigned int nthreads) |
837 | PROTOTYPE: $ |
946 | PROTOTYPE: $ |
838 | CODE: |
947 | CODE: |
839 | eio_set_min_parallel (nthreads); |
948 | eio_set_min_parallel (nthreads); |
840 | |
949 | |
841 | void |
950 | void |
842 | max_parallel (int nthreads) |
951 | max_parallel (unsigned int nthreads) |
843 | PROTOTYPE: $ |
952 | PROTOTYPE: $ |
844 | CODE: |
953 | CODE: |
845 | eio_set_max_parallel (nthreads); |
954 | eio_set_max_parallel (nthreads); |
846 | |
955 | |
847 | void |
956 | void |
848 | max_idle (int nthreads) |
957 | max_idle (unsigned int nthreads) |
849 | PROTOTYPE: $ |
958 | PROTOTYPE: $ |
850 | CODE: |
959 | CODE: |
851 | eio_set_max_idle (nthreads); |
960 | eio_set_max_idle (nthreads); |
852 | |
961 | |
853 | void |
962 | void |
|
|
963 | idle_timeout (unsigned int seconds) |
|
|
964 | PROTOTYPE: $ |
|
|
965 | CODE: |
|
|
966 | eio_set_idle_timeout (seconds); |
|
|
967 | |
|
|
968 | void |
854 | max_outstanding (int maxreqs) |
969 | max_outstanding (unsigned int maxreqs) |
855 | PROTOTYPE: $ |
970 | PROTOTYPE: $ |
856 | CODE: |
971 | CODE: |
857 | max_outstanding = maxreqs; |
972 | max_outstanding = maxreqs; |
858 | |
973 | |
859 | void |
974 | void |
… | |
… | |
1059 | } |
1174 | } |
1060 | |
1175 | |
1061 | REQ_SEND; |
1176 | REQ_SEND; |
1062 | } |
1177 | } |
1063 | |
1178 | |
|
|
1179 | UV |
|
|
1180 | major (UV dev) |
|
|
1181 | ALIAS: |
|
|
1182 | minor = 1 |
|
|
1183 | CODE: |
|
|
1184 | RETVAL = ix ? major (dev) : minor (dev); |
|
|
1185 | OUTPUT: |
|
|
1186 | RETVAL |
|
|
1187 | |
|
|
1188 | UV |
|
|
1189 | makedev (UV maj, UV min) |
|
|
1190 | CODE: |
|
|
1191 | RETVAL = makedev (maj, min); |
|
|
1192 | OUTPUT: |
|
|
1193 | RETVAL |
|
|
1194 | |
1064 | void |
1195 | void |
1065 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1196 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1066 | PPCODE: |
1197 | PPCODE: |
1067 | { |
1198 | { |
1068 | dREQ; |
1199 | dREQ; |
… | |
… | |
1523 | if (!SvOK (length) || len + offset > svlen) |
1654 | if (!SvOK (length) || len + offset > svlen) |
1524 | len = svlen - offset; |
1655 | len = svlen - offset; |
1525 | |
1656 | |
1526 | addr = (void *)(((intptr_t)addr) + offset); |
1657 | addr = (void *)(((intptr_t)addr) + offset); |
1527 | eio_page_align (&addr, &len); |
1658 | eio_page_align (&addr, &len); |
1528 | #if _POSIX_MEMLOCK |
1659 | #if _POSIX_MEMLOCK_RANGE |
1529 | RETVAL = munlock (addr, len); |
1660 | RETVAL = munlock (addr, len); |
1530 | #else |
1661 | #else |
1531 | RETVAL = ((errno = ENOSYS), -1); |
1662 | RETVAL = ((errno = ENOSYS), -1); |
1532 | #endif |
1663 | #endif |
1533 | } |
1664 | } |