… | |
… | |
122 | |
122 | |
123 | #include "libeio/eio.h" |
123 | #include "libeio/eio.h" |
124 | |
124 | |
125 | #ifndef POSIX_FADV_NORMAL |
125 | #ifndef POSIX_FADV_NORMAL |
126 | # define POSIX_FADV_NORMAL 0 |
126 | # define POSIX_FADV_NORMAL 0 |
127 | # define NO_FADVISE 1 |
|
|
128 | #endif |
127 | #endif |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
128 | #ifndef POSIX_FADV_SEQUENTIAL |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
129 | # define POSIX_FADV_SEQUENTIAL 0 |
131 | #endif |
130 | #endif |
132 | #ifndef POSIX_FADV_RANDOM |
131 | #ifndef POSIX_FADV_RANDOM |
… | |
… | |
140 | #endif |
139 | #endif |
141 | #ifndef POSIX_FADV_DONTNEED |
140 | #ifndef POSIX_FADV_DONTNEED |
142 | # define POSIX_FADV_DONTNEED 0 |
141 | # define POSIX_FADV_DONTNEED 0 |
143 | #endif |
142 | #endif |
144 | |
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 | |
145 | #ifndef ST_NODEV |
181 | #ifndef ST_NODEV |
146 | # define ST_NODEV 0 |
182 | # define ST_NODEV 0 |
147 | #endif |
183 | #endif |
148 | #ifndef ST_NOEXEC |
184 | #ifndef ST_NOEXEC |
149 | # define ST_NOEXEC 0 |
185 | # define ST_NOEXEC 0 |
… | |
… | |
169 | #ifndef ST_NODIRATIME |
205 | #ifndef ST_NODIRATIME |
170 | # define ST_NODIRATIME 0 |
206 | # define ST_NODIRATIME 0 |
171 | #endif |
207 | #endif |
172 | #ifndef ST_RELATIME |
208 | #ifndef ST_RELATIME |
173 | # define ST_RELATIME 0 |
209 | # 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 |
210 | #endif |
182 | |
211 | |
183 | #ifndef MAP_ANONYMOUS |
212 | #ifndef MAP_ANONYMOUS |
184 | # ifdef MAP_ANON |
213 | # ifdef MAP_ANON |
185 | # define MAP_ANONYMOUS MAP_ANON |
214 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
304 | } |
333 | } |
305 | } |
334 | } |
306 | |
335 | |
307 | static int req_invoke (eio_req *req) |
336 | static int req_invoke (eio_req *req) |
308 | { |
337 | { |
309 | dSP; |
|
|
310 | |
|
|
311 | if (req->flags & FLAG_SV2_RO_OFF) |
338 | if (req->flags & FLAG_SV2_RO_OFF) |
312 | SvREADONLY_off (req->sv2); |
339 | SvREADONLY_off (req->sv2); |
313 | |
340 | |
314 | if (!EIO_CANCELLED (req) && req->callback) |
341 | if (!EIO_CANCELLED (req) && req->callback) |
315 | { |
342 | { |
|
|
343 | dSP; |
316 | static SV *sv_result_cache; /* caches the result integer SV */ |
344 | static SV *sv_result_cache; /* caches the result integer SV */ |
317 | SV *sv_result; |
345 | SV *sv_result; |
318 | |
346 | |
319 | ENTER; |
347 | ENTER; |
320 | SAVETMPS; |
348 | SAVETMPS; |
… | |
… | |
497 | SvSETMAGIC (req->sv2); |
525 | SvSETMAGIC (req->sv2); |
498 | PUSHs (sv_result); |
526 | PUSHs (sv_result); |
499 | } |
527 | } |
500 | break; |
528 | break; |
501 | |
529 | |
502 | case EIO_DUP2: |
530 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
503 | if (req->result > 0) |
531 | if (req->result > 0) |
504 | SvIV_set (sv_result, 0); |
532 | SvIV_set (sv_result, 0); |
505 | /* FALLTHROUGH */ |
533 | /* FALLTHROUGH */ |
506 | |
534 | |
507 | default: |
535 | default: |
… | |
… | |
607 | /*****************************************************************************/ |
635 | /*****************************************************************************/ |
608 | |
636 | |
609 | #if !_POSIX_MAPPED_FILES |
637 | #if !_POSIX_MAPPED_FILES |
610 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
638 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
611 | # define munmap(addr,length) (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 |
612 | #endif |
646 | #endif |
613 | |
647 | |
614 | #define MMAP_MAGIC PERL_MAGIC_ext |
648 | #define MMAP_MAGIC PERL_MAGIC_ext |
615 | |
649 | |
616 | static int |
650 | static int |
… | |
… | |
621 | errno = old_errno; |
655 | errno = old_errno; |
622 | |
656 | |
623 | mg->mg_obj = 0; /* just in case */ |
657 | mg->mg_obj = 0; /* just in case */ |
624 | |
658 | |
625 | SvREADONLY_off (sv); |
659 | SvREADONLY_off (sv); |
|
|
660 | |
|
|
661 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
662 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
663 | |
626 | SvCUR_set (sv, 0); |
664 | SvCUR_set (sv, 0); |
627 | SvLEN_set (sv, 0); |
|
|
628 | SvPVX (sv) = 0; |
665 | SvPVX (sv) = 0; |
629 | SvOK_off (sv); |
666 | SvOK_off (sv); |
630 | |
667 | |
631 | return 0; |
668 | return 0; |
632 | } |
669 | } |
… | |
… | |
697 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
734 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
698 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
735 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
699 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
736 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
700 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
737 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
701 | |
738 | |
|
|
739 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
740 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
741 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
742 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
743 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
|
|
744 | |
702 | const_iv (ST_RDONLY) |
745 | const_iv (ST_RDONLY) |
703 | const_iv (ST_NOSUID) |
746 | const_iv (ST_NOSUID) |
704 | const_iv (ST_NODEV) |
747 | const_iv (ST_NODEV) |
705 | const_iv (ST_NOEXEC) |
748 | const_iv (ST_NOEXEC) |
706 | const_iv (ST_SYNCHRONOUS) |
749 | const_iv (ST_SYNCHRONOUS) |
… | |
… | |
710 | const_iv (ST_IMMUTABLE) |
753 | const_iv (ST_IMMUTABLE) |
711 | const_iv (ST_NOATIME) |
754 | const_iv (ST_NOATIME) |
712 | const_iv (ST_NODIRATIME) |
755 | const_iv (ST_NODIRATIME) |
713 | const_iv (ST_RELATIME) |
756 | const_iv (ST_RELATIME) |
714 | |
757 | |
|
|
758 | const_iv (PROT_NONE) |
715 | const_iv (PROT_EXEC) |
759 | const_iv (PROT_EXEC) |
716 | const_iv (PROT_NONE) |
|
|
717 | const_iv (PROT_READ) |
760 | const_iv (PROT_READ) |
718 | const_iv (PROT_WRITE) |
761 | const_iv (PROT_WRITE) |
719 | |
762 | |
720 | /*const_iv (MAP_FIXED)*/ |
763 | /*const_iv (MAP_FIXED)*/ |
721 | const_iv (MAP_PRIVATE) |
764 | const_iv (MAP_PRIVATE) |
… | |
… | |
727 | const_iv (MAP_LOCKED) |
770 | const_iv (MAP_LOCKED) |
728 | const_iv (MAP_NORESERVE) |
771 | const_iv (MAP_NORESERVE) |
729 | const_iv (MAP_POPULATE) |
772 | const_iv (MAP_POPULATE) |
730 | const_iv (MAP_NONBLOCK) |
773 | const_iv (MAP_NONBLOCK) |
731 | |
774 | |
732 | const_iv (MCL_FUTURE) |
775 | const_eio (MCL_FUTURE) |
733 | const_iv (MCL_CURRENT) |
776 | const_eio (MCL_CURRENT) |
734 | |
777 | |
735 | const_eio (MS_ASYNC) |
778 | const_eio (MS_ASYNC) |
736 | const_eio (MS_INVALIDATE) |
779 | const_eio (MS_INVALIDATE) |
737 | const_eio (MS_SYNC) |
780 | const_eio (MS_SYNC) |
738 | |
781 | |
… | |
… | |
812 | CODE: |
855 | CODE: |
813 | max_outstanding = maxreqs; |
856 | max_outstanding = maxreqs; |
814 | |
857 | |
815 | void |
858 | void |
816 | 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) |
817 | PROTOTYPE: $$$;$ |
|
|
818 | PPCODE: |
860 | PPCODE: |
819 | { |
861 | { |
820 | dREQ; |
862 | dREQ; |
821 | |
863 | |
822 | req->type = EIO_OPEN; |
864 | req->type = EIO_OPEN; |
… | |
… | |
828 | REQ_SEND; |
870 | REQ_SEND; |
829 | } |
871 | } |
830 | |
872 | |
831 | void |
873 | void |
832 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
874 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
833 | PROTOTYPE: $;$ |
|
|
834 | ALIAS: |
875 | ALIAS: |
835 | aio_fsync = EIO_FSYNC |
876 | aio_fsync = EIO_FSYNC |
836 | aio_fdatasync = EIO_FDATASYNC |
877 | aio_fdatasync = EIO_FDATASYNC |
837 | PPCODE: |
878 | PPCODE: |
838 | { |
879 | { |
… | |
… | |
846 | REQ_SEND (req); |
887 | REQ_SEND (req); |
847 | } |
888 | } |
848 | |
889 | |
849 | void |
890 | void |
850 | 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) |
851 | PROTOTYPE: $$$$;$ |
|
|
852 | PPCODE: |
892 | PPCODE: |
853 | { |
893 | { |
854 | int fd = s_fileno_croak (fh, 0); |
894 | int fd = s_fileno_croak (fh, 0); |
855 | dREQ; |
895 | dREQ; |
856 | |
896 | |
… | |
… | |
864 | REQ_SEND (req); |
904 | REQ_SEND (req); |
865 | } |
905 | } |
866 | |
906 | |
867 | void |
907 | void |
868 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
908 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
869 | PROTOTYPE: $;$ |
|
|
870 | PPCODE: |
909 | PPCODE: |
871 | { |
910 | { |
872 | 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 */ |
873 | int fd = s_fileno_croak (fh, 0); |
912 | int fd = s_fileno_croak (fh, 0); |
874 | dREQ; |
913 | dREQ; |
… | |
… | |
896 | void |
935 | void |
897 | 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) |
898 | ALIAS: |
937 | ALIAS: |
899 | aio_read = EIO_READ |
938 | aio_read = EIO_READ |
900 | aio_write = EIO_WRITE |
939 | aio_write = EIO_WRITE |
901 | PROTOTYPE: $$$$$;$ |
|
|
902 | PPCODE: |
940 | PPCODE: |
903 | { |
941 | { |
904 | STRLEN svlen; |
942 | STRLEN svlen; |
905 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
943 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
906 | char *svptr = SvPVbyte (data, svlen); |
944 | char *svptr = SvPVbyte (data, svlen); |
… | |
… | |
947 | } |
985 | } |
948 | } |
986 | } |
949 | |
987 | |
950 | void |
988 | void |
951 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
989 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
952 | PROTOTYPE: $$;$ |
|
|
953 | PPCODE: |
990 | PPCODE: |
954 | { |
991 | { |
955 | SV *data; |
992 | SV *data; |
956 | dREQ; |
993 | dREQ; |
957 | |
994 | |
… | |
… | |
962 | REQ_SEND; |
999 | REQ_SEND; |
963 | } |
1000 | } |
964 | |
1001 | |
965 | void |
1002 | void |
966 | 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) |
967 | PROTOTYPE: $$$$;$ |
|
|
968 | PPCODE: |
1004 | PPCODE: |
969 | { |
1005 | { |
970 | int ifd = s_fileno_croak (in_fh , 0); |
1006 | int ifd = s_fileno_croak (in_fh , 0); |
971 | int ofd = s_fileno_croak (out_fh, 1); |
1007 | int ofd = s_fileno_croak (out_fh, 1); |
972 | dREQ; |
1008 | dREQ; |
… | |
… | |
982 | REQ_SEND; |
1018 | REQ_SEND; |
983 | } |
1019 | } |
984 | |
1020 | |
985 | void |
1021 | void |
986 | 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) |
987 | PROTOTYPE: $$$;$ |
|
|
988 | PPCODE: |
1023 | PPCODE: |
989 | { |
1024 | { |
990 | int fd = s_fileno_croak (fh, 0); |
1025 | int fd = s_fileno_croak (fh, 0); |
991 | dREQ; |
1026 | dREQ; |
992 | |
1027 | |
… | |
… | |
1193 | void |
1228 | void |
1194 | 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) |
1195 | ALIAS: |
1230 | ALIAS: |
1196 | aio_mtouch = EIO_MTOUCH |
1231 | aio_mtouch = EIO_MTOUCH |
1197 | aio_msync = EIO_MSYNC |
1232 | aio_msync = EIO_MSYNC |
1198 | PROTOTYPE: $$$$;$ |
|
|
1199 | PPCODE: |
1233 | PPCODE: |
1200 | { |
1234 | { |
1201 | STRLEN svlen; |
1235 | STRLEN svlen; |
|
|
1236 | char *svptr = SvPVbyte (data, svlen); |
1202 | UV len = SvUV (length); |
1237 | UV len = SvUV (length); |
1203 | char *svptr = SvPVbyte (data, svlen); |
|
|
1204 | |
1238 | |
1205 | if (offset < 0) |
1239 | if (offset < 0) |
1206 | offset += svlen; |
1240 | offset += svlen; |
1207 | |
1241 | |
1208 | if (offset < 0 || offset > svlen) |
1242 | if (offset < 0 || offset > svlen) |
… | |
… | |
1213 | |
1247 | |
1214 | { |
1248 | { |
1215 | dREQ; |
1249 | dREQ; |
1216 | |
1250 | |
1217 | req->type = ix; |
1251 | req->type = ix; |
1218 | req->size = len; |
|
|
1219 | req->sv2 = SvREFCNT_inc (data); |
1252 | req->sv2 = SvREFCNT_inc (data); |
1220 | req->ptr2 = (char *)svptr + offset; |
1253 | req->ptr2 = (char *)svptr + offset; |
|
|
1254 | req->size = len; |
1221 | req->int1 = flags; |
1255 | req->int1 = flags; |
1222 | |
1256 | |
1223 | REQ_SEND; |
1257 | REQ_SEND; |
1224 | } |
1258 | } |
1225 | } |
1259 | } |
1226 | |
1260 | |
1227 | 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 |
1228 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1303 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1229 | PPCODE: |
1304 | PPCODE: |
1230 | { |
1305 | { |
1231 | dREQ; |
1306 | dREQ; |
1232 | |
1307 | |
… | |
… | |
1236 | REQ_SEND; |
1311 | REQ_SEND; |
1237 | } |
1312 | } |
1238 | |
1313 | |
1239 | void |
1314 | void |
1240 | aio_group (SV *callback=&PL_sv_undef) |
1315 | aio_group (SV *callback=&PL_sv_undef) |
1241 | PROTOTYPE: ;$ |
|
|
1242 | PPCODE: |
1316 | PPCODE: |
1243 | { |
1317 | { |
1244 | dREQ; |
1318 | dREQ; |
1245 | |
1319 | |
1246 | req->type = EIO_GROUP; |
1320 | req->type = EIO_GROUP; |
… | |
… | |
1263 | REQ_SEND; |
1337 | REQ_SEND; |
1264 | } |
1338 | } |
1265 | |
1339 | |
1266 | int |
1340 | int |
1267 | aioreq_pri (int pri = 0) |
1341 | aioreq_pri (int pri = 0) |
1268 | PROTOTYPE: ;$ |
|
|
1269 | CODE: |
1342 | CODE: |
1270 | RETVAL = next_pri; |
1343 | RETVAL = next_pri; |
1271 | if (items > 0) |
1344 | if (items > 0) |
1272 | { |
1345 | { |
1273 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1346 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1285 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1358 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1286 | next_pri = nice; |
1359 | next_pri = nice; |
1287 | |
1360 | |
1288 | void |
1361 | void |
1289 | flush () |
1362 | flush () |
1290 | PROTOTYPE: |
|
|
1291 | CODE: |
1363 | CODE: |
1292 | while (eio_nreqs ()) |
1364 | while (eio_nreqs ()) |
1293 | { |
1365 | { |
1294 | poll_wait (); |
1366 | poll_wait (); |
1295 | poll_cb (); |
1367 | poll_cb (); |
1296 | } |
1368 | } |
1297 | |
1369 | |
1298 | int |
1370 | int |
1299 | poll() |
1371 | poll () |
1300 | PROTOTYPE: |
|
|
1301 | CODE: |
1372 | CODE: |
1302 | poll_wait (); |
1373 | poll_wait (); |
1303 | RETVAL = poll_cb (); |
1374 | RETVAL = poll_cb (); |
1304 | OUTPUT: |
1375 | OUTPUT: |
1305 | RETVAL |
1376 | RETVAL |
1306 | |
1377 | |
1307 | int |
1378 | int |
1308 | poll_fileno() |
1379 | poll_fileno () |
1309 | PROTOTYPE: |
|
|
1310 | CODE: |
1380 | CODE: |
1311 | RETVAL = s_epipe_fd (&respipe); |
1381 | RETVAL = s_epipe_fd (&respipe); |
1312 | OUTPUT: |
1382 | OUTPUT: |
1313 | RETVAL |
1383 | RETVAL |
1314 | |
1384 | |
1315 | int |
1385 | int |
1316 | poll_cb(...) |
1386 | poll_cb (...) |
1317 | PROTOTYPE: |
1387 | PROTOTYPE: |
1318 | CODE: |
1388 | CODE: |
1319 | RETVAL = poll_cb (); |
1389 | RETVAL = poll_cb (); |
1320 | OUTPUT: |
1390 | OUTPUT: |
1321 | RETVAL |
1391 | RETVAL |
1322 | |
1392 | |
1323 | void |
1393 | void |
1324 | poll_wait() |
1394 | poll_wait () |
1325 | PROTOTYPE: |
|
|
1326 | CODE: |
1395 | CODE: |
1327 | poll_wait (); |
1396 | poll_wait (); |
1328 | |
1397 | |
1329 | int |
1398 | int |
1330 | nreqs() |
1399 | nreqs () |
1331 | PROTOTYPE: |
|
|
1332 | CODE: |
1400 | CODE: |
1333 | RETVAL = eio_nreqs (); |
1401 | RETVAL = eio_nreqs (); |
1334 | OUTPUT: |
1402 | OUTPUT: |
1335 | RETVAL |
1403 | RETVAL |
1336 | |
1404 | |
1337 | int |
1405 | int |
1338 | nready() |
1406 | nready () |
1339 | PROTOTYPE: |
|
|
1340 | CODE: |
1407 | CODE: |
1341 | RETVAL = eio_nready (); |
1408 | RETVAL = eio_nready (); |
1342 | OUTPUT: |
1409 | OUTPUT: |
1343 | RETVAL |
1410 | RETVAL |
1344 | |
1411 | |
1345 | int |
1412 | int |
1346 | npending() |
1413 | npending () |
1347 | PROTOTYPE: |
|
|
1348 | CODE: |
1414 | CODE: |
1349 | RETVAL = eio_npending (); |
1415 | RETVAL = eio_npending (); |
1350 | OUTPUT: |
1416 | OUTPUT: |
1351 | RETVAL |
1417 | RETVAL |
1352 | |
1418 | |
1353 | int |
1419 | int |
1354 | nthreads() |
1420 | nthreads () |
1355 | PROTOTYPE: |
|
|
1356 | CODE: |
1421 | CODE: |
1357 | RETVAL = eio_nthreads (); |
1422 | RETVAL = eio_nthreads (); |
1358 | OUTPUT: |
1423 | OUTPUT: |
1359 | RETVAL |
1424 | RETVAL |
1360 | |
1425 | |
1361 | int |
1426 | int |
1362 | 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) |
1363 | PROTOTYPE: $$$$ |
|
|
1364 | CODE: |
1428 | CODE: |
1365 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1366 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1429 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1367 | #else |
|
|
1368 | RETVAL = errno = ENOSYS; /* yes, this is actually correct */ |
|
|
1369 | #endif |
|
|
1370 | OUTPUT: |
1430 | OUTPUT: |
1371 | RETVAL |
1431 | RETVAL |
1372 | |
1432 | |
1373 | ssize_t |
1433 | ssize_t |
1374 | 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) |
1375 | PROTOTYPE: $$$$ |
|
|
1376 | CODE: |
1435 | CODE: |
1377 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1436 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1378 | OUTPUT: |
1437 | OUTPUT: |
1379 | RETVAL |
1438 | RETVAL |
1380 | |
1439 | |
1381 | void |
1440 | void |
1382 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1441 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1383 | PROTOTYPE: $$$$$;$ |
|
|
1384 | PPCODE: |
1442 | PPCODE: |
1385 | sv_unmagic (scalar, MMAP_MAGIC); |
1443 | sv_unmagic (scalar, MMAP_MAGIC); |
1386 | { |
1444 | { |
1387 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1445 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1388 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1446 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1389 | if (addr == (void *)-1) |
1447 | if (addr == (void *)-1) |
1390 | XSRETURN_NO; |
1448 | XSRETURN_NO; |
1391 | |
1449 | |
|
|
1450 | sv_force_normal (scalar); |
|
|
1451 | |
1392 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
1452 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
1393 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
1453 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
1394 | ->mg_obj = (SV *)length; |
1454 | ->mg_obj = (SV *)length; |
1395 | |
1455 | |
1396 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
1456 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1457 | |
1397 | if (!(prot & PROT_WRITE)) |
1458 | if (!(prot & PROT_WRITE)) |
1398 | SvREADONLY_on (scalar); |
1459 | SvREADONLY_on (scalar); |
|
|
1460 | |
|
|
1461 | if (SvLEN (scalar)) |
|
|
1462 | Safefree (SvPVX (scalar)); |
1399 | |
1463 | |
1400 | SvPVX (scalar) = (char *)addr; |
1464 | SvPVX (scalar) = (char *)addr; |
1401 | SvCUR_set (scalar, length); |
1465 | SvCUR_set (scalar, length); |
1402 | SvLEN_set (scalar, 0); |
1466 | SvLEN_set (scalar, 0); |
1403 | SvPOK_only (scalar); |
1467 | SvPOK_only (scalar); |
… | |
… | |
1405 | XSRETURN_YES; |
1469 | XSRETURN_YES; |
1406 | } |
1470 | } |
1407 | |
1471 | |
1408 | void |
1472 | void |
1409 | munmap (SV *scalar) |
1473 | munmap (SV *scalar) |
1410 | PROTOTYPE: $ |
|
|
1411 | CODE: |
1474 | CODE: |
1412 | sv_unmagic (scalar, MMAP_MAGIC); |
1475 | sv_unmagic (scalar, MMAP_MAGIC); |
1413 | |
1476 | |
1414 | int |
1477 | int |
1415 | mlockall (int flags) |
1478 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
1416 | PROTOTYPE: $ |
1479 | ALIAS: |
|
|
1480 | mprotect = 1 |
1417 | CODE: |
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); |
1418 | #if _POSIX_MEMLOCK |
1527 | #if _POSIX_MEMLOCK |
1419 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
1528 | RETVAL = munlock (addr, len); |
1420 | extern int mallopt (int, int); |
|
|
1421 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1422 | #endif |
|
|
1423 | mlockall (flags); |
|
|
1424 | #else |
1529 | #else |
1425 | RETVAL = -1; |
1530 | RETVAL = ((errno = ENOSYS), -1); |
1426 | errno = ENOSYS; |
|
|
1427 | #endif |
1531 | #endif |
|
|
1532 | } |
1428 | OUTPUT: |
1533 | OUTPUT: |
1429 | RETVAL |
1534 | RETVAL |
1430 | |
1535 | |
1431 | int |
1536 | int |
1432 | munlockall () |
1537 | munlockall () |
1433 | PROTOTYPE: |
|
|
1434 | CODE: |
1538 | CODE: |
1435 | #if _POSIX_MEMLOCK |
1539 | #if _POSIX_MEMLOCK |
1436 | munlockall (); |
1540 | munlockall (); |
1437 | #else |
1541 | #else |
1438 | RETVAL = -1; |
1542 | RETVAL = -1; |