… | |
… | |
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_MEMLOCK_RANGE || _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 |
82 | |
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 | #define EIO_STRUCT_STAT struct _stati64 |
|
|
68 | #define EIO_STRUCT_STATI64 |
|
|
69 | |
|
|
70 | #else |
|
|
71 | |
|
|
72 | #include <sys/time.h> |
|
|
73 | #include <sys/select.h> |
|
|
74 | #include <unistd.h> |
|
|
75 | #include <utime.h> |
|
|
76 | #include <signal.h> |
|
|
77 | |
83 | #define EIO_STRUCT_STAT Stat_t |
78 | #define EIO_STRUCT_STAT Stat_t |
|
|
79 | |
|
|
80 | #endif |
84 | |
81 | |
85 | /* use NV for 32 bit perls as it allows larger offsets */ |
82 | /* use NV for 32 bit perls as it allows larger offsets */ |
86 | #if IVSIZE >= 8 |
83 | #if IVSIZE >= 8 |
87 | # define VAL64 IV |
84 | # define VAL64 IV |
88 | # define SvVAL64 SvIV |
85 | # define SvVAL64 SvIV |
… | |
… | |
108 | |
105 | |
109 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
106 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
110 | typedef int aio_rfd; /* read file desriptor */ |
107 | typedef int aio_rfd; /* read file desriptor */ |
111 | typedef int aio_wfd; /* write file descriptor */ |
108 | typedef int aio_wfd; /* write file descriptor */ |
112 | |
109 | |
113 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash; |
110 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash; |
114 | |
111 | |
115 | #define EIO_REQ_MEMBERS \ |
112 | #define EIO_REQ_MEMBERS \ |
116 | SV *callback; \ |
113 | SV *callback; \ |
117 | SV *sv1, *sv2; \ |
114 | SV *sv1, *sv2; \ |
|
|
115 | SV *sv3, *sv4; \ |
118 | STRLEN stroffset; \ |
116 | STRLEN stroffset; \ |
119 | SV *self; |
117 | SV *self; |
120 | |
118 | |
121 | #define EIO_NO_WRAPPERS 1 |
119 | #define EIO_NO_WRAPPERS 1 |
122 | |
120 | |
123 | #include "libeio/config.h" |
121 | #include "libeio/config.h" |
124 | #include "libeio/eio.h" |
122 | #include "libeio/eio.h" |
|
|
123 | |
|
|
124 | static int req_invoke (eio_req *req); |
|
|
125 | #define EIO_FINISH(req) req_invoke (req) |
|
|
126 | static void req_destroy (eio_req *grp); |
|
|
127 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
128 | |
|
|
129 | #include "libeio/eio.c" |
125 | |
130 | |
126 | /* Linux/others */ |
131 | /* Linux/others */ |
127 | #ifndef O_ASYNC |
132 | #ifndef O_ASYNC |
128 | # define O_ASYNC 0 |
133 | # define O_ASYNC 0 |
129 | #endif |
134 | #endif |
… | |
… | |
223 | #endif |
228 | #endif |
224 | #ifndef PROT_EXEC |
229 | #ifndef PROT_EXEC |
225 | # define PROT_EXEC 0 |
230 | # define PROT_EXEC 0 |
226 | #endif |
231 | #endif |
227 | |
232 | |
|
|
233 | #ifndef ST_RDONLY |
|
|
234 | # define ST_RDONLY 0 |
|
|
235 | #endif |
|
|
236 | #ifndef ST_NOSUID |
|
|
237 | # define ST_NOSUID 0 |
|
|
238 | #endif |
228 | #ifndef ST_NODEV |
239 | #ifndef ST_NODEV |
229 | # define ST_NODEV 0 |
240 | # define ST_NODEV 0 |
230 | #endif |
241 | #endif |
231 | #ifndef ST_NOEXEC |
242 | #ifndef ST_NOEXEC |
232 | # define ST_NOEXEC 0 |
243 | # define ST_NOEXEC 0 |
… | |
… | |
316 | |
327 | |
317 | #ifndef PAGESIZE |
328 | #ifndef PAGESIZE |
318 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
329 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
319 | #endif |
330 | #endif |
320 | |
331 | |
321 | static int req_invoke (eio_req *req); |
|
|
322 | #define EIO_FINISH(req) req_invoke (req) |
|
|
323 | static void req_destroy (eio_req *grp); |
|
|
324 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
325 | |
|
|
326 | enum { |
332 | enum { |
327 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
333 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
328 | }; |
334 | }; |
329 | |
335 | |
330 | #include "libeio/eio.c" |
|
|
331 | |
|
|
332 | typedef eio_req *aio_req; |
336 | typedef eio_req *aio_req; |
333 | typedef eio_req *aio_req_ornot; |
337 | typedef eio_req *aio_req_ornot; |
|
|
338 | typedef eio_wd aio_wd; |
334 | |
339 | |
335 | static SV *on_next_submit; |
340 | static SV *on_next_submit; |
336 | static int next_pri = EIO_PRI_DEFAULT; |
341 | static int next_pri = EIO_PRI_DEFAULT; |
337 | static int max_outstanding; |
342 | static int max_outstanding; |
338 | |
343 | |
339 | static s_epipe respipe; |
344 | static s_epipe respipe; |
340 | |
345 | |
341 | static void req_destroy (aio_req req); |
346 | static void req_destroy (aio_req req); |
342 | static void req_cancel (aio_req req); |
347 | static void req_cancel (aio_req req); |
343 | |
348 | |
344 | static void want_poll (void) |
349 | static void |
|
|
350 | want_poll (void) |
345 | { |
351 | { |
346 | /* write a dummy byte to the pipe so fh becomes ready */ |
352 | /* write a dummy byte to the pipe so fh becomes ready */ |
347 | s_epipe_signal (&respipe); |
353 | s_epipe_signal (&respipe); |
348 | } |
354 | } |
349 | |
355 | |
350 | static void done_poll (void) |
356 | static void |
|
|
357 | done_poll (void) |
351 | { |
358 | { |
352 | /* read any signals sent by the worker threads */ |
359 | /* read any signals sent by the worker threads */ |
353 | s_epipe_drain (&respipe); |
360 | s_epipe_drain (&respipe); |
354 | } |
361 | } |
355 | |
362 | |
356 | /* must be called at most once */ |
363 | /* must be called at most once */ |
|
|
364 | static SV * |
357 | static SV *req_sv (aio_req req, HV *stash) |
365 | req_sv (aio_req req, HV *stash) |
358 | { |
366 | { |
359 | if (!req->self) |
367 | if (!req->self) |
360 | { |
368 | { |
361 | req->self = (SV *)newHV (); |
369 | req->self = (SV *)newHV (); |
362 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
370 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
363 | } |
371 | } |
364 | |
372 | |
365 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
373 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
366 | } |
374 | } |
367 | |
375 | |
368 | static aio_req SvAIO_REQ (SV *sv) |
376 | static SV * |
|
|
377 | newSVaio_wd (aio_wd wd) |
|
|
378 | { |
|
|
379 | return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); |
|
|
380 | } |
|
|
381 | |
|
|
382 | static aio_req |
|
|
383 | SvAIO_REQ (SV *sv) |
369 | { |
384 | { |
370 | MAGIC *mg; |
385 | MAGIC *mg; |
371 | |
386 | |
372 | if (!SvROK (sv) |
387 | if (!SvROK (sv) |
|
|
388 | /* for speed reasons, we do not verify that SvROK actually has a stash ptr */ |
373 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
389 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
374 | && SvSTASH (SvRV (sv)) != aio_req_stash |
390 | && SvSTASH (SvRV (sv)) != aio_req_stash |
375 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
391 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
376 | croak ("object of class IO::AIO::REQ expected"); |
392 | croak ("object of class IO::AIO::REQ expected"); |
377 | |
393 | |
378 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
394 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
379 | |
395 | |
380 | return mg ? (aio_req)mg->mg_ptr : 0; |
396 | return mg ? (aio_req)mg->mg_ptr : 0; |
381 | } |
397 | } |
382 | |
398 | |
|
|
399 | static aio_wd |
|
|
400 | SvAIO_WD (SV *sv) |
|
|
401 | { |
|
|
402 | if (!SvROK (sv) |
|
|
403 | || SvTYPE (SvRV (sv)) != SVt_PVMG |
|
|
404 | || SvSTASH (SvRV (sv)) != aio_wd_stash) |
|
|
405 | croak ("IO::AIO: expected a working directory object as returned by aio_wd"); |
|
|
406 | |
|
|
407 | return (aio_wd)(long)SvIVX (SvRV (sv)); |
|
|
408 | } |
|
|
409 | |
|
|
410 | static void |
383 | static void aio_grp_feed (aio_req grp) |
411 | aio_grp_feed (aio_req grp) |
384 | { |
412 | { |
385 | if (grp->sv2 && SvOK (grp->sv2)) |
413 | if (grp->sv2 && SvOK (grp->sv2)) |
386 | { |
414 | { |
387 | dSP; |
415 | dSP; |
388 | |
416 | |
… | |
… | |
396 | FREETMPS; |
424 | FREETMPS; |
397 | LEAVE; |
425 | LEAVE; |
398 | } |
426 | } |
399 | } |
427 | } |
400 | |
428 | |
|
|
429 | static void |
401 | static void req_submit (eio_req *req) |
430 | req_submit (eio_req *req) |
402 | { |
431 | { |
403 | eio_submit (req); |
432 | eio_submit (req); |
404 | |
433 | |
405 | if (expect_false (on_next_submit)) |
434 | if (expect_false (on_next_submit)) |
406 | { |
435 | { |
… | |
… | |
413 | PUTBACK; |
442 | PUTBACK; |
414 | call_sv (cb, G_DISCARD | G_EVAL); |
443 | call_sv (cb, G_DISCARD | G_EVAL); |
415 | } |
444 | } |
416 | } |
445 | } |
417 | |
446 | |
|
|
447 | static int |
418 | static int req_invoke (eio_req *req) |
448 | req_invoke (eio_req *req) |
419 | { |
449 | { |
420 | if (req->flags & FLAG_SV2_RO_OFF) |
450 | if (req->flags & FLAG_SV2_RO_OFF) |
421 | SvREADONLY_off (req->sv2); |
451 | SvREADONLY_off (req->sv2); |
422 | |
452 | |
423 | if (!EIO_CANCELLED (req) && req->callback) |
453 | if (!EIO_CANCELLED (req) && req->callback) |
… | |
… | |
444 | SvREADONLY_on (sv_result); |
474 | SvREADONLY_on (sv_result); |
445 | } |
475 | } |
446 | |
476 | |
447 | switch (req->type) |
477 | switch (req->type) |
448 | { |
478 | { |
|
|
479 | case EIO_WD_OPEN: |
|
|
480 | PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd))); |
|
|
481 | break; |
|
|
482 | |
449 | case EIO_READDIR: |
483 | case EIO_READDIR: |
450 | { |
484 | { |
451 | SV *rv = &PL_sv_undef; |
485 | SV *rv = &PL_sv_undef; |
452 | |
486 | |
453 | if (req->result >= 0) |
487 | if (req->result >= 0) |
… | |
… | |
541 | case EIO_STATVFS: |
575 | case EIO_STATVFS: |
542 | case EIO_FSTATVFS: |
576 | case EIO_FSTATVFS: |
543 | { |
577 | { |
544 | SV *rv = &PL_sv_undef; |
578 | SV *rv = &PL_sv_undef; |
545 | |
579 | |
|
|
580 | #ifndef _WIN32 |
546 | if (req->result >= 0) |
581 | if (req->result >= 0) |
547 | { |
582 | { |
548 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
583 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
549 | HV *hv = newHV (); |
584 | HV *hv = newHV (); |
550 | |
585 | |
… | |
… | |
560 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
595 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
561 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
596 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
562 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
597 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
563 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
598 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
564 | } |
599 | } |
|
|
600 | #endif |
565 | |
601 | |
566 | PUSHs (rv); |
602 | PUSHs (rv); |
567 | } |
603 | } |
568 | |
604 | |
569 | break; |
605 | break; |
… | |
… | |
593 | break; |
629 | break; |
594 | |
630 | |
595 | case EIO_STAT: |
631 | case EIO_STAT: |
596 | case EIO_LSTAT: |
632 | case EIO_LSTAT: |
597 | case EIO_FSTAT: |
633 | case EIO_FSTAT: |
598 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
634 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
635 | |
599 | PL_laststatval = req->result; |
636 | if (!(PL_laststatval = req->result)) |
|
|
637 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
600 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
638 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
|
|
639 | |
601 | PUSHs (sv_result); |
640 | PUSHs (sv_result); |
|
|
641 | break; |
|
|
642 | |
|
|
643 | case EIO_SEEK: |
|
|
644 | PUSHs (req->result ? sv_result : sv_2mortal (newSVval64 (req->offs))); |
602 | break; |
645 | break; |
603 | |
646 | |
604 | case EIO_READ: |
647 | case EIO_READ: |
605 | { |
648 | { |
606 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
649 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
… | |
… | |
639 | } |
682 | } |
640 | |
683 | |
641 | return !!SvTRUE (ERRSV); |
684 | return !!SvTRUE (ERRSV); |
642 | } |
685 | } |
643 | |
686 | |
|
|
687 | static void |
644 | static void req_destroy (aio_req req) |
688 | req_destroy (aio_req req) |
645 | { |
689 | { |
646 | if (req->self) |
690 | if (req->self) |
647 | { |
691 | { |
648 | sv_unmagic (req->self, PERL_MAGIC_ext); |
692 | sv_unmagic (req->self, PERL_MAGIC_ext); |
649 | SvREFCNT_dec (req->self); |
693 | SvREFCNT_dec (req->self); |
650 | } |
694 | } |
651 | |
695 | |
652 | SvREFCNT_dec (req->sv1); |
696 | SvREFCNT_dec (req->sv1); |
653 | SvREFCNT_dec (req->sv2); |
697 | SvREFCNT_dec (req->sv2); |
|
|
698 | SvREFCNT_dec (req->sv3); |
|
|
699 | SvREFCNT_dec (req->sv4); |
654 | SvREFCNT_dec (req->callback); |
700 | SvREFCNT_dec (req->callback); |
655 | |
701 | |
656 | Safefree (req); |
702 | free (req); |
657 | } |
703 | } |
658 | |
704 | |
|
|
705 | static void |
659 | static void req_cancel_subs (aio_req grp) |
706 | req_cancel_subs (aio_req grp) |
660 | { |
707 | { |
661 | aio_req sub; |
|
|
662 | |
|
|
663 | if (grp->type != EIO_GROUP) |
708 | if (grp->type != EIO_GROUP) |
664 | return; |
709 | return; |
665 | |
710 | |
666 | SvREFCNT_dec (grp->sv2); |
711 | SvREFCNT_dec (grp->sv2); |
667 | grp->sv2 = 0; |
712 | grp->sv2 = 0; |
668 | |
713 | |
669 | eio_grp_cancel (grp); |
714 | eio_grp_cancel (grp); |
670 | } |
715 | } |
671 | |
716 | |
672 | static void |
717 | static void ecb_cold |
673 | create_respipe (void) |
718 | create_respipe (void) |
674 | { |
719 | { |
675 | if (s_epipe_renew (&respipe)) |
720 | if (s_epipe_renew (&respipe)) |
676 | croak ("IO::AIO: unable to initialize result pipe"); |
721 | croak ("IO::AIO: unable to initialize result pipe"); |
677 | } |
722 | } |
678 | |
723 | |
679 | static void poll_wait (void) |
724 | static void |
|
|
725 | poll_wait (void) |
680 | { |
726 | { |
681 | while (eio_nreqs ()) |
727 | while (eio_nreqs ()) |
682 | { |
728 | { |
683 | int size; |
729 | int size; |
684 | |
730 | |
… | |
… | |
693 | |
739 | |
694 | s_epipe_wait (&respipe); |
740 | s_epipe_wait (&respipe); |
695 | } |
741 | } |
696 | } |
742 | } |
697 | |
743 | |
698 | static int poll_cb (void) |
744 | static int |
|
|
745 | poll_cb (void) |
699 | { |
746 | { |
700 | for (;;) |
747 | for (;;) |
701 | { |
748 | { |
702 | int res = eio_poll (); |
749 | int res = eio_poll (); |
703 | |
750 | |
… | |
… | |
709 | |
756 | |
710 | poll_wait (); |
757 | poll_wait (); |
711 | } |
758 | } |
712 | } |
759 | } |
713 | |
760 | |
714 | static void atfork_child (void) |
761 | static void ecb_cold |
|
|
762 | reinit (void) |
715 | { |
763 | { |
716 | create_respipe (); |
764 | create_respipe (); |
|
|
765 | |
|
|
766 | if (eio_init (want_poll, done_poll) < 0) |
|
|
767 | croak ("IO::AIO: unable to initialise eio library"); |
717 | } |
768 | } |
718 | |
769 | |
719 | /*****************************************************************************/ |
770 | /*****************************************************************************/ |
720 | |
771 | |
721 | #if !_POSIX_MAPPED_FILES |
772 | #if !_POSIX_MAPPED_FILES |
… | |
… | |
732 | # define MAP_FIXED 0 |
783 | # define MAP_FIXED 0 |
733 | #endif |
784 | #endif |
734 | |
785 | |
735 | #define MMAP_MAGIC PERL_MAGIC_ext |
786 | #define MMAP_MAGIC PERL_MAGIC_ext |
736 | |
787 | |
737 | static int |
788 | static int ecb_cold |
738 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
789 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
739 | { |
790 | { |
740 | int old_errno = errno; |
791 | int old_errno = errno; |
741 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
792 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
742 | errno = old_errno; |
793 | errno = old_errno; |
… | |
… | |
766 | { |
817 | { |
767 | SvGETMAGIC (cb_sv); |
818 | SvGETMAGIC (cb_sv); |
768 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
819 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
769 | } |
820 | } |
770 | |
821 | |
|
|
822 | static aio_req ecb_noinline |
|
|
823 | dreq (SV *callback) |
|
|
824 | { |
|
|
825 | SV *cb_cv; |
|
|
826 | aio_req req; |
|
|
827 | int req_pri = next_pri; |
|
|
828 | next_pri = EIO_PRI_DEFAULT; |
|
|
829 | |
|
|
830 | cb_cv = get_cb (callback); |
|
|
831 | |
|
|
832 | req = calloc (sizeof (*req), 1); |
|
|
833 | if (!req) |
|
|
834 | croak ("out of memory during eio_req allocation"); |
|
|
835 | |
|
|
836 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
837 | req->pri = req_pri; |
|
|
838 | |
|
|
839 | return req; |
|
|
840 | } |
|
|
841 | |
771 | #define dREQ \ |
842 | #define dREQ \ |
772 | SV *cb_cv; \ |
843 | aio_req req = dreq (callback); \ |
773 | aio_req req; \ |
|
|
774 | int req_pri = next_pri; \ |
|
|
775 | next_pri = EIO_PRI_DEFAULT; \ |
|
|
776 | \ |
|
|
777 | cb_cv = get_cb (callback); \ |
|
|
778 | \ |
|
|
779 | Newz (0, req, 1, eio_req); \ |
|
|
780 | if (!req) \ |
|
|
781 | croak ("out of memory during eio_req allocation"); \ |
|
|
782 | \ |
|
|
783 | req->callback = SvREFCNT_inc (cb_cv); \ |
|
|
784 | req->pri = req_pri |
|
|
785 | |
844 | |
786 | #define REQ_SEND \ |
845 | #define REQ_SEND \ |
787 | PUTBACK; \ |
846 | PUTBACK; \ |
788 | req_submit (req); \ |
847 | req_submit (req); \ |
789 | SPAGAIN; \ |
848 | SPAGAIN; \ |
790 | \ |
849 | \ |
791 | if (GIMME_V != G_VOID) \ |
850 | if (GIMME_V != G_VOID) \ |
792 | XPUSHs (req_sv (req, aio_req_stash)); |
851 | XPUSHs (req_sv (req, aio_req_stash)); |
|
|
852 | |
|
|
853 | ecb_inline void |
|
|
854 | req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr) |
|
|
855 | { |
|
|
856 | if (expect_false (SvROK (path))) |
|
|
857 | { |
|
|
858 | SV *rv = SvRV (path); |
|
|
859 | SV *wdob; |
|
|
860 | |
|
|
861 | if (SvTYPE (rv) == SVt_PVAV && AvFILLp (rv) == 1) |
|
|
862 | { |
|
|
863 | path = AvARRAY (rv)[1]; |
|
|
864 | wdob = AvARRAY (rv)[0]; |
|
|
865 | |
|
|
866 | if (SvOK (wdob)) |
|
|
867 | { |
|
|
868 | *wd = SvAIO_WD (wdob); |
|
|
869 | *wdsv = SvREFCNT_inc_NN (SvRV (wdob)); |
|
|
870 | } |
|
|
871 | else |
|
|
872 | *wd = EIO_INVALID_WD; |
|
|
873 | } |
|
|
874 | else if (SvTYPE (rv) == SVt_PVMG && SvSTASH (rv) == aio_wd_stash) |
|
|
875 | { |
|
|
876 | *wd = (aio_wd)(long)SvIVX (rv); |
|
|
877 | *wdsv = SvREFCNT_inc_NN (rv); |
|
|
878 | *ptr = "."; |
|
|
879 | return; /* path set to "." */ |
|
|
880 | } |
|
|
881 | else |
|
|
882 | croak ("IO::AIO: pathname arguments must be specified as a string, an IO::AIO::WD object or a [IO::AIO::WD, path] pair"); |
|
|
883 | } |
|
|
884 | |
|
|
885 | *pathsv = newSVsv (path); |
|
|
886 | *ptr = SvPVbyte_nolen (*pathsv); |
|
|
887 | } |
|
|
888 | |
|
|
889 | static void ecb_noinline |
|
|
890 | req_set_path1 (aio_req req, SV *path) |
|
|
891 | { |
|
|
892 | req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1); |
|
|
893 | } |
|
|
894 | |
|
|
895 | static void ecb_noinline |
|
|
896 | req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path) |
|
|
897 | { |
|
|
898 | SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path; |
|
|
899 | |
|
|
900 | switch (SvTYPE (rv)) |
|
|
901 | { |
|
|
902 | case SVt_PVIO: |
|
|
903 | case SVt_PVLV: |
|
|
904 | case SVt_PVGV: |
|
|
905 | req->type = type_fh; |
|
|
906 | req->sv1 = newSVsv (fh_or_path); |
|
|
907 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
908 | break; |
|
|
909 | |
|
|
910 | default: |
|
|
911 | req->type = type_path; |
|
|
912 | req_set_path1 (req, fh_or_path); |
|
|
913 | break; |
|
|
914 | } |
|
|
915 | } |
|
|
916 | |
|
|
917 | XS(boot_IO__AIO) ecb_cold; |
793 | |
918 | |
794 | MODULE = IO::AIO PACKAGE = IO::AIO |
919 | MODULE = IO::AIO PACKAGE = IO::AIO |
795 | |
920 | |
796 | PROTOTYPES: ENABLE |
921 | PROTOTYPES: ENABLE |
797 | |
922 | |
… | |
… | |
881 | const_iv (MAP_LOCKED) |
1006 | const_iv (MAP_LOCKED) |
882 | const_iv (MAP_NORESERVE) |
1007 | const_iv (MAP_NORESERVE) |
883 | const_iv (MAP_POPULATE) |
1008 | const_iv (MAP_POPULATE) |
884 | const_iv (MAP_NONBLOCK) |
1009 | const_iv (MAP_NONBLOCK) |
885 | |
1010 | |
|
|
1011 | const_eio (SEEK_SET) |
|
|
1012 | const_eio (SEEK_CUR) |
|
|
1013 | const_eio (SEEK_END) |
|
|
1014 | |
886 | const_eio (MCL_FUTURE) |
1015 | const_eio (MCL_FUTURE) |
887 | const_eio (MCL_CURRENT) |
1016 | const_eio (MCL_CURRENT) |
888 | |
1017 | |
889 | const_eio (MS_ASYNC) |
1018 | const_eio (MS_ASYNC) |
890 | const_eio (MS_INVALIDATE) |
1019 | const_eio (MS_INVALIDATE) |
… | |
… | |
893 | const_eio (MT_MODIFY) |
1022 | const_eio (MT_MODIFY) |
894 | |
1023 | |
895 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
1024 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
896 | const_eio (SYNC_FILE_RANGE_WRITE) |
1025 | const_eio (SYNC_FILE_RANGE_WRITE) |
897 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
1026 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
|
|
1027 | |
|
|
1028 | const_eio (FALLOC_FL_KEEP_SIZE) |
898 | |
1029 | |
899 | const_eio (READDIR_DENTS) |
1030 | const_eio (READDIR_DENTS) |
900 | const_eio (READDIR_DIRS_FIRST) |
1031 | const_eio (READDIR_DIRS_FIRST) |
901 | const_eio (READDIR_STAT_ORDER) |
1032 | const_eio (READDIR_STAT_ORDER) |
902 | const_eio (READDIR_FOUND_UNKNOWN) |
1033 | const_eio (READDIR_FOUND_UNKNOWN) |
… | |
… | |
913 | }; |
1044 | }; |
914 | |
1045 | |
915 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
1046 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
916 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
1047 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
917 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
1048 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
|
|
1049 | aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1); |
918 | |
1050 | |
919 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1051 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
920 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
1052 | newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
921 | |
1053 | |
922 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
1054 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
923 | |
1055 | |
924 | create_respipe (); |
1056 | reinit (); |
925 | |
|
|
926 | if (eio_init (want_poll, done_poll) < 0) |
|
|
927 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
928 | |
|
|
929 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
930 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
931 | } |
1057 | } |
|
|
1058 | |
|
|
1059 | void |
|
|
1060 | reinit () |
|
|
1061 | PROTOTYPE: |
932 | |
1062 | |
933 | void |
1063 | void |
934 | max_poll_reqs (unsigned int nreqs) |
1064 | max_poll_reqs (unsigned int nreqs) |
935 | PROTOTYPE: $ |
1065 | PROTOTYPE: $ |
936 | CODE: |
1066 | CODE: |
… | |
… | |
971 | PROTOTYPE: $ |
1101 | PROTOTYPE: $ |
972 | CODE: |
1102 | CODE: |
973 | max_outstanding = maxreqs; |
1103 | max_outstanding = maxreqs; |
974 | |
1104 | |
975 | void |
1105 | void |
|
|
1106 | aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef) |
|
|
1107 | PPCODE: |
|
|
1108 | { |
|
|
1109 | dREQ; |
|
|
1110 | |
|
|
1111 | req->type = EIO_WD_OPEN; |
|
|
1112 | req_set_path1 (req, pathname); |
|
|
1113 | |
|
|
1114 | REQ_SEND; |
|
|
1115 | } |
|
|
1116 | |
|
|
1117 | void |
976 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
1118 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
977 | PPCODE: |
1119 | PPCODE: |
978 | { |
1120 | { |
979 | dREQ; |
1121 | dREQ; |
980 | |
1122 | |
981 | req->type = EIO_OPEN; |
1123 | req->type = EIO_OPEN; |
982 | req->sv1 = newSVsv (pathname); |
1124 | req_set_path1 (req, pathname); |
983 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
984 | req->int1 = flags; |
1125 | req->int1 = flags; |
985 | req->int2 = mode; |
1126 | req->int2 = mode; |
986 | |
1127 | |
987 | REQ_SEND; |
1128 | REQ_SEND; |
988 | } |
1129 | } |
… | |
… | |
990 | void |
1131 | void |
991 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
1132 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
992 | ALIAS: |
1133 | ALIAS: |
993 | aio_fsync = EIO_FSYNC |
1134 | aio_fsync = EIO_FSYNC |
994 | aio_fdatasync = EIO_FDATASYNC |
1135 | aio_fdatasync = EIO_FDATASYNC |
|
|
1136 | aio_syncfs = EIO_SYNCFS |
995 | PPCODE: |
1137 | PPCODE: |
996 | { |
1138 | { |
997 | int fd = s_fileno_croak (fh, 0); |
1139 | int fd = s_fileno_croak (fh, 0); |
998 | dREQ; |
1140 | dREQ; |
999 | |
1141 | |
1000 | req->type = ix; |
1142 | req->type = ix; |
1001 | req->sv1 = newSVsv (fh); |
1143 | req->sv1 = newSVsv (fh); |
1002 | req->int1 = fd; |
1144 | req->int1 = fd; |
1003 | |
1145 | |
1004 | REQ_SEND (req); |
1146 | REQ_SEND; |
1005 | } |
1147 | } |
1006 | |
1148 | |
1007 | void |
1149 | void |
1008 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1150 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1009 | PPCODE: |
1151 | PPCODE: |
… | |
… | |
1016 | req->int1 = fd; |
1158 | req->int1 = fd; |
1017 | req->offs = offset; |
1159 | req->offs = offset; |
1018 | req->size = nbytes; |
1160 | req->size = nbytes; |
1019 | req->int2 = flags; |
1161 | req->int2 = flags; |
1020 | |
1162 | |
1021 | REQ_SEND (req); |
1163 | REQ_SEND; |
|
|
1164 | } |
|
|
1165 | |
|
|
1166 | void |
|
|
1167 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
|
|
1168 | PPCODE: |
|
|
1169 | { |
|
|
1170 | int fd = s_fileno_croak (fh, 0); |
|
|
1171 | dREQ; |
|
|
1172 | |
|
|
1173 | req->type = EIO_FALLOCATE; |
|
|
1174 | req->sv1 = newSVsv (fh); |
|
|
1175 | req->int1 = fd; |
|
|
1176 | req->int2 = mode; |
|
|
1177 | req->offs = offset; |
|
|
1178 | req->size = len; |
|
|
1179 | |
|
|
1180 | REQ_SEND; |
1022 | } |
1181 | } |
1023 | |
1182 | |
1024 | void |
1183 | void |
1025 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1184 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1026 | PPCODE: |
1185 | PPCODE: |
1027 | { |
1186 | { |
1028 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
1187 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
1029 | int fd = s_fileno_croak (fh, 0); |
1188 | int fd = s_fileno_croak (fh, 0); |
1030 | dREQ; |
1189 | dREQ; |
1031 | |
1190 | |
1032 | if (close_pipe < 0) |
1191 | if (expect_false (close_fd < 0)) |
1033 | { |
1192 | { |
1034 | int pipefd [2]; |
1193 | int pipefd [2]; |
1035 | |
1194 | |
|
|
1195 | if ( |
|
|
1196 | #ifdef _WIN32 |
|
|
1197 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1198 | #else |
1036 | if (pipe (pipefd) < 0 |
1199 | pipe (pipefd) < 0 |
1037 | || close (pipefd [1]) < 0 |
|
|
1038 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1200 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 |
|
|
1201 | #endif |
|
|
1202 | || close (pipefd [1]) < 0 |
|
|
1203 | ) |
1039 | abort (); /*D*/ |
1204 | abort (); /*D*/ |
1040 | |
1205 | |
1041 | close_pipe = pipefd [0]; |
1206 | close_fd = pipefd [0]; |
1042 | } |
1207 | } |
1043 | |
1208 | |
1044 | req->type = EIO_DUP2; |
1209 | req->type = EIO_DUP2; |
1045 | req->int1 = close_pipe; |
1210 | req->int1 = close_fd; |
1046 | req->sv2 = newSVsv (fh); |
1211 | req->sv2 = newSVsv (fh); |
1047 | req->int2 = fd; |
1212 | req->int2 = fd; |
1048 | |
1213 | |
1049 | REQ_SEND (req); |
1214 | REQ_SEND; |
|
|
1215 | } |
|
|
1216 | |
|
|
1217 | void |
|
|
1218 | aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) |
|
|
1219 | PPCODE: |
|
|
1220 | { |
|
|
1221 | STRLEN svlen; |
|
|
1222 | int fd = s_fileno_croak (fh, 0); |
|
|
1223 | dREQ; |
|
|
1224 | |
|
|
1225 | req->type = EIO_SEEK; |
|
|
1226 | req->sv1 = newSVsv (fh); |
|
|
1227 | req->int1 = fd; |
|
|
1228 | req->offs = SvVAL64 (offset); |
|
|
1229 | req->int2 = whence; |
|
|
1230 | |
|
|
1231 | REQ_SEND; |
1050 | } |
1232 | } |
1051 | |
1233 | |
1052 | void |
1234 | void |
1053 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
1235 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
1054 | ALIAS: |
1236 | ALIAS: |
… | |
… | |
1101 | REQ_SEND; |
1283 | REQ_SEND; |
1102 | } |
1284 | } |
1103 | } |
1285 | } |
1104 | |
1286 | |
1105 | void |
1287 | void |
1106 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1288 | aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1107 | ALIAS: |
1289 | ALIAS: |
1108 | aio_readlink = EIO_READLINK |
1290 | aio_readlink = EIO_READLINK |
1109 | aio_realpath = EIO_REALPATH |
1291 | aio_realpath = EIO_REALPATH |
1110 | PPCODE: |
1292 | PPCODE: |
1111 | { |
1293 | { |
1112 | SV *data; |
|
|
1113 | dREQ; |
1294 | dREQ; |
1114 | |
1295 | |
1115 | req->type = ix; |
1296 | req->type = ix; |
1116 | req->sv1 = newSVsv (path); |
1297 | req_set_path1 (req, pathname); |
1117 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1118 | |
1298 | |
1119 | REQ_SEND; |
1299 | REQ_SEND; |
1120 | } |
1300 | } |
1121 | |
1301 | |
1122 | void |
1302 | void |
… | |
… | |
1162 | aio_statvfs = EIO_STATVFS |
1342 | aio_statvfs = EIO_STATVFS |
1163 | PPCODE: |
1343 | PPCODE: |
1164 | { |
1344 | { |
1165 | dREQ; |
1345 | dREQ; |
1166 | |
1346 | |
1167 | req->sv1 = newSVsv (fh_or_path); |
1347 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
1168 | |
|
|
1169 | if (SvPOK (req->sv1)) |
|
|
1170 | { |
|
|
1171 | req->type = ix; |
|
|
1172 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1173 | } |
|
|
1174 | else |
|
|
1175 | { |
|
|
1176 | req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; |
|
|
1177 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1178 | } |
|
|
1179 | |
1348 | |
1180 | REQ_SEND; |
1349 | REQ_SEND; |
1181 | } |
1350 | } |
1182 | |
1351 | |
1183 | UV |
1352 | UV |
… | |
… | |
1202 | { |
1371 | { |
1203 | dREQ; |
1372 | dREQ; |
1204 | |
1373 | |
1205 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1374 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1206 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1375 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1207 | req->sv1 = newSVsv (fh_or_path); |
1376 | req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path); |
1208 | |
|
|
1209 | if (SvPOK (req->sv1)) |
|
|
1210 | { |
|
|
1211 | req->type = EIO_UTIME; |
|
|
1212 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1213 | } |
|
|
1214 | else |
|
|
1215 | { |
|
|
1216 | req->type = EIO_FUTIME; |
|
|
1217 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1218 | } |
|
|
1219 | |
1377 | |
1220 | REQ_SEND; |
1378 | REQ_SEND; |
1221 | } |
1379 | } |
1222 | |
1380 | |
1223 | void |
1381 | void |
1224 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
1382 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
1225 | PPCODE: |
1383 | PPCODE: |
1226 | { |
1384 | { |
1227 | dREQ; |
1385 | dREQ; |
1228 | |
1386 | |
1229 | req->sv1 = newSVsv (fh_or_path); |
|
|
1230 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1387 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1231 | |
1388 | req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path); |
1232 | if (SvPOK (req->sv1)) |
|
|
1233 | { |
|
|
1234 | req->type = EIO_TRUNCATE; |
|
|
1235 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1236 | } |
|
|
1237 | else |
|
|
1238 | { |
|
|
1239 | req->type = EIO_FTRUNCATE; |
|
|
1240 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1241 | } |
|
|
1242 | |
1389 | |
1243 | REQ_SEND; |
1390 | REQ_SEND; |
1244 | } |
1391 | } |
1245 | |
1392 | |
1246 | void |
1393 | void |
1247 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1394 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1248 | ALIAS: |
|
|
1249 | aio_chmod = EIO_CHMOD |
|
|
1250 | aio_mkdir = EIO_MKDIR |
|
|
1251 | PPCODE: |
1395 | PPCODE: |
1252 | { |
1396 | { |
1253 | dREQ; |
1397 | dREQ; |
1254 | |
1398 | |
1255 | req->int2 = mode; |
1399 | req->int2 = mode; |
1256 | req->sv1 = newSVsv (fh_or_path); |
1400 | req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path); |
1257 | |
|
|
1258 | if (SvPOK (req->sv1)) |
|
|
1259 | { |
|
|
1260 | req->type = ix; |
|
|
1261 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1262 | } |
|
|
1263 | else |
|
|
1264 | { |
|
|
1265 | req->type = EIO_FCHMOD; |
|
|
1266 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1267 | } |
|
|
1268 | |
1401 | |
1269 | REQ_SEND; |
1402 | REQ_SEND; |
1270 | } |
1403 | } |
1271 | |
1404 | |
1272 | void |
1405 | void |
… | |
… | |
1275 | { |
1408 | { |
1276 | dREQ; |
1409 | dREQ; |
1277 | |
1410 | |
1278 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1411 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1279 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1412 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1280 | req->sv1 = newSVsv (fh_or_path); |
1413 | req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path); |
1281 | |
|
|
1282 | if (SvPOK (req->sv1)) |
|
|
1283 | { |
|
|
1284 | req->type = EIO_CHOWN; |
|
|
1285 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1286 | } |
|
|
1287 | else |
|
|
1288 | { |
|
|
1289 | req->type = EIO_FCHOWN; |
|
|
1290 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1291 | } |
|
|
1292 | |
1414 | |
1293 | REQ_SEND; |
1415 | REQ_SEND; |
1294 | } |
1416 | } |
1295 | |
1417 | |
1296 | void |
1418 | void |
… | |
… | |
1298 | PPCODE: |
1420 | PPCODE: |
1299 | { |
1421 | { |
1300 | dREQ; |
1422 | dREQ; |
1301 | |
1423 | |
1302 | req->type = EIO_READDIR; |
1424 | req->type = EIO_READDIR; |
1303 | req->sv1 = newSVsv (pathname); |
|
|
1304 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1305 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1425 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1306 | |
1426 | |
1307 | if (flags & EIO_READDIR_DENTS) |
1427 | if (flags & EIO_READDIR_DENTS) |
1308 | req->int1 |= EIO_READDIR_CUSTOM2; |
1428 | req->int1 |= EIO_READDIR_CUSTOM2; |
1309 | |
1429 | |
|
|
1430 | req_set_path1 (req, pathname); |
|
|
1431 | |
1310 | REQ_SEND; |
1432 | REQ_SEND; |
|
|
1433 | } |
|
|
1434 | |
|
|
1435 | void |
|
|
1436 | aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef) |
|
|
1437 | PPCODE: |
|
|
1438 | { |
|
|
1439 | dREQ; |
|
|
1440 | |
|
|
1441 | req->type = EIO_MKDIR; |
|
|
1442 | req->int2 = mode; |
|
|
1443 | req_set_path1 (req, pathname); |
|
|
1444 | |
|
|
1445 | REQ_SEND; |
1311 | } |
1446 | } |
1312 | |
1447 | |
1313 | void |
1448 | void |
1314 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1449 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1315 | ALIAS: |
1450 | ALIAS: |
… | |
… | |
1319 | PPCODE: |
1454 | PPCODE: |
1320 | { |
1455 | { |
1321 | dREQ; |
1456 | dREQ; |
1322 | |
1457 | |
1323 | req->type = ix; |
1458 | req->type = ix; |
1324 | req->sv1 = newSVsv (pathname); |
1459 | req_set_path1 (req, pathname); |
1325 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1326 | |
1460 | |
1327 | REQ_SEND; |
1461 | REQ_SEND; |
1328 | } |
1462 | } |
1329 | |
1463 | |
1330 | void |
1464 | void |
… | |
… | |
1333 | aio_link = EIO_LINK |
1467 | aio_link = EIO_LINK |
1334 | aio_symlink = EIO_SYMLINK |
1468 | aio_symlink = EIO_SYMLINK |
1335 | aio_rename = EIO_RENAME |
1469 | aio_rename = EIO_RENAME |
1336 | PPCODE: |
1470 | PPCODE: |
1337 | { |
1471 | { |
|
|
1472 | eio_wd wd2 = 0; |
1338 | dREQ; |
1473 | dREQ; |
1339 | |
1474 | |
1340 | req->type = ix; |
1475 | req->type = ix; |
1341 | req->sv1 = newSVsv (oldpath); |
1476 | req_set_path1 (req, oldpath); |
1342 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1477 | req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2); |
1343 | req->sv2 = newSVsv (newpath); |
1478 | req->int3 = (long)wd2; |
1344 | req->ptr2 = SvPVbyte_nolen (req->sv2); |
|
|
1345 | |
1479 | |
1346 | REQ_SEND; |
1480 | REQ_SEND; |
1347 | } |
1481 | } |
1348 | |
1482 | |
1349 | void |
1483 | void |
… | |
… | |
1351 | PPCODE: |
1485 | PPCODE: |
1352 | { |
1486 | { |
1353 | dREQ; |
1487 | dREQ; |
1354 | |
1488 | |
1355 | req->type = EIO_MKNOD; |
1489 | req->type = EIO_MKNOD; |
1356 | req->sv1 = newSVsv (pathname); |
|
|
1357 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1358 | req->int2 = (mode_t)mode; |
1490 | req->int2 = (mode_t)mode; |
1359 | req->offs = dev; |
1491 | req->offs = dev; |
|
|
1492 | req_set_path1 (req, pathname); |
1360 | |
1493 | |
1361 | REQ_SEND; |
1494 | REQ_SEND; |
1362 | } |
1495 | } |
1363 | |
1496 | |
1364 | void |
1497 | void |
… | |
… | |
1564 | CODE: |
1697 | CODE: |
1565 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1698 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1566 | OUTPUT: |
1699 | OUTPUT: |
1567 | RETVAL |
1700 | RETVAL |
1568 | |
1701 | |
1569 | ssize_t |
1702 | IV |
1570 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1703 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1571 | CODE: |
1704 | CODE: |
1572 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1705 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1573 | OUTPUT: |
1706 | OUTPUT: |
1574 | RETVAL |
1707 | RETVAL |
… | |
… | |
1686 | SvREFCNT_dec (on_next_submit); |
1819 | SvREFCNT_dec (on_next_submit); |
1687 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1820 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1688 | |
1821 | |
1689 | PROTOTYPES: DISABLE |
1822 | PROTOTYPES: DISABLE |
1690 | |
1823 | |
|
|
1824 | MODULE = IO::AIO PACKAGE = IO::AIO::WD |
|
|
1825 | |
|
|
1826 | BOOT: |
|
|
1827 | { |
|
|
1828 | newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD )); |
|
|
1829 | newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD)); |
|
|
1830 | } |
|
|
1831 | |
|
|
1832 | void |
|
|
1833 | DESTROY (SV *self) |
|
|
1834 | CODE: |
|
|
1835 | { |
|
|
1836 | aio_wd wd = SvAIO_WD (self); |
|
|
1837 | #if HAVE_AT |
|
|
1838 | { |
|
|
1839 | SV *callback = &PL_sv_undef; |
|
|
1840 | dREQ; /* clobbers next_pri :/ */ |
|
|
1841 | next_pri = req->pri; /* restore next_pri */ |
|
|
1842 | req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */ |
|
|
1843 | req->type = EIO_WD_CLOSE; |
|
|
1844 | req->wd = wd; |
|
|
1845 | REQ_SEND; |
|
|
1846 | } |
|
|
1847 | #else |
|
|
1848 | eio_wd_close_sync (wd); |
|
|
1849 | #endif |
|
|
1850 | } |
|
|
1851 | |
1691 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1852 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1692 | |
1853 | |
1693 | void |
1854 | void |
1694 | cancel (aio_req_ornot req) |
1855 | cancel (aio_req_ornot req) |
1695 | CODE: |
1856 | CODE: |