… | |
… | |
15 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
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 | |
|
|
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
|
|
22 | # include <sys/mman.h> |
|
|
23 | #endif |
20 | |
24 | |
21 | /* perl namespace pollution */ |
25 | /* perl namespace pollution */ |
22 | #undef VERSION |
26 | #undef VERSION |
23 | |
27 | |
24 | #ifdef _WIN32 |
28 | #ifdef _WIN32 |
… | |
… | |
118 | |
122 | |
119 | #include "libeio/eio.h" |
123 | #include "libeio/eio.h" |
120 | |
124 | |
121 | #ifndef POSIX_FADV_NORMAL |
125 | #ifndef POSIX_FADV_NORMAL |
122 | # define POSIX_FADV_NORMAL 0 |
126 | # define POSIX_FADV_NORMAL 0 |
123 | # define NO_FADVISE 1 |
|
|
124 | #endif |
127 | #endif |
125 | |
|
|
126 | #ifndef POSIX_FADV_SEQUENTIAL |
128 | #ifndef POSIX_FADV_SEQUENTIAL |
127 | # define POSIX_FADV_SEQUENTIAL 0 |
129 | # define POSIX_FADV_SEQUENTIAL 0 |
128 | #endif |
130 | #endif |
129 | |
|
|
130 | #ifndef POSIX_FADV_RANDOM |
131 | #ifndef POSIX_FADV_RANDOM |
131 | # define POSIX_FADV_RANDOM 0 |
132 | # define POSIX_FADV_RANDOM 0 |
132 | #endif |
133 | #endif |
133 | |
|
|
134 | #ifndef POSIX_FADV_NOREUSE |
134 | #ifndef POSIX_FADV_NOREUSE |
135 | # define POSIX_FADV_NOREUSE 0 |
135 | # define POSIX_FADV_NOREUSE 0 |
136 | #endif |
136 | #endif |
137 | |
|
|
138 | #ifndef POSIX_FADV_WILLNEED |
137 | #ifndef POSIX_FADV_WILLNEED |
139 | # define POSIX_FADV_WILLNEED 0 |
138 | # define POSIX_FADV_WILLNEED 0 |
140 | #endif |
139 | #endif |
141 | |
|
|
142 | #ifndef POSIX_FADV_DONTNEED |
140 | #ifndef POSIX_FADV_DONTNEED |
143 | # define POSIX_FADV_DONTNEED 0 |
141 | # define POSIX_FADV_DONTNEED 0 |
144 | #endif |
142 | #endif |
145 | |
143 | |
|
|
144 | #if !HAVE_POSIX_FADVISE |
|
|
145 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
|
|
146 | #endif |
|
|
147 | |
|
|
148 | #ifndef POSIX_MADV_NORMAL |
|
|
149 | # define POSIX_MADV_NORMAL 0 |
|
|
150 | #endif |
|
|
151 | #ifndef POSIX_MADV_SEQUENTIAL |
|
|
152 | # define POSIX_MADV_SEQUENTIAL 0 |
|
|
153 | #endif |
|
|
154 | #ifndef POSIX_MADV_RANDOM |
|
|
155 | # define POSIX_MADV_RANDOM 0 |
|
|
156 | #endif |
|
|
157 | #ifndef POSIX_MADV_WILLNEED |
|
|
158 | # define POSIX_MADV_WILLNEED 0 |
|
|
159 | #endif |
|
|
160 | #ifndef POSIX_MADV_DONTNEED |
|
|
161 | # define POSIX_MADV_DONTNEED 0 |
|
|
162 | #endif |
|
|
163 | |
|
|
164 | #if !HAVE_POSIX_MADVISE |
|
|
165 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
|
|
166 | #endif |
|
|
167 | |
|
|
168 | #ifndef PROT_NONE |
|
|
169 | # define PROT_NONE 0 |
|
|
170 | #endif |
|
|
171 | #ifndef PROT_READ |
|
|
172 | # define PROT_READ 0 |
|
|
173 | #endif |
|
|
174 | #ifndef PROT_WRITE |
|
|
175 | # define PROT_READ 0 |
|
|
176 | #endif |
|
|
177 | #ifndef PROT_EXEC |
|
|
178 | # define PROT_EXEC 0 |
|
|
179 | #endif |
|
|
180 | |
146 | #ifndef ST_NODEV |
181 | #ifndef ST_NODEV |
147 | # define ST_NODEV 0 |
182 | # define ST_NODEV 0 |
148 | #endif |
183 | #endif |
149 | |
|
|
150 | #ifndef ST_NOEXEC |
184 | #ifndef ST_NOEXEC |
151 | # define ST_NOEXEC 0 |
185 | # define ST_NOEXEC 0 |
152 | #endif |
186 | #endif |
153 | |
|
|
154 | #ifndef ST_SYNCHRONOUS |
187 | #ifndef ST_SYNCHRONOUS |
155 | # define ST_SYNCHRONOUS 0 |
188 | # define ST_SYNCHRONOUS 0 |
156 | #endif |
189 | #endif |
157 | |
|
|
158 | #ifndef ST_MANDLOCK |
190 | #ifndef ST_MANDLOCK |
159 | # define ST_MANDLOCK 0 |
191 | # define ST_MANDLOCK 0 |
160 | #endif |
192 | #endif |
161 | |
|
|
162 | #ifndef ST_WRITE |
193 | #ifndef ST_WRITE |
163 | # define ST_WRITE 0 |
194 | # define ST_WRITE 0 |
164 | #endif |
195 | #endif |
165 | |
|
|
166 | #ifndef ST_APPEND |
196 | #ifndef ST_APPEND |
167 | # define ST_APPEND 0 |
197 | # define ST_APPEND 0 |
168 | #endif |
198 | #endif |
169 | |
|
|
170 | #ifndef ST_IMMUTABLE |
199 | #ifndef ST_IMMUTABLE |
171 | # define ST_IMMUTABLE 0 |
200 | # define ST_IMMUTABLE 0 |
172 | #endif |
201 | #endif |
173 | |
|
|
174 | #ifndef ST_NOATIME |
202 | #ifndef ST_NOATIME |
175 | # define ST_NOATIME 0 |
203 | # define ST_NOATIME 0 |
176 | #endif |
204 | #endif |
177 | |
|
|
178 | #ifndef ST_NODIRATIME |
205 | #ifndef ST_NODIRATIME |
179 | # define ST_NODIRATIME 0 |
206 | # define ST_NODIRATIME 0 |
180 | #endif |
207 | #endif |
181 | |
|
|
182 | #ifndef ST_RELATIME |
208 | #ifndef ST_RELATIME |
183 | # define ST_RELATIME 0 |
209 | # define ST_RELATIME 0 |
|
|
210 | #endif |
|
|
211 | |
|
|
212 | #ifndef MAP_ANONYMOUS |
|
|
213 | # ifdef MAP_ANON |
|
|
214 | # define MAP_ANONYMOUS MAP_ANON |
|
|
215 | # else |
|
|
216 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
|
|
217 | # endif |
|
|
218 | #endif |
|
|
219 | #ifndef MAP_HUGETLB |
|
|
220 | # define MAP_HUGETLB 0 |
|
|
221 | #endif |
|
|
222 | #ifndef MAP_LOCKED |
|
|
223 | # define MAP_LOCKED 0 |
|
|
224 | #endif |
|
|
225 | #ifndef MAP_NORESERVE |
|
|
226 | # define MAP_NORESERVE 0 |
|
|
227 | #endif |
|
|
228 | #ifndef MAP_POPULATE |
|
|
229 | # define MAP_POPULATE 0 |
|
|
230 | #endif |
|
|
231 | #ifndef MAP_NONBLOCK |
|
|
232 | # define MAP_NONBLOCK 0 |
|
|
233 | #endif |
|
|
234 | |
|
|
235 | #ifndef PAGESIZE |
|
|
236 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
184 | #endif |
237 | #endif |
185 | |
238 | |
186 | static int req_invoke (eio_req *req); |
239 | static int req_invoke (eio_req *req); |
187 | #define EIO_FINISH(req) req_invoke (req) |
240 | #define EIO_FINISH(req) req_invoke (req) |
188 | static void req_destroy (eio_req *grp); |
241 | static void req_destroy (eio_req *grp); |
… | |
… | |
280 | } |
333 | } |
281 | } |
334 | } |
282 | |
335 | |
283 | static int req_invoke (eio_req *req) |
336 | static int req_invoke (eio_req *req) |
284 | { |
337 | { |
285 | dSP; |
|
|
286 | |
|
|
287 | if (req->flags & FLAG_SV2_RO_OFF) |
338 | if (req->flags & FLAG_SV2_RO_OFF) |
288 | SvREADONLY_off (req->sv2); |
339 | SvREADONLY_off (req->sv2); |
289 | |
340 | |
290 | if (!EIO_CANCELLED (req) && req->callback) |
341 | if (!EIO_CANCELLED (req) && req->callback) |
291 | { |
342 | { |
|
|
343 | dSP; |
|
|
344 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
345 | SV *sv_result; |
|
|
346 | |
292 | ENTER; |
347 | ENTER; |
293 | SAVETMPS; |
348 | SAVETMPS; |
294 | PUSHMARK (SP); |
349 | PUSHMARK (SP); |
295 | EXTEND (SP, 1); |
350 | EXTEND (SP, 1); |
|
|
351 | |
|
|
352 | /* do not recreate the result IV from scratch each time */ |
|
|
353 | if (expect_true (sv_result_cache)) |
|
|
354 | { |
|
|
355 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
356 | SvIV_set (sv_result, req->result); |
|
|
357 | } |
|
|
358 | else |
|
|
359 | { |
|
|
360 | sv_result = newSViv (req->result); |
|
|
361 | SvREADONLY_on (sv_result); |
|
|
362 | } |
296 | |
363 | |
297 | switch (req->type) |
364 | switch (req->type) |
298 | { |
365 | { |
299 | case EIO_READDIR: |
366 | case EIO_READDIR: |
300 | { |
367 | { |
… | |
… | |
445 | case EIO_LSTAT: |
512 | case EIO_LSTAT: |
446 | case EIO_FSTAT: |
513 | case EIO_FSTAT: |
447 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
514 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
448 | PL_laststatval = req->result; |
515 | PL_laststatval = req->result; |
449 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
516 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
450 | PUSHs (sv_2mortal (newSViv (req->result))); |
517 | PUSHs (sv_result); |
451 | break; |
518 | break; |
452 | |
519 | |
453 | case EIO_READ: |
520 | case EIO_READ: |
454 | { |
521 | { |
455 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
522 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
456 | *SvEND (req->sv2) = 0; |
523 | *SvEND (req->sv2) = 0; |
457 | SvPOK_only (req->sv2); |
524 | SvPOK_only (req->sv2); |
458 | SvSETMAGIC (req->sv2); |
525 | SvSETMAGIC (req->sv2); |
459 | PUSHs (sv_2mortal (newSViv (req->result))); |
526 | PUSHs (sv_result); |
460 | } |
527 | } |
461 | break; |
528 | break; |
462 | |
529 | |
463 | case EIO_DUP2: |
530 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
464 | if (req->result > 0) |
531 | if (req->result > 0) |
465 | req->result = 0; |
532 | SvIV_set (sv_result, 0); |
466 | /* FALLTHROUGH */ |
533 | /* FALLTHROUGH */ |
467 | |
534 | |
468 | default: |
535 | default: |
469 | PUSHs (sv_2mortal (newSViv (req->result))); |
536 | PUSHs (sv_result); |
470 | break; |
537 | break; |
471 | } |
538 | } |
472 | |
539 | |
473 | errno = req->errorno; |
540 | errno = req->errorno; |
474 | |
541 | |
475 | PUTBACK; |
542 | PUTBACK; |
476 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
543 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
477 | SPAGAIN; |
544 | SPAGAIN; |
|
|
545 | |
|
|
546 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
547 | SvREFCNT_dec (sv_result); |
|
|
548 | else |
|
|
549 | sv_result_cache = sv_result; |
478 | |
550 | |
479 | FREETMPS; |
551 | FREETMPS; |
480 | LEAVE; |
552 | LEAVE; |
481 | |
553 | |
482 | PUTBACK; |
554 | PUTBACK; |
… | |
… | |
557 | |
629 | |
558 | static void atfork_child (void) |
630 | static void atfork_child (void) |
559 | { |
631 | { |
560 | create_respipe (); |
632 | create_respipe (); |
561 | } |
633 | } |
|
|
634 | |
|
|
635 | /*****************************************************************************/ |
|
|
636 | |
|
|
637 | #if !_POSIX_MAPPED_FILES |
|
|
638 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
|
|
639 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
640 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
641 | # define PROT_NONE 0 |
|
|
642 | # define PROT_WRITE 0 |
|
|
643 | # define MAP_PRIVATE 0 |
|
|
644 | # define MAP_SHARED 0 |
|
|
645 | # define MAP_FIXED 0 |
|
|
646 | #endif |
|
|
647 | |
|
|
648 | #define MMAP_MAGIC PERL_MAGIC_ext |
|
|
649 | |
|
|
650 | static int |
|
|
651 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
652 | { |
|
|
653 | int old_errno = errno; |
|
|
654 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
|
|
655 | errno = old_errno; |
|
|
656 | |
|
|
657 | mg->mg_obj = 0; /* just in case */ |
|
|
658 | |
|
|
659 | SvREADONLY_off (sv); |
|
|
660 | |
|
|
661 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
662 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
663 | |
|
|
664 | SvCUR_set (sv, 0); |
|
|
665 | SvPVX (sv) = 0; |
|
|
666 | SvOK_off (sv); |
|
|
667 | |
|
|
668 | return 0; |
|
|
669 | } |
|
|
670 | |
|
|
671 | static MGVTBL mmap_vtbl = { |
|
|
672 | 0, 0, 0, 0, mmap_free |
|
|
673 | }; |
|
|
674 | |
|
|
675 | /*****************************************************************************/ |
562 | |
676 | |
563 | static SV * |
677 | static SV * |
564 | get_cb (SV *cb_sv) |
678 | get_cb (SV *cb_sv) |
565 | { |
679 | { |
566 | SvGETMAGIC (cb_sv); |
680 | SvGETMAGIC (cb_sv); |
… | |
… | |
598 | { |
712 | { |
599 | static const struct { |
713 | static const struct { |
600 | const char *name; |
714 | const char *name; |
601 | IV iv; |
715 | IV iv; |
602 | } *civ, const_iv[] = { |
716 | } *civ, const_iv[] = { |
603 | # define const_iv(name, value) { # name, (IV) value }, |
717 | # define const_niv(name, value) { # name, (IV) value }, |
|
|
718 | # define const_iv(name) { # name, (IV) name }, |
604 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
719 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
605 | const_iv (EXDEV , EXDEV) |
720 | const_iv (EXDEV) |
606 | const_iv (ENOSYS , ENOSYS) |
721 | const_iv (ENOSYS) |
607 | const_iv (O_RDONLY, O_RDONLY) |
722 | const_iv (O_RDONLY) |
608 | const_iv (O_WRONLY, O_WRONLY) |
723 | const_iv (O_WRONLY) |
|
|
724 | const_iv (O_RDWR) |
609 | const_iv (O_CREAT , O_CREAT) |
725 | const_iv (O_CREAT) |
610 | const_iv (O_TRUNC , O_TRUNC) |
726 | const_iv (O_TRUNC) |
|
|
727 | const_iv (O_EXCL) |
|
|
728 | const_iv (O_APPEND) |
611 | #ifndef _WIN32 |
729 | #ifndef _WIN32 |
612 | const_iv (S_IFIFO , S_IFIFO) |
730 | const_iv (S_IFIFO) |
613 | #endif |
731 | #endif |
614 | const_iv (FADV_NORMAL , POSIX_FADV_NORMAL) |
732 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
615 | const_iv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
733 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
616 | const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) |
734 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
617 | const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
735 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
618 | const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
736 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
619 | const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
737 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
620 | |
738 | |
621 | const_iv (ST_RDONLY , ST_RDONLY) |
739 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
622 | const_iv (ST_NOSUID , ST_NOSUID) |
740 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
623 | const_iv (ST_NODEV , ST_NODEV) |
741 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
624 | const_iv (ST_NOEXEC , ST_NOEXEC) |
742 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
743 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
|
|
744 | |
|
|
745 | const_iv (ST_RDONLY) |
|
|
746 | const_iv (ST_NOSUID) |
|
|
747 | const_iv (ST_NODEV) |
|
|
748 | const_iv (ST_NOEXEC) |
625 | const_iv (ST_SYNCHRONOUS , ST_SYNCHRONOUS) |
749 | const_iv (ST_SYNCHRONOUS) |
626 | const_iv (ST_MANDLOCK , ST_MANDLOCK) |
750 | const_iv (ST_MANDLOCK) |
627 | const_iv (ST_WRITE , ST_WRITE) |
751 | const_iv (ST_WRITE) |
628 | const_iv (ST_APPEND , ST_APPEND) |
752 | const_iv (ST_APPEND) |
629 | const_iv (ST_IMMUTABLE , ST_IMMUTABLE) |
753 | const_iv (ST_IMMUTABLE) |
630 | const_iv (ST_NOATIME , ST_NOATIME) |
754 | const_iv (ST_NOATIME) |
631 | const_iv (ST_NODIRATIME , ST_NODIRATIME) |
755 | const_iv (ST_NODIRATIME) |
632 | const_iv (ST_RELATIME , ST_RELATIME) |
756 | const_iv (ST_RELATIME) |
|
|
757 | |
|
|
758 | const_iv (PROT_NONE) |
|
|
759 | const_iv (PROT_EXEC) |
|
|
760 | const_iv (PROT_READ) |
|
|
761 | const_iv (PROT_WRITE) |
|
|
762 | |
|
|
763 | /*const_iv (MAP_FIXED)*/ |
|
|
764 | const_iv (MAP_PRIVATE) |
|
|
765 | const_iv (MAP_SHARED) |
|
|
766 | const_iv (MAP_ANONYMOUS) |
|
|
767 | |
|
|
768 | /* linuxish */ |
|
|
769 | const_iv (MAP_HUGETLB) |
|
|
770 | const_iv (MAP_LOCKED) |
|
|
771 | const_iv (MAP_NORESERVE) |
|
|
772 | const_iv (MAP_POPULATE) |
|
|
773 | const_iv (MAP_NONBLOCK) |
|
|
774 | |
|
|
775 | const_eio (MCL_FUTURE) |
|
|
776 | const_eio (MCL_CURRENT) |
633 | |
777 | |
634 | const_eio (MS_ASYNC) |
778 | const_eio (MS_ASYNC) |
635 | const_eio (MS_INVALIDATE) |
779 | const_eio (MS_INVALIDATE) |
636 | const_eio (MS_SYNC) |
780 | const_eio (MS_SYNC) |
637 | |
781 | |
… | |
… | |
662 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
806 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
663 | |
807 | |
664 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
808 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
665 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
809 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
666 | |
810 | |
|
|
811 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
|
|
812 | |
667 | create_respipe (); |
813 | create_respipe (); |
668 | |
814 | |
669 | if (eio_init (want_poll, done_poll) < 0) |
815 | if (eio_init (want_poll, done_poll) < 0) |
670 | croak ("IO::AIO: unable to initialise eio library"); |
816 | croak ("IO::AIO: unable to initialise eio library"); |
671 | |
817 | |
… | |
… | |
709 | CODE: |
855 | CODE: |
710 | max_outstanding = maxreqs; |
856 | max_outstanding = maxreqs; |
711 | |
857 | |
712 | void |
858 | void |
713 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
859 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
714 | PROTOTYPE: $$$;$ |
|
|
715 | PPCODE: |
860 | PPCODE: |
716 | { |
861 | { |
717 | dREQ; |
862 | dREQ; |
718 | |
863 | |
719 | req->type = EIO_OPEN; |
864 | req->type = EIO_OPEN; |
… | |
… | |
725 | REQ_SEND; |
870 | REQ_SEND; |
726 | } |
871 | } |
727 | |
872 | |
728 | void |
873 | void |
729 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
874 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
730 | PROTOTYPE: $;$ |
|
|
731 | ALIAS: |
875 | ALIAS: |
732 | aio_fsync = EIO_FSYNC |
876 | aio_fsync = EIO_FSYNC |
733 | aio_fdatasync = EIO_FDATASYNC |
877 | aio_fdatasync = EIO_FDATASYNC |
734 | PPCODE: |
878 | PPCODE: |
735 | { |
879 | { |
… | |
… | |
743 | REQ_SEND (req); |
887 | REQ_SEND (req); |
744 | } |
888 | } |
745 | |
889 | |
746 | void |
890 | void |
747 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
891 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
748 | PROTOTYPE: $$$$;$ |
|
|
749 | PPCODE: |
892 | PPCODE: |
750 | { |
893 | { |
751 | int fd = s_fileno_croak (fh, 0); |
894 | int fd = s_fileno_croak (fh, 0); |
752 | dREQ; |
895 | dREQ; |
753 | |
896 | |
… | |
… | |
761 | REQ_SEND (req); |
904 | REQ_SEND (req); |
762 | } |
905 | } |
763 | |
906 | |
764 | void |
907 | void |
765 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
908 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
766 | PROTOTYPE: $;$ |
|
|
767 | PPCODE: |
909 | PPCODE: |
768 | { |
910 | { |
769 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
911 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
770 | int fd = s_fileno_croak (fh, 0); |
912 | int fd = s_fileno_croak (fh, 0); |
771 | dREQ; |
913 | dREQ; |
… | |
… | |
793 | void |
935 | void |
794 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
936 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
795 | ALIAS: |
937 | ALIAS: |
796 | aio_read = EIO_READ |
938 | aio_read = EIO_READ |
797 | aio_write = EIO_WRITE |
939 | aio_write = EIO_WRITE |
798 | PROTOTYPE: $$$$$;$ |
|
|
799 | PPCODE: |
940 | PPCODE: |
800 | { |
941 | { |
801 | STRLEN svlen; |
942 | STRLEN svlen; |
802 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
943 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
803 | char *svptr = SvPVbyte (data, svlen); |
944 | char *svptr = SvPVbyte (data, svlen); |
… | |
… | |
844 | } |
985 | } |
845 | } |
986 | } |
846 | |
987 | |
847 | void |
988 | void |
848 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
989 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
849 | PROTOTYPE: $$;$ |
|
|
850 | PPCODE: |
990 | PPCODE: |
851 | { |
991 | { |
852 | SV *data; |
992 | SV *data; |
853 | dREQ; |
993 | dREQ; |
854 | |
994 | |
… | |
… | |
859 | REQ_SEND; |
999 | REQ_SEND; |
860 | } |
1000 | } |
861 | |
1001 | |
862 | void |
1002 | void |
863 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1003 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
864 | PROTOTYPE: $$$$;$ |
|
|
865 | PPCODE: |
1004 | PPCODE: |
866 | { |
1005 | { |
867 | int ifd = s_fileno_croak (in_fh , 0); |
1006 | int ifd = s_fileno_croak (in_fh , 0); |
868 | int ofd = s_fileno_croak (out_fh, 1); |
1007 | int ofd = s_fileno_croak (out_fh, 1); |
869 | dREQ; |
1008 | dREQ; |
… | |
… | |
879 | REQ_SEND; |
1018 | REQ_SEND; |
880 | } |
1019 | } |
881 | |
1020 | |
882 | void |
1021 | void |
883 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1022 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
884 | PROTOTYPE: $$$;$ |
|
|
885 | PPCODE: |
1023 | PPCODE: |
886 | { |
1024 | { |
887 | int fd = s_fileno_croak (fh, 0); |
1025 | int fd = s_fileno_croak (fh, 0); |
888 | dREQ; |
1026 | dREQ; |
889 | |
1027 | |
… | |
… | |
1090 | void |
1228 | void |
1091 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1229 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1092 | ALIAS: |
1230 | ALIAS: |
1093 | aio_mtouch = EIO_MTOUCH |
1231 | aio_mtouch = EIO_MTOUCH |
1094 | aio_msync = EIO_MSYNC |
1232 | aio_msync = EIO_MSYNC |
1095 | PROTOTYPE: $$$$;$ |
|
|
1096 | PPCODE: |
1233 | PPCODE: |
1097 | { |
1234 | { |
1098 | STRLEN svlen; |
1235 | STRLEN svlen; |
|
|
1236 | char *svptr = SvPVbyte (data, svlen); |
1099 | UV len = SvUV (length); |
1237 | UV len = SvUV (length); |
1100 | char *svptr = SvPVbyte (data, svlen); |
|
|
1101 | |
1238 | |
1102 | if (offset < 0) |
1239 | if (offset < 0) |
1103 | offset += svlen; |
1240 | offset += svlen; |
1104 | |
1241 | |
1105 | if (offset < 0 || offset > svlen) |
1242 | if (offset < 0 || offset > svlen) |
… | |
… | |
1110 | |
1247 | |
1111 | { |
1248 | { |
1112 | dREQ; |
1249 | dREQ; |
1113 | |
1250 | |
1114 | req->type = ix; |
1251 | req->type = ix; |
1115 | req->size = len; |
|
|
1116 | req->sv2 = SvREFCNT_inc (data); |
1252 | req->sv2 = SvREFCNT_inc (data); |
1117 | req->ptr2 = (char *)svptr + offset; |
1253 | req->ptr2 = (char *)svptr + offset; |
|
|
1254 | req->size = len; |
1118 | req->int1 = flags; |
1255 | req->int1 = flags; |
1119 | |
1256 | |
1120 | REQ_SEND; |
1257 | REQ_SEND; |
1121 | } |
1258 | } |
1122 | } |
1259 | } |
1123 | |
1260 | |
1124 | void |
1261 | void |
|
|
1262 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1263 | PPCODE: |
|
|
1264 | { |
|
|
1265 | STRLEN svlen; |
|
|
1266 | char *svptr = SvPVbyte (data, svlen); |
|
|
1267 | UV len = SvUV (length); |
|
|
1268 | |
|
|
1269 | if (offset < 0) |
|
|
1270 | offset += svlen; |
|
|
1271 | |
|
|
1272 | if (offset < 0 || offset > svlen) |
|
|
1273 | croak ("offset outside of scalar"); |
|
|
1274 | |
|
|
1275 | if (!SvOK (length) || len + offset > svlen) |
|
|
1276 | len = svlen - offset; |
|
|
1277 | |
|
|
1278 | { |
|
|
1279 | dREQ; |
|
|
1280 | |
|
|
1281 | req->type = EIO_MLOCK; |
|
|
1282 | req->sv2 = SvREFCNT_inc (data); |
|
|
1283 | req->ptr2 = (char *)svptr + offset; |
|
|
1284 | req->size = len; |
|
|
1285 | |
|
|
1286 | REQ_SEND; |
|
|
1287 | } |
|
|
1288 | } |
|
|
1289 | |
|
|
1290 | void |
|
|
1291 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1292 | PPCODE: |
|
|
1293 | { |
|
|
1294 | dREQ; |
|
|
1295 | |
|
|
1296 | req->type = EIO_MLOCKALL; |
|
|
1297 | req->int1 = flags; |
|
|
1298 | |
|
|
1299 | REQ_SEND; |
|
|
1300 | } |
|
|
1301 | |
|
|
1302 | void |
1125 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1303 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1126 | PPCODE: |
1304 | PPCODE: |
1127 | { |
1305 | { |
1128 | dREQ; |
1306 | dREQ; |
1129 | |
1307 | |
… | |
… | |
1133 | REQ_SEND; |
1311 | REQ_SEND; |
1134 | } |
1312 | } |
1135 | |
1313 | |
1136 | void |
1314 | void |
1137 | aio_group (SV *callback=&PL_sv_undef) |
1315 | aio_group (SV *callback=&PL_sv_undef) |
1138 | PROTOTYPE: ;$ |
|
|
1139 | PPCODE: |
1316 | PPCODE: |
1140 | { |
1317 | { |
1141 | dREQ; |
1318 | dREQ; |
1142 | |
1319 | |
1143 | req->type = EIO_GROUP; |
1320 | req->type = EIO_GROUP; |
… | |
… | |
1160 | REQ_SEND; |
1337 | REQ_SEND; |
1161 | } |
1338 | } |
1162 | |
1339 | |
1163 | int |
1340 | int |
1164 | aioreq_pri (int pri = 0) |
1341 | aioreq_pri (int pri = 0) |
1165 | PROTOTYPE: ;$ |
|
|
1166 | CODE: |
1342 | CODE: |
1167 | RETVAL = next_pri; |
1343 | RETVAL = next_pri; |
1168 | if (items > 0) |
1344 | if (items > 0) |
1169 | { |
1345 | { |
1170 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1346 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1182 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1358 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1183 | next_pri = nice; |
1359 | next_pri = nice; |
1184 | |
1360 | |
1185 | void |
1361 | void |
1186 | flush () |
1362 | flush () |
1187 | PROTOTYPE: |
|
|
1188 | CODE: |
1363 | CODE: |
1189 | while (eio_nreqs ()) |
1364 | while (eio_nreqs ()) |
1190 | { |
1365 | { |
1191 | poll_wait (); |
1366 | poll_wait (); |
1192 | poll_cb (); |
1367 | poll_cb (); |
1193 | } |
1368 | } |
1194 | |
1369 | |
1195 | int |
1370 | int |
1196 | poll() |
1371 | poll () |
1197 | PROTOTYPE: |
|
|
1198 | CODE: |
1372 | CODE: |
1199 | poll_wait (); |
1373 | poll_wait (); |
1200 | RETVAL = poll_cb (); |
1374 | RETVAL = poll_cb (); |
1201 | OUTPUT: |
1375 | OUTPUT: |
1202 | RETVAL |
1376 | RETVAL |
1203 | |
1377 | |
1204 | int |
1378 | int |
1205 | poll_fileno() |
1379 | poll_fileno () |
1206 | PROTOTYPE: |
|
|
1207 | CODE: |
1380 | CODE: |
1208 | RETVAL = s_epipe_fd (&respipe); |
1381 | RETVAL = s_epipe_fd (&respipe); |
1209 | OUTPUT: |
1382 | OUTPUT: |
1210 | RETVAL |
1383 | RETVAL |
1211 | |
1384 | |
1212 | int |
1385 | int |
1213 | poll_cb(...) |
1386 | poll_cb (...) |
1214 | PROTOTYPE: |
1387 | PROTOTYPE: |
1215 | CODE: |
1388 | CODE: |
1216 | RETVAL = poll_cb (); |
1389 | RETVAL = poll_cb (); |
1217 | OUTPUT: |
1390 | OUTPUT: |
1218 | RETVAL |
1391 | RETVAL |
1219 | |
1392 | |
1220 | void |
1393 | void |
1221 | poll_wait() |
1394 | poll_wait () |
1222 | PROTOTYPE: |
|
|
1223 | CODE: |
1395 | CODE: |
1224 | poll_wait (); |
1396 | poll_wait (); |
1225 | |
1397 | |
1226 | int |
1398 | int |
1227 | nreqs() |
1399 | nreqs () |
1228 | PROTOTYPE: |
|
|
1229 | CODE: |
1400 | CODE: |
1230 | RETVAL = eio_nreqs (); |
1401 | RETVAL = eio_nreqs (); |
1231 | OUTPUT: |
1402 | OUTPUT: |
1232 | RETVAL |
1403 | RETVAL |
1233 | |
1404 | |
1234 | int |
1405 | int |
1235 | nready() |
1406 | nready () |
1236 | PROTOTYPE: |
|
|
1237 | CODE: |
1407 | CODE: |
1238 | RETVAL = eio_nready (); |
1408 | RETVAL = eio_nready (); |
1239 | OUTPUT: |
1409 | OUTPUT: |
1240 | RETVAL |
1410 | RETVAL |
1241 | |
1411 | |
1242 | int |
1412 | int |
1243 | npending() |
1413 | npending () |
1244 | PROTOTYPE: |
|
|
1245 | CODE: |
1414 | CODE: |
1246 | RETVAL = eio_npending (); |
1415 | RETVAL = eio_npending (); |
1247 | OUTPUT: |
1416 | OUTPUT: |
1248 | RETVAL |
1417 | RETVAL |
1249 | |
1418 | |
1250 | int |
1419 | int |
1251 | nthreads() |
1420 | nthreads () |
1252 | PROTOTYPE: |
|
|
1253 | CODE: |
1421 | CODE: |
1254 | RETVAL = eio_nthreads (); |
1422 | RETVAL = eio_nthreads (); |
1255 | OUTPUT: |
1423 | OUTPUT: |
1256 | RETVAL |
1424 | RETVAL |
1257 | |
1425 | |
1258 | int |
1426 | int |
1259 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1427 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1260 | PROTOTYPE: $$$$ |
|
|
1261 | CODE: |
1428 | CODE: |
1262 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1263 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1429 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1264 | #else |
|
|
1265 | RETVAL = errno = ENOSYS; |
|
|
1266 | #endif |
|
|
1267 | OUTPUT: |
1430 | OUTPUT: |
1268 | RETVAL |
1431 | RETVAL |
1269 | |
1432 | |
1270 | ssize_t |
1433 | ssize_t |
1271 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1434 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1272 | PROTOTYPE: $$$$ |
|
|
1273 | CODE: |
1435 | CODE: |
1274 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1436 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1275 | OUTPUT: |
1437 | OUTPUT: |
1276 | RETVAL |
1438 | RETVAL |
1277 | |
1439 | |
|
|
1440 | void |
|
|
1441 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
|
|
1442 | PPCODE: |
|
|
1443 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1444 | { |
|
|
1445 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
|
|
1446 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
|
|
1447 | if (addr == (void *)-1) |
|
|
1448 | XSRETURN_NO; |
|
|
1449 | |
|
|
1450 | sv_force_normal (scalar); |
|
|
1451 | |
|
|
1452 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
|
|
1453 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
|
|
1454 | ->mg_obj = (SV *)length; |
|
|
1455 | |
|
|
1456 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1457 | |
|
|
1458 | if (!(prot & PROT_WRITE)) |
|
|
1459 | SvREADONLY_on (scalar); |
|
|
1460 | |
|
|
1461 | if (SvLEN (scalar)) |
|
|
1462 | Safefree (SvPVX (scalar)); |
|
|
1463 | |
|
|
1464 | SvPVX (scalar) = (char *)addr; |
|
|
1465 | SvCUR_set (scalar, length); |
|
|
1466 | SvLEN_set (scalar, 0); |
|
|
1467 | SvPOK_only (scalar); |
|
|
1468 | |
|
|
1469 | XSRETURN_YES; |
|
|
1470 | } |
|
|
1471 | |
|
|
1472 | void |
|
|
1473 | munmap (SV *scalar) |
|
|
1474 | CODE: |
|
|
1475 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1476 | |
|
|
1477 | int |
|
|
1478 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
|
|
1479 | ALIAS: |
|
|
1480 | mprotect = 1 |
|
|
1481 | CODE: |
|
|
1482 | { |
|
|
1483 | STRLEN svlen; |
|
|
1484 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1485 | size_t len = SvUV (length); |
|
|
1486 | |
|
|
1487 | if (offset < 0) |
|
|
1488 | offset += svlen; |
|
|
1489 | |
|
|
1490 | if (offset < 0 || offset > svlen) |
|
|
1491 | croak ("offset outside of scalar"); |
|
|
1492 | |
|
|
1493 | if (!SvOK (length) || len + offset > svlen) |
|
|
1494 | len = svlen - offset; |
|
|
1495 | |
|
|
1496 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1497 | eio_page_align (&addr, &len); |
|
|
1498 | |
|
|
1499 | switch (ix) |
|
|
1500 | { |
|
|
1501 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
|
|
1502 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
|
|
1503 | } |
|
|
1504 | } |
|
|
1505 | OUTPUT: |
|
|
1506 | RETVAL |
|
|
1507 | |
|
|
1508 | int |
|
|
1509 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
|
|
1510 | CODE: |
|
|
1511 | { |
|
|
1512 | STRLEN svlen; |
|
|
1513 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1514 | size_t len = SvUV (length); |
|
|
1515 | |
|
|
1516 | if (offset < 0) |
|
|
1517 | offset += svlen; |
|
|
1518 | |
|
|
1519 | if (offset < 0 || offset > svlen) |
|
|
1520 | croak ("offset outside of scalar"); |
|
|
1521 | |
|
|
1522 | if (!SvOK (length) || len + offset > svlen) |
|
|
1523 | len = svlen - offset; |
|
|
1524 | |
|
|
1525 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1526 | eio_page_align (&addr, &len); |
|
|
1527 | #if _POSIX_MEMLOCK |
|
|
1528 | RETVAL = munlock (addr, len); |
|
|
1529 | #else |
|
|
1530 | RETVAL = ((errno = ENOSYS), -1); |
|
|
1531 | #endif |
|
|
1532 | } |
|
|
1533 | OUTPUT: |
|
|
1534 | RETVAL |
|
|
1535 | |
|
|
1536 | int |
|
|
1537 | munlockall () |
|
|
1538 | CODE: |
|
|
1539 | #if _POSIX_MEMLOCK |
|
|
1540 | munlockall (); |
|
|
1541 | #else |
|
|
1542 | RETVAL = -1; |
|
|
1543 | errno = ENOSYS; |
|
|
1544 | #endif |
|
|
1545 | OUTPUT: |
|
|
1546 | RETVAL |
|
|
1547 | |
1278 | void _on_next_submit (SV *cb) |
1548 | void _on_next_submit (SV *cb) |
1279 | CODE: |
1549 | CODE: |
1280 | SvREFCNT_dec (on_next_submit); |
1550 | SvREFCNT_dec (on_next_submit); |
1281 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1551 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1282 | |
1552 | |