… | |
… | |
11 | #include <stddef.h> |
11 | #include <stddef.h> |
12 | #include <stdlib.h> |
12 | #include <stdlib.h> |
13 | #include <errno.h> |
13 | #include <errno.h> |
14 | #include <sys/types.h> |
14 | #include <sys/types.h> |
15 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
16 | #include <sys/statvfs.h> |
|
|
17 | #include <limits.h> |
16 | #include <limits.h> |
18 | #include <fcntl.h> |
17 | #include <fcntl.h> |
19 | #include <sched.h> |
18 | #include <sched.h> |
20 | |
19 | |
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
22 | # include <sys/mman.h> |
21 | # include <sys/mman.h> |
23 | #endif |
22 | #endif |
24 | |
23 | |
25 | /* perl namespace pollution */ |
24 | /* perl namespace pollution */ |
26 | #undef VERSION |
25 | #undef VERSION |
27 | |
|
|
28 | #ifdef _WIN32 |
|
|
29 | |
|
|
30 | # define EIO_STRUCT_DIRENT Direntry_t |
|
|
31 | # undef malloc |
|
|
32 | # undef free |
|
|
33 | |
|
|
34 | // perl overrides all those nice win32 functions |
|
|
35 | # undef open |
|
|
36 | # undef read |
|
|
37 | # undef write |
|
|
38 | # undef send |
|
|
39 | # undef recv |
|
|
40 | # undef stat |
|
|
41 | # undef fstat |
|
|
42 | # define lstat stat |
|
|
43 | # undef truncate |
|
|
44 | # undef ftruncate |
|
|
45 | # undef open |
|
|
46 | # undef close |
|
|
47 | # undef unlink |
|
|
48 | # undef rmdir |
|
|
49 | # undef rename |
|
|
50 | # undef lseek |
|
|
51 | |
|
|
52 | # define chown(a,b,c) (errno = ENOSYS, -1) |
|
|
53 | # define fchown(a,b,c) (errno = ENOSYS, -1) |
|
|
54 | # define fchmod(a,b) (errno = ENOSYS, -1) |
|
|
55 | # define symlink(a,b) (errno = ENOSYS, -1) |
|
|
56 | # define readlink(a,b,c) (errno = ENOSYS, -1) |
|
|
57 | # define mknod(a,b,c) (errno = ENOSYS, -1) |
|
|
58 | # define truncate(a,b) (errno = ENOSYS, -1) |
|
|
59 | # define ftruncate(fd,o) chsize ((fd), (o)) |
|
|
60 | # define fsync(fd) _commit (fd) |
|
|
61 | # define opendir(fd) (errno = ENOSYS, 0) |
|
|
62 | # define readdir(fd) (errno = ENOSYS, -1) |
|
|
63 | # define closedir(fd) (errno = ENOSYS, -1) |
|
|
64 | # define mkdir(a,b) mkdir (a) |
|
|
65 | |
|
|
66 | #else |
|
|
67 | |
|
|
68 | # include <sys/time.h> |
|
|
69 | # include <sys/select.h> |
|
|
70 | # include <unistd.h> |
|
|
71 | # include <utime.h> |
|
|
72 | # include <signal.h> |
|
|
73 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
74 | |
|
|
75 | #endif |
|
|
76 | |
26 | |
77 | /* perl stupidly overrides readdir and maybe others */ |
27 | /* perl stupidly overrides readdir and maybe others */ |
78 | /* with thread-unsafe versions, imagine that :( */ |
28 | /* with thread-unsafe versions, imagine that :( */ |
79 | #undef readdir |
29 | #undef readdir |
80 | #undef opendir |
30 | #undef opendir |
81 | #undef closedir |
31 | #undef closedir |
|
|
32 | |
|
|
33 | #ifdef _WIN32 |
|
|
34 | |
|
|
35 | // perl overrides all those nice libc functions |
|
|
36 | |
|
|
37 | #undef malloc |
|
|
38 | #undef free |
|
|
39 | #undef open |
|
|
40 | #undef read |
|
|
41 | #undef write |
|
|
42 | #undef send |
|
|
43 | #undef recv |
|
|
44 | #undef stat |
|
|
45 | #undef lstat |
|
|
46 | #undef fstat |
|
|
47 | #undef truncate |
|
|
48 | #undef ftruncate |
|
|
49 | #undef open |
|
|
50 | #undef link |
|
|
51 | #undef close |
|
|
52 | #undef unlink |
|
|
53 | #undef mkdir |
|
|
54 | #undef rmdir |
|
|
55 | #undef rename |
|
|
56 | #undef lseek |
|
|
57 | #undef opendir |
|
|
58 | #undef readdir |
|
|
59 | #undef closedir |
|
|
60 | #undef chmod |
|
|
61 | #undef fchmod |
|
|
62 | #undef dup |
|
|
63 | #undef dup2 |
|
|
64 | #undef abort |
|
|
65 | #undef pipe |
|
|
66 | |
|
|
67 | #else |
|
|
68 | |
|
|
69 | #include <sys/time.h> |
|
|
70 | #include <sys/select.h> |
|
|
71 | #include <unistd.h> |
|
|
72 | #include <utime.h> |
|
|
73 | #include <signal.h> |
|
|
74 | |
|
|
75 | #endif |
82 | |
76 | |
83 | #define EIO_STRUCT_STAT Stat_t |
77 | #define EIO_STRUCT_STAT Stat_t |
84 | |
78 | |
85 | /* use NV for 32 bit perls as it allows larger offsets */ |
79 | /* use NV for 32 bit perls as it allows larger offsets */ |
86 | #if IVSIZE >= 8 |
80 | #if IVSIZE >= 8 |
… | |
… | |
118 | STRLEN stroffset; \ |
112 | STRLEN stroffset; \ |
119 | SV *self; |
113 | SV *self; |
120 | |
114 | |
121 | #define EIO_NO_WRAPPERS 1 |
115 | #define EIO_NO_WRAPPERS 1 |
122 | |
116 | |
|
|
117 | #include "libeio/config.h" |
123 | #include "libeio/eio.h" |
118 | #include "libeio/eio.h" |
|
|
119 | |
|
|
120 | static int req_invoke (eio_req *req); |
|
|
121 | #define EIO_FINISH(req) req_invoke (req) |
|
|
122 | static void req_destroy (eio_req *grp); |
|
|
123 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
124 | |
|
|
125 | #include "libeio/eio.c" |
|
|
126 | |
|
|
127 | /* Linux/others */ |
|
|
128 | #ifndef O_ASYNC |
|
|
129 | # define O_ASYNC 0 |
|
|
130 | #endif |
|
|
131 | #ifndef O_DIRECT |
|
|
132 | # define O_DIRECT 0 |
|
|
133 | #endif |
|
|
134 | #ifndef O_NOATIME |
|
|
135 | # define O_NOATIME 0 |
|
|
136 | #endif |
|
|
137 | |
|
|
138 | /* POSIX */ |
|
|
139 | #ifndef O_CLOEXEC |
|
|
140 | # define O_CLOEXEC 0 |
|
|
141 | #endif |
|
|
142 | #ifndef O_NOFOLLOW |
|
|
143 | # define O_NOFOLLOW 0 |
|
|
144 | #endif |
|
|
145 | #ifndef O_NOCTTY |
|
|
146 | # define O_NOCTTY 0 |
|
|
147 | #endif |
|
|
148 | #ifndef O_NONBLOCK |
|
|
149 | # define O_NONBLOCK 0 |
|
|
150 | #endif |
|
|
151 | #ifndef O_EXEC |
|
|
152 | # define O_EXEC 0 |
|
|
153 | #endif |
|
|
154 | #ifndef O_SEARCH |
|
|
155 | # define O_SEARCH 0 |
|
|
156 | #endif |
|
|
157 | #ifndef O_DIRECTORY |
|
|
158 | # define O_DIRECTORY 0 |
|
|
159 | #endif |
|
|
160 | #ifndef O_DSYNC |
|
|
161 | # define O_DSYNC 0 |
|
|
162 | #endif |
|
|
163 | #ifndef O_RSYNC |
|
|
164 | # define O_RSYNC 0 |
|
|
165 | #endif |
|
|
166 | #ifndef O_SYNC |
|
|
167 | # define O_SYNC 0 |
|
|
168 | #endif |
|
|
169 | #ifndef O_TTY_INIT |
|
|
170 | # define O_TTY_INIT 0 |
|
|
171 | #endif |
124 | |
172 | |
125 | #ifndef POSIX_FADV_NORMAL |
173 | #ifndef POSIX_FADV_NORMAL |
126 | # define POSIX_FADV_NORMAL 0 |
174 | # define POSIX_FADV_NORMAL 0 |
127 | # define NO_FADVISE 1 |
|
|
128 | #endif |
175 | #endif |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
176 | #ifndef POSIX_FADV_SEQUENTIAL |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
177 | # define POSIX_FADV_SEQUENTIAL 0 |
131 | #endif |
178 | #endif |
132 | #ifndef POSIX_FADV_RANDOM |
179 | #ifndef POSIX_FADV_RANDOM |
… | |
… | |
140 | #endif |
187 | #endif |
141 | #ifndef POSIX_FADV_DONTNEED |
188 | #ifndef POSIX_FADV_DONTNEED |
142 | # define POSIX_FADV_DONTNEED 0 |
189 | # define POSIX_FADV_DONTNEED 0 |
143 | #endif |
190 | #endif |
144 | |
191 | |
145 | #if _XOPEN_SOURCE < 600 || NO_FADVISE |
192 | #if !HAVE_POSIX_FADVISE |
146 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
193 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
147 | #endif |
194 | #endif |
148 | |
195 | |
149 | #ifndef POSIX_MADV_NORMAL |
196 | #ifndef POSIX_MADV_NORMAL |
150 | # define POSIX_MADV_NORMAL 0 |
197 | # define POSIX_MADV_NORMAL 0 |
151 | # define NO_MADVISE 1 |
|
|
152 | #endif |
198 | #endif |
153 | #ifndef POSIX_MADV_SEQUENTIAL |
199 | #ifndef POSIX_MADV_SEQUENTIAL |
154 | # define POSIX_MADV_SEQUENTIAL 0 |
200 | # define POSIX_MADV_SEQUENTIAL 0 |
155 | #endif |
201 | #endif |
156 | #ifndef POSIX_MADV_RANDOM |
202 | #ifndef POSIX_MADV_RANDOM |
… | |
… | |
161 | #endif |
207 | #endif |
162 | #ifndef POSIX_MADV_DONTNEED |
208 | #ifndef POSIX_MADV_DONTNEED |
163 | # define POSIX_MADV_DONTNEED 0 |
209 | # define POSIX_MADV_DONTNEED 0 |
164 | #endif |
210 | #endif |
165 | |
211 | |
166 | #if _XOPEN_SOURCE < 600 || NO_MADVISE |
212 | #if !HAVE_POSIX_MADVISE |
167 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
213 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
168 | #endif |
214 | #endif |
169 | |
215 | |
170 | #ifndef PROT_NONE |
216 | #ifndef PROT_NONE |
171 | # define PROT_NONE 0 |
217 | # define PROT_NONE 0 |
… | |
… | |
178 | #endif |
224 | #endif |
179 | #ifndef PROT_EXEC |
225 | #ifndef PROT_EXEC |
180 | # define PROT_EXEC 0 |
226 | # define PROT_EXEC 0 |
181 | #endif |
227 | #endif |
182 | |
228 | |
|
|
229 | #ifndef ST_RDONLY |
|
|
230 | # define ST_RDONLY 0 |
|
|
231 | #endif |
|
|
232 | #ifndef ST_NOSUID |
|
|
233 | # define ST_NOSUID 0 |
|
|
234 | #endif |
183 | #ifndef ST_NODEV |
235 | #ifndef ST_NODEV |
184 | # define ST_NODEV 0 |
236 | # define ST_NODEV 0 |
185 | #endif |
237 | #endif |
186 | #ifndef ST_NOEXEC |
238 | #ifndef ST_NOEXEC |
187 | # define ST_NOEXEC 0 |
239 | # define ST_NOEXEC 0 |
… | |
… | |
207 | #ifndef ST_NODIRATIME |
259 | #ifndef ST_NODIRATIME |
208 | # define ST_NODIRATIME 0 |
260 | # define ST_NODIRATIME 0 |
209 | #endif |
261 | #endif |
210 | #ifndef ST_RELATIME |
262 | #ifndef ST_RELATIME |
211 | # define ST_RELATIME 0 |
263 | # define ST_RELATIME 0 |
|
|
264 | #endif |
|
|
265 | |
|
|
266 | #ifndef S_IFIFO |
|
|
267 | # define S_IFIFO 0 |
|
|
268 | #endif |
|
|
269 | #ifndef S_IFCHR |
|
|
270 | # define S_IFCHR 0 |
|
|
271 | #endif |
|
|
272 | #ifndef S_IFBLK |
|
|
273 | # define S_IFBLK 0 |
|
|
274 | #endif |
|
|
275 | #ifndef S_IFLNK |
|
|
276 | # define S_IFLNK 0 |
|
|
277 | #endif |
|
|
278 | #ifndef S_IFREG |
|
|
279 | # define S_IFREG 0 |
|
|
280 | #endif |
|
|
281 | #ifndef S_IFDIR |
|
|
282 | # define S_IFDIR 0 |
|
|
283 | #endif |
|
|
284 | #ifndef S_IFWHT |
|
|
285 | # define S_IFWHT 0 |
|
|
286 | #endif |
|
|
287 | #ifndef S_IFSOCK |
|
|
288 | # define S_IFSOCK 0 |
212 | #endif |
289 | #endif |
213 | |
290 | |
214 | #ifndef MAP_ANONYMOUS |
291 | #ifndef MAP_ANONYMOUS |
215 | # ifdef MAP_ANON |
292 | # ifdef MAP_ANON |
216 | # define MAP_ANONYMOUS MAP_ANON |
293 | # define MAP_ANONYMOUS MAP_ANON |
… | |
… | |
232 | #endif |
309 | #endif |
233 | #ifndef MAP_NONBLOCK |
310 | #ifndef MAP_NONBLOCK |
234 | # define MAP_NONBLOCK 0 |
311 | # define MAP_NONBLOCK 0 |
235 | #endif |
312 | #endif |
236 | |
313 | |
|
|
314 | #ifndef makedev |
|
|
315 | # define makedev(maj,min) (((maj) << 8) | (min)) |
|
|
316 | #endif |
|
|
317 | #ifndef major |
|
|
318 | # define major(dev) ((dev) >> 8) |
|
|
319 | #endif |
|
|
320 | #ifndef minor |
|
|
321 | # define minor(dev) ((dev) & 0xff) |
|
|
322 | #endif |
|
|
323 | |
237 | #ifndef PAGESIZE |
324 | #ifndef PAGESIZE |
238 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
325 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
239 | #endif |
326 | #endif |
240 | |
|
|
241 | static int req_invoke (eio_req *req); |
|
|
242 | #define EIO_FINISH(req) req_invoke (req) |
|
|
243 | static void req_destroy (eio_req *grp); |
|
|
244 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
245 | |
327 | |
246 | enum { |
328 | enum { |
247 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
329 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
248 | }; |
330 | }; |
249 | |
|
|
250 | #include "libeio/eio.c" |
|
|
251 | |
331 | |
252 | typedef eio_req *aio_req; |
332 | typedef eio_req *aio_req; |
253 | typedef eio_req *aio_req_ornot; |
333 | typedef eio_req *aio_req_ornot; |
254 | |
334 | |
255 | static SV *on_next_submit; |
335 | static SV *on_next_submit; |
… | |
… | |
354 | /* do not recreate the result IV from scratch each time */ |
434 | /* do not recreate the result IV from scratch each time */ |
355 | if (expect_true (sv_result_cache)) |
435 | if (expect_true (sv_result_cache)) |
356 | { |
436 | { |
357 | sv_result = sv_result_cache; sv_result_cache = 0; |
437 | sv_result = sv_result_cache; sv_result_cache = 0; |
358 | SvIV_set (sv_result, req->result); |
438 | SvIV_set (sv_result, req->result); |
|
|
439 | SvIOK_only (sv_result); |
359 | } |
440 | } |
360 | else |
441 | else |
361 | { |
442 | { |
362 | sv_result = newSViv (req->result); |
443 | sv_result = newSViv (req->result); |
363 | SvREADONLY_on (sv_result); |
444 | SvREADONLY_on (sv_result); |
… | |
… | |
460 | case EIO_STATVFS: |
541 | case EIO_STATVFS: |
461 | case EIO_FSTATVFS: |
542 | case EIO_FSTATVFS: |
462 | { |
543 | { |
463 | SV *rv = &PL_sv_undef; |
544 | SV *rv = &PL_sv_undef; |
464 | |
545 | |
|
|
546 | #ifndef _WIN32 |
465 | if (req->result >= 0) |
547 | if (req->result >= 0) |
466 | { |
548 | { |
467 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
549 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
468 | HV *hv = newHV (); |
550 | HV *hv = newHV (); |
469 | |
551 | |
… | |
… | |
479 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
561 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
480 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
562 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
481 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
563 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
482 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
564 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
483 | } |
565 | } |
|
|
566 | #endif |
484 | |
567 | |
485 | PUSHs (rv); |
568 | PUSHs (rv); |
486 | } |
569 | } |
487 | |
570 | |
488 | break; |
571 | break; |
… | |
… | |
504 | case EIO_NOP: |
587 | case EIO_NOP: |
505 | case EIO_BUSY: |
588 | case EIO_BUSY: |
506 | break; |
589 | break; |
507 | |
590 | |
508 | case EIO_READLINK: |
591 | case EIO_READLINK: |
|
|
592 | case EIO_REALPATH: |
509 | if (req->result > 0) |
593 | if (req->result > 0) |
510 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
594 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
511 | break; |
595 | break; |
512 | |
596 | |
513 | case EIO_STAT: |
597 | case EIO_STAT: |
514 | case EIO_LSTAT: |
598 | case EIO_LSTAT: |
515 | case EIO_FSTAT: |
599 | case EIO_FSTAT: |
516 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
600 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
517 | PL_laststatval = req->result; |
601 | PL_laststatval = req->result; |
|
|
602 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
518 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
603 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
519 | PUSHs (sv_result); |
604 | PUSHs (sv_result); |
520 | break; |
605 | break; |
521 | |
606 | |
522 | case EIO_READ: |
607 | case EIO_READ: |
… | |
… | |
527 | SvSETMAGIC (req->sv2); |
612 | SvSETMAGIC (req->sv2); |
528 | PUSHs (sv_result); |
613 | PUSHs (sv_result); |
529 | } |
614 | } |
530 | break; |
615 | break; |
531 | |
616 | |
532 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
617 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
533 | if (req->result > 0) |
618 | if (req->result > 0) |
534 | SvIV_set (sv_result, 0); |
619 | SvIV_set (sv_result, 0); |
535 | /* FALLTHROUGH */ |
620 | /* FALLTHROUGH */ |
536 | |
621 | |
537 | default: |
622 | default: |
… | |
… | |
574 | Safefree (req); |
659 | Safefree (req); |
575 | } |
660 | } |
576 | |
661 | |
577 | static void req_cancel_subs (aio_req grp) |
662 | static void req_cancel_subs (aio_req grp) |
578 | { |
663 | { |
579 | aio_req sub; |
|
|
580 | |
|
|
581 | if (grp->type != EIO_GROUP) |
664 | if (grp->type != EIO_GROUP) |
582 | return; |
665 | return; |
583 | |
666 | |
584 | SvREFCNT_dec (grp->sv2); |
667 | SvREFCNT_dec (grp->sv2); |
585 | grp->sv2 = 0; |
668 | grp->sv2 = 0; |
586 | |
669 | |
587 | eio_grp_cancel (grp); |
670 | eio_grp_cancel (grp); |
588 | } |
671 | } |
589 | |
672 | |
590 | static void |
|
|
591 | create_respipe (void) |
673 | static void create_respipe (void) |
592 | { |
674 | { |
593 | if (s_epipe_renew (&respipe)) |
675 | if (s_epipe_renew (&respipe)) |
594 | croak ("IO::AIO: unable to initialize result pipe"); |
676 | croak ("IO::AIO: unable to initialize result pipe"); |
595 | } |
677 | } |
596 | |
678 | |
… | |
… | |
627 | |
709 | |
628 | poll_wait (); |
710 | poll_wait (); |
629 | } |
711 | } |
630 | } |
712 | } |
631 | |
713 | |
632 | static void atfork_child (void) |
714 | static void ecb_cold |
|
|
715 | reinit (void) |
633 | { |
716 | { |
634 | create_respipe (); |
717 | create_respipe (); |
|
|
718 | |
|
|
719 | if (eio_init (want_poll, done_poll) < 0) |
|
|
720 | croak ("IO::AIO: unable to initialise eio library"); |
635 | } |
721 | } |
636 | |
722 | |
637 | /*****************************************************************************/ |
723 | /*****************************************************************************/ |
638 | |
724 | |
639 | #if !_POSIX_MAPPED_FILES |
725 | #if !_POSIX_MAPPED_FILES |
640 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
726 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
641 | # define munmap(addr,length) (errno = ENOSYS, -1) |
727 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
728 | #endif |
|
|
729 | |
|
|
730 | #if !_POSIX_MEMORY_PROTECTION |
642 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
731 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
732 | # define PROT_NONE 0 |
|
|
733 | # define PROT_WRITE 0 |
|
|
734 | # define MAP_PRIVATE 0 |
|
|
735 | # define MAP_SHARED 0 |
|
|
736 | # define MAP_FIXED 0 |
643 | #endif |
737 | #endif |
644 | |
738 | |
645 | #define MMAP_MAGIC PERL_MAGIC_ext |
739 | #define MMAP_MAGIC PERL_MAGIC_ext |
646 | |
740 | |
647 | static int |
|
|
648 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
741 | static int mmap_free (pTHX_ SV *sv, MAGIC *mg) |
649 | { |
742 | { |
650 | int old_errno = errno; |
743 | int old_errno = errno; |
651 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
744 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
652 | errno = old_errno; |
745 | errno = old_errno; |
653 | |
746 | |
… | |
… | |
669 | 0, 0, 0, 0, mmap_free |
762 | 0, 0, 0, 0, mmap_free |
670 | }; |
763 | }; |
671 | |
764 | |
672 | /*****************************************************************************/ |
765 | /*****************************************************************************/ |
673 | |
766 | |
674 | static SV * |
|
|
675 | get_cb (SV *cb_sv) |
767 | static SV * get_cb (SV *cb_sv) |
676 | { |
768 | { |
677 | SvGETMAGIC (cb_sv); |
769 | SvGETMAGIC (cb_sv); |
678 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
770 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
679 | } |
771 | } |
680 | |
772 | |
… | |
… | |
721 | const_iv (O_RDWR) |
813 | const_iv (O_RDWR) |
722 | const_iv (O_CREAT) |
814 | const_iv (O_CREAT) |
723 | const_iv (O_TRUNC) |
815 | const_iv (O_TRUNC) |
724 | const_iv (O_EXCL) |
816 | const_iv (O_EXCL) |
725 | const_iv (O_APPEND) |
817 | const_iv (O_APPEND) |
726 | #ifndef _WIN32 |
818 | |
|
|
819 | const_iv (O_ASYNC) |
|
|
820 | const_iv (O_DIRECT) |
|
|
821 | const_iv (O_NOATIME) |
|
|
822 | |
|
|
823 | const_iv (O_CLOEXEC) |
|
|
824 | const_iv (O_NOCTTY) |
|
|
825 | const_iv (O_NOFOLLOW) |
|
|
826 | const_iv (O_NONBLOCK) |
|
|
827 | const_iv (O_EXEC) |
|
|
828 | const_iv (O_SEARCH) |
|
|
829 | const_iv (O_DIRECTORY) |
|
|
830 | const_iv (O_DSYNC) |
|
|
831 | const_iv (O_RSYNC) |
|
|
832 | const_iv (O_SYNC) |
|
|
833 | const_iv (O_TTY_INIT) |
|
|
834 | |
727 | const_iv (S_IFIFO) |
835 | const_iv (S_IFIFO) |
728 | #endif |
836 | const_iv (S_IFCHR) |
|
|
837 | const_iv (S_IFBLK) |
|
|
838 | const_iv (S_IFLNK) |
|
|
839 | const_iv (S_IFREG) |
|
|
840 | const_iv (S_IFDIR) |
|
|
841 | const_iv (S_IFWHT) |
|
|
842 | const_iv (S_IFSOCK) |
|
|
843 | const_iv (S_IFMT) |
|
|
844 | |
729 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
845 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
730 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
846 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
731 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
847 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
732 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
848 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
733 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
849 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
… | |
… | |
780 | |
896 | |
781 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
897 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
782 | const_eio (SYNC_FILE_RANGE_WRITE) |
898 | const_eio (SYNC_FILE_RANGE_WRITE) |
783 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
899 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
784 | |
900 | |
|
|
901 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
902 | |
785 | const_eio (READDIR_DENTS) |
903 | const_eio (READDIR_DENTS) |
786 | const_eio (READDIR_DIRS_FIRST) |
904 | const_eio (READDIR_DIRS_FIRST) |
787 | const_eio (READDIR_STAT_ORDER) |
905 | const_eio (READDIR_STAT_ORDER) |
788 | const_eio (READDIR_FOUND_UNKNOWN) |
906 | const_eio (READDIR_FOUND_UNKNOWN) |
789 | |
907 | |
… | |
… | |
805 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
923 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
806 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
924 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
807 | |
925 | |
808 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
926 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
809 | |
927 | |
810 | create_respipe (); |
928 | reinit (); |
811 | |
|
|
812 | if (eio_init (want_poll, done_poll) < 0) |
|
|
813 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
814 | |
|
|
815 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
816 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
817 | } |
929 | } |
818 | |
930 | |
819 | void |
931 | void |
|
|
932 | reinit () |
|
|
933 | PROTOTYPE: |
|
|
934 | CODE: |
|
|
935 | reinit (); |
|
|
936 | |
|
|
937 | void |
820 | max_poll_reqs (int nreqs) |
938 | max_poll_reqs (unsigned int nreqs) |
821 | PROTOTYPE: $ |
939 | PROTOTYPE: $ |
822 | CODE: |
940 | CODE: |
823 | eio_set_max_poll_reqs (nreqs); |
941 | eio_set_max_poll_reqs (nreqs); |
824 | |
942 | |
825 | void |
943 | void |
… | |
… | |
827 | PROTOTYPE: $ |
945 | PROTOTYPE: $ |
828 | CODE: |
946 | CODE: |
829 | eio_set_max_poll_time (nseconds); |
947 | eio_set_max_poll_time (nseconds); |
830 | |
948 | |
831 | void |
949 | void |
832 | min_parallel (int nthreads) |
950 | min_parallel (unsigned int nthreads) |
833 | PROTOTYPE: $ |
951 | PROTOTYPE: $ |
834 | CODE: |
952 | CODE: |
835 | eio_set_min_parallel (nthreads); |
953 | eio_set_min_parallel (nthreads); |
836 | |
954 | |
837 | void |
955 | void |
838 | max_parallel (int nthreads) |
956 | max_parallel (unsigned int nthreads) |
839 | PROTOTYPE: $ |
957 | PROTOTYPE: $ |
840 | CODE: |
958 | CODE: |
841 | eio_set_max_parallel (nthreads); |
959 | eio_set_max_parallel (nthreads); |
842 | |
960 | |
843 | void |
961 | void |
844 | max_idle (int nthreads) |
962 | max_idle (unsigned int nthreads) |
845 | PROTOTYPE: $ |
963 | PROTOTYPE: $ |
846 | CODE: |
964 | CODE: |
847 | eio_set_max_idle (nthreads); |
965 | eio_set_max_idle (nthreads); |
848 | |
966 | |
849 | void |
967 | void |
|
|
968 | idle_timeout (unsigned int seconds) |
|
|
969 | PROTOTYPE: $ |
|
|
970 | CODE: |
|
|
971 | eio_set_idle_timeout (seconds); |
|
|
972 | |
|
|
973 | void |
850 | max_outstanding (int maxreqs) |
974 | max_outstanding (unsigned int maxreqs) |
851 | PROTOTYPE: $ |
975 | PROTOTYPE: $ |
852 | CODE: |
976 | CODE: |
853 | max_outstanding = maxreqs; |
977 | max_outstanding = maxreqs; |
854 | |
978 | |
855 | void |
979 | void |
… | |
… | |
900 | |
1024 | |
901 | REQ_SEND (req); |
1025 | REQ_SEND (req); |
902 | } |
1026 | } |
903 | |
1027 | |
904 | void |
1028 | void |
|
|
1029 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
|
|
1030 | PPCODE: |
|
|
1031 | { |
|
|
1032 | int fd = s_fileno_croak (fh, 0); |
|
|
1033 | dREQ; |
|
|
1034 | |
|
|
1035 | req->type = EIO_FALLOCATE; |
|
|
1036 | req->sv1 = newSVsv (fh); |
|
|
1037 | req->int1 = fd; |
|
|
1038 | req->int2 = mode; |
|
|
1039 | req->offs = offset; |
|
|
1040 | req->size = len; |
|
|
1041 | |
|
|
1042 | REQ_SEND (req); |
|
|
1043 | } |
|
|
1044 | |
|
|
1045 | void |
905 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1046 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
906 | PPCODE: |
1047 | PPCODE: |
907 | { |
1048 | { |
908 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
1049 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
909 | int fd = s_fileno_croak (fh, 0); |
1050 | int fd = s_fileno_croak (fh, 0); |
910 | dREQ; |
1051 | dREQ; |
911 | |
1052 | |
912 | if (close_pipe < 0) |
1053 | if (expect_false (close_fd < 0)) |
913 | { |
1054 | { |
914 | int pipefd [2]; |
1055 | int pipefd [2]; |
915 | |
1056 | |
|
|
1057 | if ( |
|
|
1058 | #ifdef _WIN32 |
|
|
1059 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1060 | #else |
916 | if (pipe (pipefd) < 0 |
1061 | pipe (pipefd) < 0 |
917 | || close (pipefd [1]) < 0 |
|
|
918 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1062 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 |
|
|
1063 | #endif |
|
|
1064 | || close (pipefd [1]) < 0 |
|
|
1065 | ) |
919 | abort (); /*D*/ |
1066 | abort (); /*D*/ |
920 | |
1067 | |
921 | close_pipe = pipefd [0]; |
1068 | close_fd = pipefd [0]; |
922 | } |
1069 | } |
923 | |
1070 | |
924 | req->type = EIO_DUP2; |
1071 | req->type = EIO_DUP2; |
925 | req->int1 = close_pipe; |
1072 | req->int1 = close_fd; |
926 | req->sv2 = newSVsv (fh); |
1073 | req->sv2 = newSVsv (fh); |
927 | req->int2 = fd; |
1074 | req->int2 = fd; |
928 | |
1075 | |
929 | REQ_SEND (req); |
1076 | REQ_SEND (req); |
930 | } |
1077 | } |
… | |
… | |
982 | } |
1129 | } |
983 | } |
1130 | } |
984 | |
1131 | |
985 | void |
1132 | void |
986 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1133 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
|
|
1134 | ALIAS: |
|
|
1135 | aio_readlink = EIO_READLINK |
|
|
1136 | aio_realpath = EIO_REALPATH |
987 | PPCODE: |
1137 | PPCODE: |
988 | { |
1138 | { |
989 | SV *data; |
|
|
990 | dREQ; |
1139 | dREQ; |
991 | |
1140 | |
992 | req->type = EIO_READLINK; |
1141 | req->type = ix; |
993 | req->sv1 = newSVsv (path); |
1142 | req->sv1 = newSVsv (path); |
994 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1143 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
995 | |
1144 | |
996 | REQ_SEND; |
1145 | REQ_SEND; |
997 | } |
1146 | } |
… | |
… | |
1055 | } |
1204 | } |
1056 | |
1205 | |
1057 | REQ_SEND; |
1206 | REQ_SEND; |
1058 | } |
1207 | } |
1059 | |
1208 | |
|
|
1209 | UV |
|
|
1210 | major (UV dev) |
|
|
1211 | ALIAS: |
|
|
1212 | minor = 1 |
|
|
1213 | CODE: |
|
|
1214 | RETVAL = ix ? major (dev) : minor (dev); |
|
|
1215 | OUTPUT: |
|
|
1216 | RETVAL |
|
|
1217 | |
|
|
1218 | UV |
|
|
1219 | makedev (UV maj, UV min) |
|
|
1220 | CODE: |
|
|
1221 | RETVAL = makedev (maj, min); |
|
|
1222 | OUTPUT: |
|
|
1223 | RETVAL |
|
|
1224 | |
1060 | void |
1225 | void |
1061 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1226 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1062 | PPCODE: |
1227 | PPCODE: |
1063 | { |
1228 | { |
1064 | dREQ; |
1229 | dREQ; |
… | |
… | |
1257 | |
1422 | |
1258 | void |
1423 | void |
1259 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
1424 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
1260 | PPCODE: |
1425 | PPCODE: |
1261 | { |
1426 | { |
1262 | |
|
|
1263 | STRLEN svlen; |
1427 | STRLEN svlen; |
1264 | char *svptr = SvPVbyte (data, svlen); |
1428 | char *svptr = SvPVbyte (data, svlen); |
1265 | UV len = SvUV (length); |
1429 | UV len = SvUV (length); |
1266 | |
1430 | |
1267 | if (offset < 0) |
1431 | if (offset < 0) |
… | |
… | |
1520 | if (!SvOK (length) || len + offset > svlen) |
1684 | if (!SvOK (length) || len + offset > svlen) |
1521 | len = svlen - offset; |
1685 | len = svlen - offset; |
1522 | |
1686 | |
1523 | addr = (void *)(((intptr_t)addr) + offset); |
1687 | addr = (void *)(((intptr_t)addr) + offset); |
1524 | eio_page_align (&addr, &len); |
1688 | eio_page_align (&addr, &len); |
1525 | #if _POSIX_MEMLOCK |
1689 | #if _POSIX_MEMLOCK_RANGE |
1526 | RETVAL = munlock (addr, len); |
1690 | RETVAL = munlock (addr, len); |
1527 | #else |
1691 | #else |
1528 | RETVAL = ((errno = ENOSYS), -1); |
1692 | RETVAL = ((errno = ENOSYS), -1); |
1529 | #endif |
1693 | #endif |
1530 | } |
1694 | } |