… | |
… | |
16 | #include <sys/statvfs.h> |
16 | #include <sys/statvfs.h> |
17 | #include <limits.h> |
17 | #include <limits.h> |
18 | #include <fcntl.h> |
18 | #include <fcntl.h> |
19 | #include <sched.h> |
19 | #include <sched.h> |
20 | |
20 | |
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
21 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
22 | # include <sys/mman.h> |
22 | # include <sys/mman.h> |
23 | #endif |
23 | #endif |
24 | |
24 | |
25 | /* perl namespace pollution */ |
25 | /* perl namespace pollution */ |
26 | #undef VERSION |
26 | #undef VERSION |
… | |
… | |
118 | STRLEN stroffset; \ |
118 | STRLEN stroffset; \ |
119 | SV *self; |
119 | SV *self; |
120 | |
120 | |
121 | #define EIO_NO_WRAPPERS 1 |
121 | #define EIO_NO_WRAPPERS 1 |
122 | |
122 | |
|
|
123 | #include "libeio/config.h" |
123 | #include "libeio/eio.h" |
124 | #include "libeio/eio.h" |
124 | |
125 | |
125 | #ifndef POSIX_FADV_NORMAL |
126 | #ifndef POSIX_FADV_NORMAL |
126 | # define POSIX_FADV_NORMAL 0 |
127 | # define POSIX_FADV_NORMAL 0 |
127 | # define NO_FADVISE 1 |
|
|
128 | #endif |
128 | #endif |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
131 | #endif |
131 | #endif |
132 | #ifndef POSIX_FADV_RANDOM |
132 | #ifndef POSIX_FADV_RANDOM |
… | |
… | |
140 | #endif |
140 | #endif |
141 | #ifndef POSIX_FADV_DONTNEED |
141 | #ifndef POSIX_FADV_DONTNEED |
142 | # define POSIX_FADV_DONTNEED 0 |
142 | # define POSIX_FADV_DONTNEED 0 |
143 | #endif |
143 | #endif |
144 | |
144 | |
145 | #if _XOPEN_SOURCE < 600 || NO_FADVISE |
145 | #if !HAVE_POSIX_FADVISE |
146 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
146 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
147 | #endif |
147 | #endif |
148 | |
148 | |
149 | #ifndef POSIX_MADV_NORMAL |
149 | #ifndef POSIX_MADV_NORMAL |
150 | # define POSIX_MADV_NORMAL 0 |
150 | # define POSIX_MADV_NORMAL 0 |
151 | # define NO_MADVISE 1 |
|
|
152 | #endif |
151 | #endif |
153 | #ifndef POSIX_MADV_SEQUENTIAL |
152 | #ifndef POSIX_MADV_SEQUENTIAL |
154 | # define POSIX_MADV_SEQUENTIAL 0 |
153 | # define POSIX_MADV_SEQUENTIAL 0 |
155 | #endif |
154 | #endif |
156 | #ifndef POSIX_MADV_RANDOM |
155 | #ifndef POSIX_MADV_RANDOM |
… | |
… | |
161 | #endif |
160 | #endif |
162 | #ifndef POSIX_MADV_DONTNEED |
161 | #ifndef POSIX_MADV_DONTNEED |
163 | # define POSIX_MADV_DONTNEED 0 |
162 | # define POSIX_MADV_DONTNEED 0 |
164 | #endif |
163 | #endif |
165 | |
164 | |
166 | #if _XOPEN_SOURCE < 600 || NO_MADVISE |
165 | #if !HAVE_POSIX_MADVISE |
167 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
166 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
168 | #endif |
167 | #endif |
169 | |
168 | |
170 | #ifndef PROT_NONE |
169 | #ifndef PROT_NONE |
171 | # define PROT_NONE 0 |
170 | # define PROT_NONE 0 |
… | |
… | |
207 | #ifndef ST_NODIRATIME |
206 | #ifndef ST_NODIRATIME |
208 | # define ST_NODIRATIME 0 |
207 | # define ST_NODIRATIME 0 |
209 | #endif |
208 | #endif |
210 | #ifndef ST_RELATIME |
209 | #ifndef ST_RELATIME |
211 | # define ST_RELATIME 0 |
210 | # define ST_RELATIME 0 |
212 | #endif |
|
|
213 | |
|
|
214 | #ifndef MCL_CURRENT |
|
|
215 | # define MCL_CURRENT 0 |
|
|
216 | #endif |
|
|
217 | #ifndef MCL_FUTURE |
|
|
218 | # define MCL_FUTURE 0 |
|
|
219 | #endif |
211 | #endif |
220 | |
212 | |
221 | #ifndef MAP_ANONYMOUS |
213 | #ifndef MAP_ANONYMOUS |
222 | # ifdef MAP_ANON |
214 | # ifdef MAP_ANON |
223 | # define MAP_ANONYMOUS MAP_ANON |
215 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
361 | /* do not recreate the result IV from scratch each time */ |
353 | /* do not recreate the result IV from scratch each time */ |
362 | if (expect_true (sv_result_cache)) |
354 | if (expect_true (sv_result_cache)) |
363 | { |
355 | { |
364 | sv_result = sv_result_cache; sv_result_cache = 0; |
356 | sv_result = sv_result_cache; sv_result_cache = 0; |
365 | SvIV_set (sv_result, req->result); |
357 | SvIV_set (sv_result, req->result); |
|
|
358 | SvIOK_only (sv_result); |
366 | } |
359 | } |
367 | else |
360 | else |
368 | { |
361 | { |
369 | sv_result = newSViv (req->result); |
362 | sv_result = newSViv (req->result); |
370 | SvREADONLY_on (sv_result); |
363 | SvREADONLY_on (sv_result); |
… | |
… | |
534 | SvSETMAGIC (req->sv2); |
527 | SvSETMAGIC (req->sv2); |
535 | PUSHs (sv_result); |
528 | PUSHs (sv_result); |
536 | } |
529 | } |
537 | break; |
530 | break; |
538 | |
531 | |
539 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
532 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
540 | if (req->result > 0) |
533 | if (req->result > 0) |
541 | SvIV_set (sv_result, 0); |
534 | SvIV_set (sv_result, 0); |
542 | /* FALLTHROUGH */ |
535 | /* FALLTHROUGH */ |
543 | |
536 | |
544 | default: |
537 | default: |
… | |
… | |
644 | /*****************************************************************************/ |
637 | /*****************************************************************************/ |
645 | |
638 | |
646 | #if !_POSIX_MAPPED_FILES |
639 | #if !_POSIX_MAPPED_FILES |
647 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
640 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
648 | # define munmap(addr,length) (errno = ENOSYS, -1) |
641 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
642 | #endif |
|
|
643 | |
|
|
644 | #if !_POSIX_MEMORY_PROTECTION |
649 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
645 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
646 | # define PROT_NONE 0 |
|
|
647 | # define PROT_WRITE 0 |
|
|
648 | # define MAP_PRIVATE 0 |
|
|
649 | # define MAP_SHARED 0 |
|
|
650 | # define MAP_FIXED 0 |
650 | #endif |
651 | #endif |
651 | |
652 | |
652 | #define MMAP_MAGIC PERL_MAGIC_ext |
653 | #define MMAP_MAGIC PERL_MAGIC_ext |
653 | |
654 | |
654 | static int |
655 | static int |
… | |
… | |
774 | const_iv (MAP_LOCKED) |
775 | const_iv (MAP_LOCKED) |
775 | const_iv (MAP_NORESERVE) |
776 | const_iv (MAP_NORESERVE) |
776 | const_iv (MAP_POPULATE) |
777 | const_iv (MAP_POPULATE) |
777 | const_iv (MAP_NONBLOCK) |
778 | const_iv (MAP_NONBLOCK) |
778 | |
779 | |
779 | const_iv (MCL_FUTURE) |
780 | const_eio (MCL_FUTURE) |
780 | const_iv (MCL_CURRENT) |
781 | const_eio (MCL_CURRENT) |
781 | |
782 | |
782 | const_eio (MS_ASYNC) |
783 | const_eio (MS_ASYNC) |
783 | const_eio (MS_INVALIDATE) |
784 | const_eio (MS_INVALIDATE) |
784 | const_eio (MS_SYNC) |
785 | const_eio (MS_SYNC) |
785 | |
786 | |
… | |
… | |
859 | CODE: |
860 | CODE: |
860 | max_outstanding = maxreqs; |
861 | max_outstanding = maxreqs; |
861 | |
862 | |
862 | void |
863 | void |
863 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
864 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
864 | PROTOTYPE: $$$;$ |
|
|
865 | PPCODE: |
865 | PPCODE: |
866 | { |
866 | { |
867 | dREQ; |
867 | dREQ; |
868 | |
868 | |
869 | req->type = EIO_OPEN; |
869 | req->type = EIO_OPEN; |
… | |
… | |
875 | REQ_SEND; |
875 | REQ_SEND; |
876 | } |
876 | } |
877 | |
877 | |
878 | void |
878 | void |
879 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
879 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
880 | PROTOTYPE: $;$ |
|
|
881 | ALIAS: |
880 | ALIAS: |
882 | aio_fsync = EIO_FSYNC |
881 | aio_fsync = EIO_FSYNC |
883 | aio_fdatasync = EIO_FDATASYNC |
882 | aio_fdatasync = EIO_FDATASYNC |
884 | PPCODE: |
883 | PPCODE: |
885 | { |
884 | { |
… | |
… | |
893 | REQ_SEND (req); |
892 | REQ_SEND (req); |
894 | } |
893 | } |
895 | |
894 | |
896 | void |
895 | void |
897 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
896 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
898 | PROTOTYPE: $$$$;$ |
|
|
899 | PPCODE: |
897 | PPCODE: |
900 | { |
898 | { |
901 | int fd = s_fileno_croak (fh, 0); |
899 | int fd = s_fileno_croak (fh, 0); |
902 | dREQ; |
900 | dREQ; |
903 | |
901 | |
… | |
… | |
911 | REQ_SEND (req); |
909 | REQ_SEND (req); |
912 | } |
910 | } |
913 | |
911 | |
914 | void |
912 | void |
915 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
913 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
916 | PROTOTYPE: $;$ |
|
|
917 | PPCODE: |
914 | PPCODE: |
918 | { |
915 | { |
919 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
916 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
920 | int fd = s_fileno_croak (fh, 0); |
917 | int fd = s_fileno_croak (fh, 0); |
921 | dREQ; |
918 | dREQ; |
… | |
… | |
943 | void |
940 | void |
944 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
941 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
945 | ALIAS: |
942 | ALIAS: |
946 | aio_read = EIO_READ |
943 | aio_read = EIO_READ |
947 | aio_write = EIO_WRITE |
944 | aio_write = EIO_WRITE |
948 | PROTOTYPE: $$$$$;$ |
|
|
949 | PPCODE: |
945 | PPCODE: |
950 | { |
946 | { |
951 | STRLEN svlen; |
947 | STRLEN svlen; |
952 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
948 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
953 | char *svptr = SvPVbyte (data, svlen); |
949 | char *svptr = SvPVbyte (data, svlen); |
… | |
… | |
994 | } |
990 | } |
995 | } |
991 | } |
996 | |
992 | |
997 | void |
993 | void |
998 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
994 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
999 | PROTOTYPE: $$;$ |
|
|
1000 | PPCODE: |
995 | PPCODE: |
1001 | { |
996 | { |
1002 | SV *data; |
997 | SV *data; |
1003 | dREQ; |
998 | dREQ; |
1004 | |
999 | |
… | |
… | |
1009 | REQ_SEND; |
1004 | REQ_SEND; |
1010 | } |
1005 | } |
1011 | |
1006 | |
1012 | void |
1007 | void |
1013 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1008 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1014 | PROTOTYPE: $$$$;$ |
|
|
1015 | PPCODE: |
1009 | PPCODE: |
1016 | { |
1010 | { |
1017 | int ifd = s_fileno_croak (in_fh , 0); |
1011 | int ifd = s_fileno_croak (in_fh , 0); |
1018 | int ofd = s_fileno_croak (out_fh, 1); |
1012 | int ofd = s_fileno_croak (out_fh, 1); |
1019 | dREQ; |
1013 | dREQ; |
… | |
… | |
1029 | REQ_SEND; |
1023 | REQ_SEND; |
1030 | } |
1024 | } |
1031 | |
1025 | |
1032 | void |
1026 | void |
1033 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1027 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1034 | PROTOTYPE: $$$;$ |
|
|
1035 | PPCODE: |
1028 | PPCODE: |
1036 | { |
1029 | { |
1037 | int fd = s_fileno_croak (fh, 0); |
1030 | int fd = s_fileno_croak (fh, 0); |
1038 | dREQ; |
1031 | dREQ; |
1039 | |
1032 | |
… | |
… | |
1240 | void |
1233 | void |
1241 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1234 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
1242 | ALIAS: |
1235 | ALIAS: |
1243 | aio_mtouch = EIO_MTOUCH |
1236 | aio_mtouch = EIO_MTOUCH |
1244 | aio_msync = EIO_MSYNC |
1237 | aio_msync = EIO_MSYNC |
1245 | PROTOTYPE: $$$$;$ |
|
|
1246 | PPCODE: |
1238 | PPCODE: |
1247 | { |
1239 | { |
1248 | STRLEN svlen; |
1240 | STRLEN svlen; |
|
|
1241 | char *svptr = SvPVbyte (data, svlen); |
1249 | UV len = SvUV (length); |
1242 | UV len = SvUV (length); |
1250 | char *svptr = SvPVbyte (data, svlen); |
|
|
1251 | |
1243 | |
1252 | if (offset < 0) |
1244 | if (offset < 0) |
1253 | offset += svlen; |
1245 | offset += svlen; |
1254 | |
1246 | |
1255 | if (offset < 0 || offset > svlen) |
1247 | if (offset < 0 || offset > svlen) |
… | |
… | |
1260 | |
1252 | |
1261 | { |
1253 | { |
1262 | dREQ; |
1254 | dREQ; |
1263 | |
1255 | |
1264 | req->type = ix; |
1256 | req->type = ix; |
1265 | req->size = len; |
|
|
1266 | req->sv2 = SvREFCNT_inc (data); |
1257 | req->sv2 = SvREFCNT_inc (data); |
1267 | req->ptr2 = (char *)svptr + offset; |
1258 | req->ptr2 = (char *)svptr + offset; |
|
|
1259 | req->size = len; |
1268 | req->int1 = flags; |
1260 | req->int1 = flags; |
1269 | |
1261 | |
1270 | REQ_SEND; |
1262 | REQ_SEND; |
1271 | } |
1263 | } |
1272 | } |
1264 | } |
1273 | |
1265 | |
1274 | void |
1266 | void |
|
|
1267 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1268 | PPCODE: |
|
|
1269 | { |
|
|
1270 | STRLEN svlen; |
|
|
1271 | char *svptr = SvPVbyte (data, svlen); |
|
|
1272 | UV len = SvUV (length); |
|
|
1273 | |
|
|
1274 | if (offset < 0) |
|
|
1275 | offset += svlen; |
|
|
1276 | |
|
|
1277 | if (offset < 0 || offset > svlen) |
|
|
1278 | croak ("offset outside of scalar"); |
|
|
1279 | |
|
|
1280 | if (!SvOK (length) || len + offset > svlen) |
|
|
1281 | len = svlen - offset; |
|
|
1282 | |
|
|
1283 | { |
|
|
1284 | dREQ; |
|
|
1285 | |
|
|
1286 | req->type = EIO_MLOCK; |
|
|
1287 | req->sv2 = SvREFCNT_inc (data); |
|
|
1288 | req->ptr2 = (char *)svptr + offset; |
|
|
1289 | req->size = len; |
|
|
1290 | |
|
|
1291 | REQ_SEND; |
|
|
1292 | } |
|
|
1293 | } |
|
|
1294 | |
|
|
1295 | void |
|
|
1296 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1297 | PPCODE: |
|
|
1298 | { |
|
|
1299 | dREQ; |
|
|
1300 | |
|
|
1301 | req->type = EIO_MLOCKALL; |
|
|
1302 | req->int1 = flags; |
|
|
1303 | |
|
|
1304 | REQ_SEND; |
|
|
1305 | } |
|
|
1306 | |
|
|
1307 | void |
1275 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1308 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1276 | PPCODE: |
1309 | PPCODE: |
1277 | { |
1310 | { |
1278 | dREQ; |
1311 | dREQ; |
1279 | |
1312 | |
… | |
… | |
1283 | REQ_SEND; |
1316 | REQ_SEND; |
1284 | } |
1317 | } |
1285 | |
1318 | |
1286 | void |
1319 | void |
1287 | aio_group (SV *callback=&PL_sv_undef) |
1320 | aio_group (SV *callback=&PL_sv_undef) |
1288 | PROTOTYPE: ;$ |
|
|
1289 | PPCODE: |
1321 | PPCODE: |
1290 | { |
1322 | { |
1291 | dREQ; |
1323 | dREQ; |
1292 | |
1324 | |
1293 | req->type = EIO_GROUP; |
1325 | req->type = EIO_GROUP; |
… | |
… | |
1310 | REQ_SEND; |
1342 | REQ_SEND; |
1311 | } |
1343 | } |
1312 | |
1344 | |
1313 | int |
1345 | int |
1314 | aioreq_pri (int pri = 0) |
1346 | aioreq_pri (int pri = 0) |
1315 | PROTOTYPE: ;$ |
|
|
1316 | CODE: |
1347 | CODE: |
1317 | RETVAL = next_pri; |
1348 | RETVAL = next_pri; |
1318 | if (items > 0) |
1349 | if (items > 0) |
1319 | { |
1350 | { |
1320 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1351 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1332 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1363 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1333 | next_pri = nice; |
1364 | next_pri = nice; |
1334 | |
1365 | |
1335 | void |
1366 | void |
1336 | flush () |
1367 | flush () |
1337 | PROTOTYPE: |
|
|
1338 | CODE: |
1368 | CODE: |
1339 | while (eio_nreqs ()) |
1369 | while (eio_nreqs ()) |
1340 | { |
1370 | { |
1341 | poll_wait (); |
1371 | poll_wait (); |
1342 | poll_cb (); |
1372 | poll_cb (); |
1343 | } |
1373 | } |
1344 | |
1374 | |
1345 | int |
1375 | int |
1346 | poll() |
1376 | poll () |
1347 | PROTOTYPE: |
|
|
1348 | CODE: |
1377 | CODE: |
1349 | poll_wait (); |
1378 | poll_wait (); |
1350 | RETVAL = poll_cb (); |
1379 | RETVAL = poll_cb (); |
1351 | OUTPUT: |
1380 | OUTPUT: |
1352 | RETVAL |
1381 | RETVAL |
1353 | |
1382 | |
1354 | int |
1383 | int |
1355 | poll_fileno() |
1384 | poll_fileno () |
1356 | PROTOTYPE: |
|
|
1357 | CODE: |
1385 | CODE: |
1358 | RETVAL = s_epipe_fd (&respipe); |
1386 | RETVAL = s_epipe_fd (&respipe); |
1359 | OUTPUT: |
1387 | OUTPUT: |
1360 | RETVAL |
1388 | RETVAL |
1361 | |
1389 | |
1362 | int |
1390 | int |
1363 | poll_cb(...) |
1391 | poll_cb (...) |
1364 | PROTOTYPE: |
1392 | PROTOTYPE: |
1365 | CODE: |
1393 | CODE: |
1366 | RETVAL = poll_cb (); |
1394 | RETVAL = poll_cb (); |
1367 | OUTPUT: |
1395 | OUTPUT: |
1368 | RETVAL |
1396 | RETVAL |
1369 | |
1397 | |
1370 | void |
1398 | void |
1371 | poll_wait() |
1399 | poll_wait () |
1372 | PROTOTYPE: |
|
|
1373 | CODE: |
1400 | CODE: |
1374 | poll_wait (); |
1401 | poll_wait (); |
1375 | |
1402 | |
1376 | int |
1403 | int |
1377 | nreqs() |
1404 | nreqs () |
1378 | PROTOTYPE: |
|
|
1379 | CODE: |
1405 | CODE: |
1380 | RETVAL = eio_nreqs (); |
1406 | RETVAL = eio_nreqs (); |
1381 | OUTPUT: |
1407 | OUTPUT: |
1382 | RETVAL |
1408 | RETVAL |
1383 | |
1409 | |
1384 | int |
1410 | int |
1385 | nready() |
1411 | nready () |
1386 | PROTOTYPE: |
|
|
1387 | CODE: |
1412 | CODE: |
1388 | RETVAL = eio_nready (); |
1413 | RETVAL = eio_nready (); |
1389 | OUTPUT: |
1414 | OUTPUT: |
1390 | RETVAL |
1415 | RETVAL |
1391 | |
1416 | |
1392 | int |
1417 | int |
1393 | npending() |
1418 | npending () |
1394 | PROTOTYPE: |
|
|
1395 | CODE: |
1419 | CODE: |
1396 | RETVAL = eio_npending (); |
1420 | RETVAL = eio_npending (); |
1397 | OUTPUT: |
1421 | OUTPUT: |
1398 | RETVAL |
1422 | RETVAL |
1399 | |
1423 | |
1400 | int |
1424 | int |
1401 | nthreads() |
1425 | nthreads () |
1402 | PROTOTYPE: |
|
|
1403 | CODE: |
1426 | CODE: |
1404 | RETVAL = eio_nthreads (); |
1427 | RETVAL = eio_nthreads (); |
1405 | OUTPUT: |
1428 | OUTPUT: |
1406 | RETVAL |
1429 | RETVAL |
1407 | |
1430 | |
1408 | int |
1431 | int |
1409 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1432 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1410 | PROTOTYPE: $$$$ |
|
|
1411 | CODE: |
1433 | CODE: |
1412 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1434 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1413 | OUTPUT: |
1435 | OUTPUT: |
1414 | RETVAL |
1436 | RETVAL |
1415 | |
1437 | |
1416 | ssize_t |
1438 | ssize_t |
1417 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1439 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1418 | PROTOTYPE: $$$$ |
|
|
1419 | CODE: |
1440 | CODE: |
1420 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1441 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1421 | OUTPUT: |
1442 | OUTPUT: |
1422 | RETVAL |
1443 | RETVAL |
1423 | |
1444 | |
1424 | void |
1445 | void |
1425 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1446 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1426 | PROTOTYPE: $$$$$;$ |
|
|
1427 | PPCODE: |
1447 | PPCODE: |
1428 | sv_unmagic (scalar, MMAP_MAGIC); |
1448 | sv_unmagic (scalar, MMAP_MAGIC); |
1429 | { |
1449 | { |
1430 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1450 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1431 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1451 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
… | |
… | |
1454 | XSRETURN_YES; |
1474 | XSRETURN_YES; |
1455 | } |
1475 | } |
1456 | |
1476 | |
1457 | void |
1477 | void |
1458 | munmap (SV *scalar) |
1478 | munmap (SV *scalar) |
1459 | PROTOTYPE: $ |
|
|
1460 | CODE: |
1479 | CODE: |
1461 | sv_unmagic (scalar, MMAP_MAGIC); |
1480 | sv_unmagic (scalar, MMAP_MAGIC); |
1462 | |
1481 | |
1463 | int |
1482 | int |
1464 | madvise (SV *scalar, off_t offset, off_t length, IV advice_or_prot) |
1483 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
1465 | ALIAS: |
1484 | ALIAS: |
1466 | mprotect = 1 |
1485 | mprotect = 1 |
1467 | PROTOTYPE: $$$$ |
|
|
1468 | CODE: |
1486 | CODE: |
1469 | { |
1487 | { |
1470 | STRLEN cur; |
1488 | STRLEN svlen; |
1471 | char *addr = SvPVbyte (scalar, cur); |
1489 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1490 | size_t len = SvUV (length); |
1472 | |
1491 | |
1473 | if (offset > cur) |
1492 | if (offset < 0) |
1474 | RETVAL = errno = EFAULT; |
1493 | offset += svlen; |
1475 | else |
1494 | |
|
|
1495 | if (offset < 0 || offset > svlen) |
|
|
1496 | croak ("offset outside of scalar"); |
|
|
1497 | |
|
|
1498 | if (!SvOK (length) || len + offset > svlen) |
|
|
1499 | len = svlen - offset; |
|
|
1500 | |
|
|
1501 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1502 | eio_page_align (&addr, &len); |
|
|
1503 | |
|
|
1504 | switch (ix) |
1476 | { |
1505 | { |
1477 | if (!SvOK (ST (2))) |
|
|
1478 | length = cur - offset; |
|
|
1479 | |
|
|
1480 | if (offset + length > cur) |
|
|
1481 | RETVAL = errno = EFAULT; |
|
|
1482 | else |
|
|
1483 | switch (ix) |
|
|
1484 | { |
|
|
1485 | case 0: RETVAL = posix_madvise (addr + offset, length, advice_or_prot); break; |
1506 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
1486 | case 1: RETVAL = mprotect (addr + offset, length, advice_or_prot); break; |
1507 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
1487 | } |
|
|
1488 | } |
1508 | } |
1489 | } |
1509 | } |
1490 | OUTPUT: |
1510 | OUTPUT: |
1491 | RETVAL |
1511 | RETVAL |
1492 | |
1512 | |
1493 | int |
1513 | int |
1494 | mlockall (int flags) |
1514 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
1495 | PROTOTYPE: $ |
|
|
1496 | CODE: |
1515 | CODE: |
|
|
1516 | { |
|
|
1517 | STRLEN svlen; |
|
|
1518 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1519 | size_t len = SvUV (length); |
|
|
1520 | |
|
|
1521 | if (offset < 0) |
|
|
1522 | offset += svlen; |
|
|
1523 | |
|
|
1524 | if (offset < 0 || offset > svlen) |
|
|
1525 | croak ("offset outside of scalar"); |
|
|
1526 | |
|
|
1527 | if (!SvOK (length) || len + offset > svlen) |
|
|
1528 | len = svlen - offset; |
|
|
1529 | |
|
|
1530 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1531 | eio_page_align (&addr, &len); |
1497 | #if _POSIX_MEMLOCK |
1532 | #if _POSIX_MEMLOCK_RANGE |
1498 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
1533 | RETVAL = munlock (addr, len); |
1499 | extern int mallopt (int, int); |
|
|
1500 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1501 | #endif |
|
|
1502 | mlockall (flags); |
|
|
1503 | #else |
1534 | #else |
1504 | RETVAL = -1; |
1535 | RETVAL = ((errno = ENOSYS), -1); |
1505 | errno = ENOSYS; |
|
|
1506 | #endif |
1536 | #endif |
|
|
1537 | } |
1507 | OUTPUT: |
1538 | OUTPUT: |
1508 | RETVAL |
1539 | RETVAL |
1509 | |
1540 | |
1510 | int |
1541 | int |
1511 | munlockall () |
1542 | munlockall () |
1512 | PROTOTYPE: |
|
|
1513 | CODE: |
1543 | CODE: |
1514 | #if _POSIX_MEMLOCK |
1544 | #if _POSIX_MEMLOCK |
1515 | munlockall (); |
1545 | munlockall (); |
1516 | #else |
1546 | #else |
1517 | RETVAL = -1; |
1547 | RETVAL = -1; |