… | |
… | |
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 |
… | |
… | |
169 | #ifndef ST_NODIRATIME |
206 | #ifndef ST_NODIRATIME |
170 | # define ST_NODIRATIME 0 |
207 | # define ST_NODIRATIME 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 |
|
|
175 | |
|
|
176 | #ifndef MCL_CURRENT |
|
|
177 | # define MCL_CURRENT 0 |
|
|
178 | #endif |
|
|
179 | #ifndef MCL_FUTURE |
|
|
180 | # define MCL_FUTURE 0 |
|
|
181 | #endif |
211 | #endif |
182 | |
212 | |
183 | #ifndef MAP_ANONYMOUS |
213 | #ifndef MAP_ANONYMOUS |
184 | # ifdef MAP_ANON |
214 | # ifdef MAP_ANON |
185 | # define MAP_ANONYMOUS MAP_ANON |
215 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
304 | } |
334 | } |
305 | } |
335 | } |
306 | |
336 | |
307 | static int req_invoke (eio_req *req) |
337 | static int req_invoke (eio_req *req) |
308 | { |
338 | { |
309 | dSP; |
|
|
310 | |
|
|
311 | if (req->flags & FLAG_SV2_RO_OFF) |
339 | if (req->flags & FLAG_SV2_RO_OFF) |
312 | SvREADONLY_off (req->sv2); |
340 | SvREADONLY_off (req->sv2); |
313 | |
341 | |
314 | if (!EIO_CANCELLED (req) && req->callback) |
342 | if (!EIO_CANCELLED (req) && req->callback) |
315 | { |
343 | { |
|
|
344 | dSP; |
|
|
345 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
346 | SV *sv_result; |
|
|
347 | |
316 | ENTER; |
348 | ENTER; |
317 | SAVETMPS; |
349 | SAVETMPS; |
318 | PUSHMARK (SP); |
350 | PUSHMARK (SP); |
319 | EXTEND (SP, 1); |
351 | EXTEND (SP, 1); |
|
|
352 | |
|
|
353 | /* do not recreate the result IV from scratch each time */ |
|
|
354 | if (expect_true (sv_result_cache)) |
|
|
355 | { |
|
|
356 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
357 | SvIV_set (sv_result, req->result); |
|
|
358 | } |
|
|
359 | else |
|
|
360 | { |
|
|
361 | sv_result = newSViv (req->result); |
|
|
362 | SvREADONLY_on (sv_result); |
|
|
363 | } |
320 | |
364 | |
321 | switch (req->type) |
365 | switch (req->type) |
322 | { |
366 | { |
323 | case EIO_READDIR: |
367 | case EIO_READDIR: |
324 | { |
368 | { |
… | |
… | |
469 | case EIO_LSTAT: |
513 | case EIO_LSTAT: |
470 | case EIO_FSTAT: |
514 | case EIO_FSTAT: |
471 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
515 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
472 | PL_laststatval = req->result; |
516 | PL_laststatval = req->result; |
473 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
517 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
474 | PUSHs (sv_2mortal (newSViv (req->result))); |
518 | PUSHs (sv_result); |
475 | break; |
519 | break; |
476 | |
520 | |
477 | case EIO_READ: |
521 | case EIO_READ: |
478 | { |
522 | { |
479 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
523 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
480 | *SvEND (req->sv2) = 0; |
524 | *SvEND (req->sv2) = 0; |
481 | SvPOK_only (req->sv2); |
525 | SvPOK_only (req->sv2); |
482 | SvSETMAGIC (req->sv2); |
526 | SvSETMAGIC (req->sv2); |
483 | PUSHs (sv_2mortal (newSViv (req->result))); |
527 | PUSHs (sv_result); |
484 | } |
528 | } |
485 | break; |
529 | break; |
486 | |
530 | |
487 | case EIO_DUP2: |
531 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
488 | if (req->result > 0) |
532 | if (req->result > 0) |
489 | req->result = 0; |
533 | SvIV_set (sv_result, 0); |
490 | /* FALLTHROUGH */ |
534 | /* FALLTHROUGH */ |
491 | |
535 | |
492 | default: |
536 | default: |
493 | PUSHs (sv_2mortal (newSViv (req->result))); |
537 | PUSHs (sv_result); |
494 | break; |
538 | break; |
495 | } |
539 | } |
496 | |
540 | |
497 | errno = req->errorno; |
541 | errno = req->errorno; |
498 | |
542 | |
499 | PUTBACK; |
543 | PUTBACK; |
500 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
544 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
501 | SPAGAIN; |
545 | SPAGAIN; |
|
|
546 | |
|
|
547 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
548 | SvREFCNT_dec (sv_result); |
|
|
549 | else |
|
|
550 | sv_result_cache = sv_result; |
502 | |
551 | |
503 | FREETMPS; |
552 | FREETMPS; |
504 | LEAVE; |
553 | LEAVE; |
505 | |
554 | |
506 | PUTBACK; |
555 | PUTBACK; |
… | |
… | |
587 | /*****************************************************************************/ |
636 | /*****************************************************************************/ |
588 | |
637 | |
589 | #if !_POSIX_MAPPED_FILES |
638 | #if !_POSIX_MAPPED_FILES |
590 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
639 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
591 | # define munmap(addr,length) (errno = ENOSYS, -1) |
640 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
641 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
642 | # define PROT_NONE 0 |
|
|
643 | # define PROT_WRITE 0 |
|
|
644 | # define MAP_PRIVATE 0 |
|
|
645 | # define MAP_SHARED 0 |
|
|
646 | # define MAP_FIXED 0 |
592 | #endif |
647 | #endif |
593 | |
648 | |
594 | #define MMAP_MAGIC PERL_MAGIC_ext |
649 | #define MMAP_MAGIC PERL_MAGIC_ext |
595 | |
650 | |
596 | static int |
651 | static int |
… | |
… | |
601 | errno = old_errno; |
656 | errno = old_errno; |
602 | |
657 | |
603 | mg->mg_obj = 0; /* just in case */ |
658 | mg->mg_obj = 0; /* just in case */ |
604 | |
659 | |
605 | SvREADONLY_off (sv); |
660 | SvREADONLY_off (sv); |
|
|
661 | |
|
|
662 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
663 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
664 | |
606 | SvCUR_set (sv, 0); |
665 | SvCUR_set (sv, 0); |
607 | SvLEN_set (sv, 0); |
|
|
608 | SvPVX (sv) = 0; |
666 | SvPVX (sv) = 0; |
609 | SvOK_off (sv); |
667 | SvOK_off (sv); |
610 | |
668 | |
611 | return 0; |
669 | return 0; |
612 | } |
670 | } |
… | |
… | |
662 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
720 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
663 | const_iv (EXDEV) |
721 | const_iv (EXDEV) |
664 | const_iv (ENOSYS) |
722 | const_iv (ENOSYS) |
665 | const_iv (O_RDONLY) |
723 | const_iv (O_RDONLY) |
666 | const_iv (O_WRONLY) |
724 | const_iv (O_WRONLY) |
|
|
725 | const_iv (O_RDWR) |
667 | const_iv (O_CREAT) |
726 | const_iv (O_CREAT) |
668 | const_iv (O_TRUNC) |
727 | const_iv (O_TRUNC) |
|
|
728 | const_iv (O_EXCL) |
|
|
729 | const_iv (O_APPEND) |
669 | #ifndef _WIN32 |
730 | #ifndef _WIN32 |
670 | const_iv (S_IFIFO) |
731 | const_iv (S_IFIFO) |
671 | #endif |
732 | #endif |
672 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
733 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
673 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
734 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
674 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
735 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
675 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
736 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
676 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
737 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
677 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
738 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
|
|
739 | |
|
|
740 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
741 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
742 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
743 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
744 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
678 | |
745 | |
679 | const_iv (ST_RDONLY) |
746 | const_iv (ST_RDONLY) |
680 | const_iv (ST_NOSUID) |
747 | const_iv (ST_NOSUID) |
681 | const_iv (ST_NODEV) |
748 | const_iv (ST_NODEV) |
682 | const_iv (ST_NOEXEC) |
749 | const_iv (ST_NOEXEC) |
… | |
… | |
687 | const_iv (ST_IMMUTABLE) |
754 | const_iv (ST_IMMUTABLE) |
688 | const_iv (ST_NOATIME) |
755 | const_iv (ST_NOATIME) |
689 | const_iv (ST_NODIRATIME) |
756 | const_iv (ST_NODIRATIME) |
690 | const_iv (ST_RELATIME) |
757 | const_iv (ST_RELATIME) |
691 | |
758 | |
|
|
759 | const_iv (PROT_NONE) |
692 | const_iv (PROT_EXEC) |
760 | const_iv (PROT_EXEC) |
693 | const_iv (PROT_NONE) |
|
|
694 | const_iv (PROT_READ) |
761 | const_iv (PROT_READ) |
695 | const_iv (PROT_WRITE) |
762 | const_iv (PROT_WRITE) |
696 | |
763 | |
697 | /*const_iv (MAP_FIXED)*/ |
764 | /*const_iv (MAP_FIXED)*/ |
698 | const_iv (MAP_PRIVATE) |
765 | const_iv (MAP_PRIVATE) |
… | |
… | |
704 | const_iv (MAP_LOCKED) |
771 | const_iv (MAP_LOCKED) |
705 | const_iv (MAP_NORESERVE) |
772 | const_iv (MAP_NORESERVE) |
706 | const_iv (MAP_POPULATE) |
773 | const_iv (MAP_POPULATE) |
707 | const_iv (MAP_NONBLOCK) |
774 | const_iv (MAP_NONBLOCK) |
708 | |
775 | |
709 | const_iv (MCL_FUTURE) |
776 | const_eio (MCL_FUTURE) |
710 | const_iv (MCL_CURRENT) |
777 | const_eio (MCL_CURRENT) |
711 | |
778 | |
712 | const_eio (MS_ASYNC) |
779 | const_eio (MS_ASYNC) |
713 | const_eio (MS_INVALIDATE) |
780 | const_eio (MS_INVALIDATE) |
714 | const_eio (MS_SYNC) |
781 | const_eio (MS_SYNC) |
715 | |
782 | |
… | |
… | |
789 | CODE: |
856 | CODE: |
790 | max_outstanding = maxreqs; |
857 | max_outstanding = maxreqs; |
791 | |
858 | |
792 | void |
859 | void |
793 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
860 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
794 | PROTOTYPE: $$$;$ |
|
|
795 | PPCODE: |
861 | PPCODE: |
796 | { |
862 | { |
797 | dREQ; |
863 | dREQ; |
798 | |
864 | |
799 | req->type = EIO_OPEN; |
865 | req->type = EIO_OPEN; |
… | |
… | |
805 | REQ_SEND; |
871 | REQ_SEND; |
806 | } |
872 | } |
807 | |
873 | |
808 | void |
874 | void |
809 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
875 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
810 | PROTOTYPE: $;$ |
|
|
811 | ALIAS: |
876 | ALIAS: |
812 | aio_fsync = EIO_FSYNC |
877 | aio_fsync = EIO_FSYNC |
813 | aio_fdatasync = EIO_FDATASYNC |
878 | aio_fdatasync = EIO_FDATASYNC |
814 | PPCODE: |
879 | PPCODE: |
815 | { |
880 | { |
… | |
… | |
823 | REQ_SEND (req); |
888 | REQ_SEND (req); |
824 | } |
889 | } |
825 | |
890 | |
826 | void |
891 | void |
827 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
892 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
828 | PROTOTYPE: $$$$;$ |
|
|
829 | PPCODE: |
893 | PPCODE: |
830 | { |
894 | { |
831 | int fd = s_fileno_croak (fh, 0); |
895 | int fd = s_fileno_croak (fh, 0); |
832 | dREQ; |
896 | dREQ; |
833 | |
897 | |
… | |
… | |
841 | REQ_SEND (req); |
905 | REQ_SEND (req); |
842 | } |
906 | } |
843 | |
907 | |
844 | void |
908 | void |
845 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
909 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
846 | PROTOTYPE: $;$ |
|
|
847 | PPCODE: |
910 | PPCODE: |
848 | { |
911 | { |
849 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
912 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
850 | int fd = s_fileno_croak (fh, 0); |
913 | int fd = s_fileno_croak (fh, 0); |
851 | dREQ; |
914 | dREQ; |
… | |
… | |
873 | void |
936 | void |
874 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
937 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
875 | ALIAS: |
938 | ALIAS: |
876 | aio_read = EIO_READ |
939 | aio_read = EIO_READ |
877 | aio_write = EIO_WRITE |
940 | aio_write = EIO_WRITE |
878 | PROTOTYPE: $$$$$;$ |
|
|
879 | PPCODE: |
941 | PPCODE: |
880 | { |
942 | { |
881 | STRLEN svlen; |
943 | STRLEN svlen; |
882 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
944 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
883 | char *svptr = SvPVbyte (data, svlen); |
945 | char *svptr = SvPVbyte (data, svlen); |
… | |
… | |
924 | } |
986 | } |
925 | } |
987 | } |
926 | |
988 | |
927 | void |
989 | void |
928 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
990 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
929 | PROTOTYPE: $$;$ |
|
|
930 | PPCODE: |
991 | PPCODE: |
931 | { |
992 | { |
932 | SV *data; |
993 | SV *data; |
933 | dREQ; |
994 | dREQ; |
934 | |
995 | |
… | |
… | |
939 | REQ_SEND; |
1000 | REQ_SEND; |
940 | } |
1001 | } |
941 | |
1002 | |
942 | void |
1003 | void |
943 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1004 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
944 | PROTOTYPE: $$$$;$ |
|
|
945 | PPCODE: |
1005 | PPCODE: |
946 | { |
1006 | { |
947 | int ifd = s_fileno_croak (in_fh , 0); |
1007 | int ifd = s_fileno_croak (in_fh , 0); |
948 | int ofd = s_fileno_croak (out_fh, 1); |
1008 | int ofd = s_fileno_croak (out_fh, 1); |
949 | dREQ; |
1009 | dREQ; |
… | |
… | |
959 | REQ_SEND; |
1019 | REQ_SEND; |
960 | } |
1020 | } |
961 | |
1021 | |
962 | void |
1022 | void |
963 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1023 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
964 | PROTOTYPE: $$$;$ |
|
|
965 | PPCODE: |
1024 | PPCODE: |
966 | { |
1025 | { |
967 | int fd = s_fileno_croak (fh, 0); |
1026 | int fd = s_fileno_croak (fh, 0); |
968 | dREQ; |
1027 | dREQ; |
969 | |
1028 | |
… | |
… | |
1170 | void |
1229 | void |
1171 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1230 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1172 | ALIAS: |
1231 | ALIAS: |
1173 | aio_mtouch = EIO_MTOUCH |
1232 | aio_mtouch = EIO_MTOUCH |
1174 | aio_msync = EIO_MSYNC |
1233 | aio_msync = EIO_MSYNC |
1175 | PROTOTYPE: $$$$;$ |
|
|
1176 | PPCODE: |
1234 | PPCODE: |
1177 | { |
1235 | { |
1178 | STRLEN svlen; |
1236 | STRLEN svlen; |
|
|
1237 | char *svptr = SvPVbyte (data, svlen); |
1179 | UV len = SvUV (length); |
1238 | UV len = SvUV (length); |
1180 | char *svptr = SvPVbyte (data, svlen); |
|
|
1181 | |
1239 | |
1182 | if (offset < 0) |
1240 | if (offset < 0) |
1183 | offset += svlen; |
1241 | offset += svlen; |
1184 | |
1242 | |
1185 | if (offset < 0 || offset > svlen) |
1243 | if (offset < 0 || offset > svlen) |
… | |
… | |
1190 | |
1248 | |
1191 | { |
1249 | { |
1192 | dREQ; |
1250 | dREQ; |
1193 | |
1251 | |
1194 | req->type = ix; |
1252 | req->type = ix; |
1195 | req->size = len; |
|
|
1196 | req->sv2 = SvREFCNT_inc (data); |
1253 | req->sv2 = SvREFCNT_inc (data); |
1197 | req->ptr2 = (char *)svptr + offset; |
1254 | req->ptr2 = (char *)svptr + offset; |
|
|
1255 | req->size = len; |
1198 | req->int1 = flags; |
1256 | req->int1 = flags; |
1199 | |
1257 | |
1200 | REQ_SEND; |
1258 | REQ_SEND; |
1201 | } |
1259 | } |
1202 | } |
1260 | } |
1203 | |
1261 | |
1204 | void |
1262 | void |
|
|
1263 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1264 | PPCODE: |
|
|
1265 | { |
|
|
1266 | STRLEN svlen; |
|
|
1267 | char *svptr = SvPVbyte (data, svlen); |
|
|
1268 | UV len = SvUV (length); |
|
|
1269 | |
|
|
1270 | if (offset < 0) |
|
|
1271 | offset += svlen; |
|
|
1272 | |
|
|
1273 | if (offset < 0 || offset > svlen) |
|
|
1274 | croak ("offset outside of scalar"); |
|
|
1275 | |
|
|
1276 | if (!SvOK (length) || len + offset > svlen) |
|
|
1277 | len = svlen - offset; |
|
|
1278 | |
|
|
1279 | { |
|
|
1280 | dREQ; |
|
|
1281 | |
|
|
1282 | req->type = EIO_MLOCK; |
|
|
1283 | req->sv2 = SvREFCNT_inc (data); |
|
|
1284 | req->ptr2 = (char *)svptr + offset; |
|
|
1285 | req->size = len; |
|
|
1286 | |
|
|
1287 | REQ_SEND; |
|
|
1288 | } |
|
|
1289 | } |
|
|
1290 | |
|
|
1291 | void |
|
|
1292 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1293 | PPCODE: |
|
|
1294 | { |
|
|
1295 | dREQ; |
|
|
1296 | |
|
|
1297 | req->type = EIO_MLOCKALL; |
|
|
1298 | req->int1 = flags; |
|
|
1299 | |
|
|
1300 | REQ_SEND; |
|
|
1301 | } |
|
|
1302 | |
|
|
1303 | void |
1205 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1304 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1206 | PPCODE: |
1305 | PPCODE: |
1207 | { |
1306 | { |
1208 | dREQ; |
1307 | dREQ; |
1209 | |
1308 | |
… | |
… | |
1213 | REQ_SEND; |
1312 | REQ_SEND; |
1214 | } |
1313 | } |
1215 | |
1314 | |
1216 | void |
1315 | void |
1217 | aio_group (SV *callback=&PL_sv_undef) |
1316 | aio_group (SV *callback=&PL_sv_undef) |
1218 | PROTOTYPE: ;$ |
|
|
1219 | PPCODE: |
1317 | PPCODE: |
1220 | { |
1318 | { |
1221 | dREQ; |
1319 | dREQ; |
1222 | |
1320 | |
1223 | req->type = EIO_GROUP; |
1321 | req->type = EIO_GROUP; |
… | |
… | |
1240 | REQ_SEND; |
1338 | REQ_SEND; |
1241 | } |
1339 | } |
1242 | |
1340 | |
1243 | int |
1341 | int |
1244 | aioreq_pri (int pri = 0) |
1342 | aioreq_pri (int pri = 0) |
1245 | PROTOTYPE: ;$ |
|
|
1246 | CODE: |
1343 | CODE: |
1247 | RETVAL = next_pri; |
1344 | RETVAL = next_pri; |
1248 | if (items > 0) |
1345 | if (items > 0) |
1249 | { |
1346 | { |
1250 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1347 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1262 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1359 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1263 | next_pri = nice; |
1360 | next_pri = nice; |
1264 | |
1361 | |
1265 | void |
1362 | void |
1266 | flush () |
1363 | flush () |
1267 | PROTOTYPE: |
|
|
1268 | CODE: |
1364 | CODE: |
1269 | while (eio_nreqs ()) |
1365 | while (eio_nreqs ()) |
1270 | { |
1366 | { |
1271 | poll_wait (); |
1367 | poll_wait (); |
1272 | poll_cb (); |
1368 | poll_cb (); |
1273 | } |
1369 | } |
1274 | |
1370 | |
1275 | int |
1371 | int |
1276 | poll() |
1372 | poll () |
1277 | PROTOTYPE: |
|
|
1278 | CODE: |
1373 | CODE: |
1279 | poll_wait (); |
1374 | poll_wait (); |
1280 | RETVAL = poll_cb (); |
1375 | RETVAL = poll_cb (); |
1281 | OUTPUT: |
1376 | OUTPUT: |
1282 | RETVAL |
1377 | RETVAL |
1283 | |
1378 | |
1284 | int |
1379 | int |
1285 | poll_fileno() |
1380 | poll_fileno () |
1286 | PROTOTYPE: |
|
|
1287 | CODE: |
1381 | CODE: |
1288 | RETVAL = s_epipe_fd (&respipe); |
1382 | RETVAL = s_epipe_fd (&respipe); |
1289 | OUTPUT: |
1383 | OUTPUT: |
1290 | RETVAL |
1384 | RETVAL |
1291 | |
1385 | |
1292 | int |
1386 | int |
1293 | poll_cb(...) |
1387 | poll_cb (...) |
1294 | PROTOTYPE: |
1388 | PROTOTYPE: |
1295 | CODE: |
1389 | CODE: |
1296 | RETVAL = poll_cb (); |
1390 | RETVAL = poll_cb (); |
1297 | OUTPUT: |
1391 | OUTPUT: |
1298 | RETVAL |
1392 | RETVAL |
1299 | |
1393 | |
1300 | void |
1394 | void |
1301 | poll_wait() |
1395 | poll_wait () |
1302 | PROTOTYPE: |
|
|
1303 | CODE: |
1396 | CODE: |
1304 | poll_wait (); |
1397 | poll_wait (); |
1305 | |
1398 | |
1306 | int |
1399 | int |
1307 | nreqs() |
1400 | nreqs () |
1308 | PROTOTYPE: |
|
|
1309 | CODE: |
1401 | CODE: |
1310 | RETVAL = eio_nreqs (); |
1402 | RETVAL = eio_nreqs (); |
1311 | OUTPUT: |
1403 | OUTPUT: |
1312 | RETVAL |
1404 | RETVAL |
1313 | |
1405 | |
1314 | int |
1406 | int |
1315 | nready() |
1407 | nready () |
1316 | PROTOTYPE: |
|
|
1317 | CODE: |
1408 | CODE: |
1318 | RETVAL = eio_nready (); |
1409 | RETVAL = eio_nready (); |
1319 | OUTPUT: |
1410 | OUTPUT: |
1320 | RETVAL |
1411 | RETVAL |
1321 | |
1412 | |
1322 | int |
1413 | int |
1323 | npending() |
1414 | npending () |
1324 | PROTOTYPE: |
|
|
1325 | CODE: |
1415 | CODE: |
1326 | RETVAL = eio_npending (); |
1416 | RETVAL = eio_npending (); |
1327 | OUTPUT: |
1417 | OUTPUT: |
1328 | RETVAL |
1418 | RETVAL |
1329 | |
1419 | |
1330 | int |
1420 | int |
1331 | nthreads() |
1421 | nthreads () |
1332 | PROTOTYPE: |
|
|
1333 | CODE: |
1422 | CODE: |
1334 | RETVAL = eio_nthreads (); |
1423 | RETVAL = eio_nthreads (); |
1335 | OUTPUT: |
1424 | OUTPUT: |
1336 | RETVAL |
1425 | RETVAL |
1337 | |
1426 | |
1338 | int |
1427 | int |
1339 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1428 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1340 | PROTOTYPE: $$$$ |
|
|
1341 | CODE: |
1429 | CODE: |
1342 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1343 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1430 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1344 | #else |
|
|
1345 | RETVAL = errno = ENOSYS; /* yes, this is actually correct */ |
|
|
1346 | #endif |
|
|
1347 | OUTPUT: |
1431 | OUTPUT: |
1348 | RETVAL |
1432 | RETVAL |
1349 | |
1433 | |
1350 | ssize_t |
1434 | ssize_t |
1351 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1435 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1352 | PROTOTYPE: $$$$ |
|
|
1353 | CODE: |
1436 | CODE: |
1354 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1437 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1355 | OUTPUT: |
1438 | OUTPUT: |
1356 | RETVAL |
1439 | RETVAL |
1357 | |
1440 | |
1358 | void |
1441 | void |
1359 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1442 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1360 | PROTOTYPE: $$$$$;$ |
|
|
1361 | PPCODE: |
1443 | PPCODE: |
1362 | sv_unmagic (scalar, MMAP_MAGIC); |
1444 | sv_unmagic (scalar, MMAP_MAGIC); |
1363 | { |
1445 | { |
1364 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1446 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1365 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1447 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1366 | if (addr == (void *)-1) |
1448 | if (addr == (void *)-1) |
1367 | XSRETURN_NO; |
1449 | XSRETURN_NO; |
1368 | |
1450 | |
|
|
1451 | sv_force_normal (scalar); |
|
|
1452 | |
1369 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
1453 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
1370 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
1454 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
1371 | ->mg_obj = (SV *)length; |
1455 | ->mg_obj = (SV *)length; |
1372 | |
1456 | |
1373 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
1457 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1458 | |
1374 | if (!(prot & PROT_WRITE)) |
1459 | if (!(prot & PROT_WRITE)) |
1375 | SvREADONLY_on (scalar); |
1460 | SvREADONLY_on (scalar); |
|
|
1461 | |
|
|
1462 | if (SvLEN (scalar)) |
|
|
1463 | Safefree (SvPVX (scalar)); |
1376 | |
1464 | |
1377 | SvPVX (scalar) = (char *)addr; |
1465 | SvPVX (scalar) = (char *)addr; |
1378 | SvCUR_set (scalar, length); |
1466 | SvCUR_set (scalar, length); |
1379 | SvLEN_set (scalar, 0); |
1467 | SvLEN_set (scalar, 0); |
1380 | SvPOK_only (scalar); |
1468 | SvPOK_only (scalar); |
… | |
… | |
1382 | XSRETURN_YES; |
1470 | XSRETURN_YES; |
1383 | } |
1471 | } |
1384 | |
1472 | |
1385 | void |
1473 | void |
1386 | munmap (SV *scalar) |
1474 | munmap (SV *scalar) |
1387 | PROTOTYPE: $ |
|
|
1388 | CODE: |
1475 | CODE: |
1389 | sv_unmagic (scalar, MMAP_MAGIC); |
1476 | sv_unmagic (scalar, MMAP_MAGIC); |
1390 | |
1477 | |
1391 | int |
1478 | int |
1392 | mlockall (int flags) |
1479 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
1393 | PROTOTYPE: $ |
1480 | ALIAS: |
|
|
1481 | mprotect = 1 |
1394 | CODE: |
1482 | CODE: |
|
|
1483 | { |
|
|
1484 | STRLEN svlen; |
|
|
1485 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1486 | size_t len = SvUV (length); |
|
|
1487 | |
|
|
1488 | if (offset < 0) |
|
|
1489 | offset += svlen; |
|
|
1490 | |
|
|
1491 | if (offset < 0 || offset > svlen) |
|
|
1492 | croak ("offset outside of scalar"); |
|
|
1493 | |
|
|
1494 | if (!SvOK (length) || len + offset > svlen) |
|
|
1495 | len = svlen - offset; |
|
|
1496 | |
|
|
1497 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1498 | eio_page_align (&addr, &len); |
|
|
1499 | |
|
|
1500 | switch (ix) |
|
|
1501 | { |
|
|
1502 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
|
|
1503 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
|
|
1504 | } |
|
|
1505 | } |
|
|
1506 | OUTPUT: |
|
|
1507 | RETVAL |
|
|
1508 | |
|
|
1509 | int |
|
|
1510 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
|
|
1511 | CODE: |
|
|
1512 | { |
|
|
1513 | STRLEN svlen; |
|
|
1514 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1515 | size_t len = SvUV (length); |
|
|
1516 | |
|
|
1517 | if (offset < 0) |
|
|
1518 | offset += svlen; |
|
|
1519 | |
|
|
1520 | if (offset < 0 || offset > svlen) |
|
|
1521 | croak ("offset outside of scalar"); |
|
|
1522 | |
|
|
1523 | if (!SvOK (length) || len + offset > svlen) |
|
|
1524 | len = svlen - offset; |
|
|
1525 | |
|
|
1526 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1527 | eio_page_align (&addr, &len); |
1395 | #if _POSIX_MEMLOCK |
1528 | #if _POSIX_MEMLOCK |
1396 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
1529 | RETVAL = munlock (addr, len); |
1397 | extern int mallopt (int, int); |
|
|
1398 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1399 | #endif |
|
|
1400 | mlockall (flags); |
|
|
1401 | #else |
1530 | #else |
1402 | RETVAL = -1; |
1531 | RETVAL = ((errno = ENOSYS), -1); |
1403 | errno = ENOSYS; |
|
|
1404 | #endif |
1532 | #endif |
|
|
1533 | } |
1405 | OUTPUT: |
1534 | OUTPUT: |
1406 | RETVAL |
1535 | RETVAL |
1407 | |
1536 | |
1408 | int |
1537 | int |
1409 | munlockall () |
1538 | munlockall () |
1410 | PROTOTYPE: |
|
|
1411 | CODE: |
1539 | CODE: |
1412 | #if _POSIX_MEMLOCK |
1540 | #if _POSIX_MEMLOCK |
1413 | munlockall (); |
1541 | munlockall (); |
1414 | #else |
1542 | #else |
1415 | RETVAL = -1; |
1543 | RETVAL = -1; |