… | |
… | |
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 | |
|
|
717 | static void ecb_cold |
672 | static void create_respipe (void) |
718 | create_respipe (void) |
673 | { |
719 | { |
674 | if (s_epipe_renew (&respipe)) |
720 | if (s_epipe_renew (&respipe)) |
675 | croak ("IO::AIO: unable to initialize result pipe"); |
721 | croak ("IO::AIO: unable to initialize result pipe"); |
676 | } |
722 | } |
677 | |
723 | |
678 | static void poll_wait (void) |
724 | static void |
|
|
725 | poll_wait (void) |
679 | { |
726 | { |
680 | while (eio_nreqs ()) |
727 | while (eio_nreqs ()) |
681 | { |
728 | { |
682 | int size; |
729 | int size; |
683 | |
730 | |
… | |
… | |
692 | |
739 | |
693 | s_epipe_wait (&respipe); |
740 | s_epipe_wait (&respipe); |
694 | } |
741 | } |
695 | } |
742 | } |
696 | |
743 | |
697 | static int poll_cb (void) |
744 | static int |
|
|
745 | poll_cb (void) |
698 | { |
746 | { |
699 | for (;;) |
747 | for (;;) |
700 | { |
748 | { |
701 | int res = eio_poll (); |
749 | int res = eio_poll (); |
702 | |
750 | |
… | |
… | |
708 | |
756 | |
709 | poll_wait (); |
757 | poll_wait (); |
710 | } |
758 | } |
711 | } |
759 | } |
712 | |
760 | |
713 | static void atfork_child (void) |
761 | static void ecb_cold |
|
|
762 | reinit (void) |
714 | { |
763 | { |
715 | create_respipe (); |
764 | create_respipe (); |
|
|
765 | |
|
|
766 | if (eio_init (want_poll, done_poll) < 0) |
|
|
767 | croak ("IO::AIO: unable to initialise eio library"); |
716 | } |
768 | } |
717 | |
769 | |
718 | /*****************************************************************************/ |
770 | /*****************************************************************************/ |
719 | |
771 | |
720 | #if !_POSIX_MAPPED_FILES |
772 | #if !_POSIX_MAPPED_FILES |
… | |
… | |
731 | # define MAP_FIXED 0 |
783 | # define MAP_FIXED 0 |
732 | #endif |
784 | #endif |
733 | |
785 | |
734 | #define MMAP_MAGIC PERL_MAGIC_ext |
786 | #define MMAP_MAGIC PERL_MAGIC_ext |
735 | |
787 | |
|
|
788 | static int ecb_cold |
736 | static int mmap_free (pTHX_ SV *sv, MAGIC *mg) |
789 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
737 | { |
790 | { |
738 | int old_errno = errno; |
791 | int old_errno = errno; |
739 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
792 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
740 | errno = old_errno; |
793 | errno = old_errno; |
741 | |
794 | |
… | |
… | |
757 | 0, 0, 0, 0, mmap_free |
810 | 0, 0, 0, 0, mmap_free |
758 | }; |
811 | }; |
759 | |
812 | |
760 | /*****************************************************************************/ |
813 | /*****************************************************************************/ |
761 | |
814 | |
|
|
815 | static SV * |
762 | static SV * get_cb (SV *cb_sv) |
816 | get_cb (SV *cb_sv) |
763 | { |
817 | { |
764 | SvGETMAGIC (cb_sv); |
818 | SvGETMAGIC (cb_sv); |
765 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
819 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
766 | } |
820 | } |
767 | |
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 | |
768 | #define dREQ \ |
842 | #define dREQ \ |
769 | SV *cb_cv; \ |
843 | aio_req req = dreq (callback); \ |
770 | aio_req req; \ |
|
|
771 | int req_pri = next_pri; \ |
|
|
772 | next_pri = EIO_PRI_DEFAULT; \ |
|
|
773 | \ |
|
|
774 | cb_cv = get_cb (callback); \ |
|
|
775 | \ |
|
|
776 | Newz (0, req, 1, eio_req); \ |
|
|
777 | if (!req) \ |
|
|
778 | croak ("out of memory during eio_req allocation"); \ |
|
|
779 | \ |
|
|
780 | req->callback = SvREFCNT_inc (cb_cv); \ |
|
|
781 | req->pri = req_pri |
|
|
782 | |
844 | |
783 | #define REQ_SEND \ |
845 | #define REQ_SEND \ |
784 | PUTBACK; \ |
846 | PUTBACK; \ |
785 | req_submit (req); \ |
847 | req_submit (req); \ |
786 | SPAGAIN; \ |
848 | SPAGAIN; \ |
787 | \ |
849 | \ |
788 | if (GIMME_V != G_VOID) \ |
850 | if (GIMME_V != G_VOID) \ |
789 | 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; |
790 | |
918 | |
791 | MODULE = IO::AIO PACKAGE = IO::AIO |
919 | MODULE = IO::AIO PACKAGE = IO::AIO |
792 | |
920 | |
793 | PROTOTYPES: ENABLE |
921 | PROTOTYPES: ENABLE |
794 | |
922 | |
… | |
… | |
878 | const_iv (MAP_LOCKED) |
1006 | const_iv (MAP_LOCKED) |
879 | const_iv (MAP_NORESERVE) |
1007 | const_iv (MAP_NORESERVE) |
880 | const_iv (MAP_POPULATE) |
1008 | const_iv (MAP_POPULATE) |
881 | const_iv (MAP_NONBLOCK) |
1009 | const_iv (MAP_NONBLOCK) |
882 | |
1010 | |
|
|
1011 | const_eio (SEEK_SET) |
|
|
1012 | const_eio (SEEK_CUR) |
|
|
1013 | const_eio (SEEK_END) |
|
|
1014 | |
883 | const_eio (MCL_FUTURE) |
1015 | const_eio (MCL_FUTURE) |
884 | const_eio (MCL_CURRENT) |
1016 | const_eio (MCL_CURRENT) |
885 | |
1017 | |
886 | const_eio (MS_ASYNC) |
1018 | const_eio (MS_ASYNC) |
887 | const_eio (MS_INVALIDATE) |
1019 | const_eio (MS_INVALIDATE) |
… | |
… | |
912 | }; |
1044 | }; |
913 | |
1045 | |
914 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
1046 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
915 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
1047 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
916 | 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); |
917 | |
1050 | |
918 | 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--) |
919 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
1052 | newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
920 | |
1053 | |
921 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
1054 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
922 | |
1055 | |
923 | create_respipe (); |
1056 | reinit (); |
924 | |
|
|
925 | if (eio_init (want_poll, done_poll) < 0) |
|
|
926 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
927 | |
|
|
928 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
929 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
930 | } |
1057 | } |
|
|
1058 | |
|
|
1059 | void |
|
|
1060 | reinit () |
|
|
1061 | PROTOTYPE: |
931 | |
1062 | |
932 | void |
1063 | void |
933 | max_poll_reqs (unsigned int nreqs) |
1064 | max_poll_reqs (unsigned int nreqs) |
934 | PROTOTYPE: $ |
1065 | PROTOTYPE: $ |
935 | CODE: |
1066 | CODE: |
… | |
… | |
970 | PROTOTYPE: $ |
1101 | PROTOTYPE: $ |
971 | CODE: |
1102 | CODE: |
972 | max_outstanding = maxreqs; |
1103 | max_outstanding = maxreqs; |
973 | |
1104 | |
974 | 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 |
975 | 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) |
976 | PPCODE: |
1119 | PPCODE: |
977 | { |
1120 | { |
978 | dREQ; |
1121 | dREQ; |
979 | |
1122 | |
980 | req->type = EIO_OPEN; |
1123 | req->type = EIO_OPEN; |
981 | req->sv1 = newSVsv (pathname); |
1124 | req_set_path1 (req, pathname); |
982 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
983 | req->int1 = flags; |
1125 | req->int1 = flags; |
984 | req->int2 = mode; |
1126 | req->int2 = mode; |
985 | |
1127 | |
986 | REQ_SEND; |
1128 | REQ_SEND; |
987 | } |
1129 | } |
… | |
… | |
989 | void |
1131 | void |
990 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
1132 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
991 | ALIAS: |
1133 | ALIAS: |
992 | aio_fsync = EIO_FSYNC |
1134 | aio_fsync = EIO_FSYNC |
993 | aio_fdatasync = EIO_FDATASYNC |
1135 | aio_fdatasync = EIO_FDATASYNC |
|
|
1136 | aio_syncfs = EIO_SYNCFS |
994 | PPCODE: |
1137 | PPCODE: |
995 | { |
1138 | { |
996 | int fd = s_fileno_croak (fh, 0); |
1139 | int fd = s_fileno_croak (fh, 0); |
997 | dREQ; |
1140 | dREQ; |
998 | |
1141 | |
999 | req->type = ix; |
1142 | req->type = ix; |
1000 | req->sv1 = newSVsv (fh); |
1143 | req->sv1 = newSVsv (fh); |
1001 | req->int1 = fd; |
1144 | req->int1 = fd; |
1002 | |
1145 | |
1003 | REQ_SEND (req); |
1146 | REQ_SEND; |
1004 | } |
1147 | } |
1005 | |
1148 | |
1006 | void |
1149 | void |
1007 | 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) |
1008 | PPCODE: |
1151 | PPCODE: |
… | |
… | |
1015 | req->int1 = fd; |
1158 | req->int1 = fd; |
1016 | req->offs = offset; |
1159 | req->offs = offset; |
1017 | req->size = nbytes; |
1160 | req->size = nbytes; |
1018 | req->int2 = flags; |
1161 | req->int2 = flags; |
1019 | |
1162 | |
1020 | REQ_SEND (req); |
1163 | REQ_SEND; |
1021 | } |
1164 | } |
1022 | |
1165 | |
1023 | void |
1166 | void |
1024 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
1167 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
1025 | PPCODE: |
1168 | PPCODE: |
… | |
… | |
1032 | req->int1 = fd; |
1175 | req->int1 = fd; |
1033 | req->int2 = mode; |
1176 | req->int2 = mode; |
1034 | req->offs = offset; |
1177 | req->offs = offset; |
1035 | req->size = len; |
1178 | req->size = len; |
1036 | |
1179 | |
1037 | REQ_SEND (req); |
1180 | REQ_SEND; |
1038 | } |
1181 | } |
1039 | |
1182 | |
1040 | void |
1183 | void |
1041 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1184 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1042 | PPCODE: |
1185 | PPCODE: |
1043 | { |
1186 | { |
1044 | 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 */ |
1045 | int fd = s_fileno_croak (fh, 0); |
1188 | int fd = s_fileno_croak (fh, 0); |
1046 | dREQ; |
1189 | dREQ; |
1047 | |
1190 | |
1048 | if (close_pipe < 0) |
1191 | if (expect_false (close_fd < 0)) |
1049 | { |
1192 | { |
1050 | int pipefd [2]; |
1193 | int pipefd [2]; |
1051 | |
1194 | |
|
|
1195 | if ( |
|
|
1196 | #ifdef _WIN32 |
|
|
1197 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1198 | #else |
1052 | if (pipe (pipefd) < 0 |
1199 | pipe (pipefd) < 0 |
1053 | || close (pipefd [1]) < 0 |
|
|
1054 | || 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 | ) |
1055 | abort (); /*D*/ |
1204 | abort (); /*D*/ |
1056 | |
1205 | |
1057 | close_pipe = pipefd [0]; |
1206 | close_fd = pipefd [0]; |
1058 | } |
1207 | } |
1059 | |
1208 | |
1060 | req->type = EIO_DUP2; |
1209 | req->type = EIO_DUP2; |
1061 | req->int1 = close_pipe; |
1210 | req->int1 = close_fd; |
1062 | req->sv2 = newSVsv (fh); |
1211 | req->sv2 = newSVsv (fh); |
1063 | req->int2 = fd; |
1212 | req->int2 = fd; |
1064 | |
1213 | |
1065 | 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; |
1066 | } |
1232 | } |
1067 | |
1233 | |
1068 | void |
1234 | void |
1069 | 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) |
1070 | ALIAS: |
1236 | ALIAS: |
… | |
… | |
1117 | REQ_SEND; |
1283 | REQ_SEND; |
1118 | } |
1284 | } |
1119 | } |
1285 | } |
1120 | |
1286 | |
1121 | void |
1287 | void |
1122 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1288 | aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1123 | ALIAS: |
1289 | ALIAS: |
1124 | aio_readlink = EIO_READLINK |
1290 | aio_readlink = EIO_READLINK |
1125 | aio_realpath = EIO_REALPATH |
1291 | aio_realpath = EIO_REALPATH |
1126 | PPCODE: |
1292 | PPCODE: |
1127 | { |
1293 | { |
1128 | SV *data; |
|
|
1129 | dREQ; |
1294 | dREQ; |
1130 | |
1295 | |
1131 | req->type = ix; |
1296 | req->type = ix; |
1132 | req->sv1 = newSVsv (path); |
1297 | req_set_path1 (req, pathname); |
1133 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1134 | |
1298 | |
1135 | REQ_SEND; |
1299 | REQ_SEND; |
1136 | } |
1300 | } |
1137 | |
1301 | |
1138 | void |
1302 | void |
… | |
… | |
1178 | aio_statvfs = EIO_STATVFS |
1342 | aio_statvfs = EIO_STATVFS |
1179 | PPCODE: |
1343 | PPCODE: |
1180 | { |
1344 | { |
1181 | dREQ; |
1345 | dREQ; |
1182 | |
1346 | |
1183 | req->sv1 = newSVsv (fh_or_path); |
1347 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
1184 | |
|
|
1185 | if (SvPOK (req->sv1)) |
|
|
1186 | { |
|
|
1187 | req->type = ix; |
|
|
1188 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1189 | } |
|
|
1190 | else |
|
|
1191 | { |
|
|
1192 | req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; |
|
|
1193 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1194 | } |
|
|
1195 | |
1348 | |
1196 | REQ_SEND; |
1349 | REQ_SEND; |
1197 | } |
1350 | } |
1198 | |
1351 | |
1199 | UV |
1352 | UV |
… | |
… | |
1218 | { |
1371 | { |
1219 | dREQ; |
1372 | dREQ; |
1220 | |
1373 | |
1221 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1374 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1222 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1375 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1223 | req->sv1 = newSVsv (fh_or_path); |
1376 | req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path); |
1224 | |
|
|
1225 | if (SvPOK (req->sv1)) |
|
|
1226 | { |
|
|
1227 | req->type = EIO_UTIME; |
|
|
1228 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1229 | } |
|
|
1230 | else |
|
|
1231 | { |
|
|
1232 | req->type = EIO_FUTIME; |
|
|
1233 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1234 | } |
|
|
1235 | |
1377 | |
1236 | REQ_SEND; |
1378 | REQ_SEND; |
1237 | } |
1379 | } |
1238 | |
1380 | |
1239 | void |
1381 | void |
1240 | 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) |
1241 | PPCODE: |
1383 | PPCODE: |
1242 | { |
1384 | { |
1243 | dREQ; |
1385 | dREQ; |
1244 | |
1386 | |
1245 | req->sv1 = newSVsv (fh_or_path); |
|
|
1246 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1387 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1247 | |
1388 | req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path); |
1248 | if (SvPOK (req->sv1)) |
|
|
1249 | { |
|
|
1250 | req->type = EIO_TRUNCATE; |
|
|
1251 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1252 | } |
|
|
1253 | else |
|
|
1254 | { |
|
|
1255 | req->type = EIO_FTRUNCATE; |
|
|
1256 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1257 | } |
|
|
1258 | |
1389 | |
1259 | REQ_SEND; |
1390 | REQ_SEND; |
1260 | } |
1391 | } |
1261 | |
1392 | |
1262 | void |
1393 | void |
1263 | 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) |
1264 | ALIAS: |
|
|
1265 | aio_chmod = EIO_CHMOD |
|
|
1266 | aio_mkdir = EIO_MKDIR |
|
|
1267 | PPCODE: |
1395 | PPCODE: |
1268 | { |
1396 | { |
1269 | dREQ; |
1397 | dREQ; |
1270 | |
1398 | |
1271 | req->int2 = mode; |
1399 | req->int2 = mode; |
1272 | req->sv1 = newSVsv (fh_or_path); |
1400 | req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path); |
1273 | |
|
|
1274 | if (SvPOK (req->sv1)) |
|
|
1275 | { |
|
|
1276 | req->type = ix; |
|
|
1277 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1278 | } |
|
|
1279 | else |
|
|
1280 | { |
|
|
1281 | req->type = EIO_FCHMOD; |
|
|
1282 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1283 | } |
|
|
1284 | |
1401 | |
1285 | REQ_SEND; |
1402 | REQ_SEND; |
1286 | } |
1403 | } |
1287 | |
1404 | |
1288 | void |
1405 | void |
… | |
… | |
1291 | { |
1408 | { |
1292 | dREQ; |
1409 | dREQ; |
1293 | |
1410 | |
1294 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1411 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1295 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1412 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1296 | req->sv1 = newSVsv (fh_or_path); |
1413 | req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path); |
1297 | |
|
|
1298 | if (SvPOK (req->sv1)) |
|
|
1299 | { |
|
|
1300 | req->type = EIO_CHOWN; |
|
|
1301 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1302 | } |
|
|
1303 | else |
|
|
1304 | { |
|
|
1305 | req->type = EIO_FCHOWN; |
|
|
1306 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1307 | } |
|
|
1308 | |
1414 | |
1309 | REQ_SEND; |
1415 | REQ_SEND; |
1310 | } |
1416 | } |
1311 | |
1417 | |
1312 | void |
1418 | void |
… | |
… | |
1314 | PPCODE: |
1420 | PPCODE: |
1315 | { |
1421 | { |
1316 | dREQ; |
1422 | dREQ; |
1317 | |
1423 | |
1318 | req->type = EIO_READDIR; |
1424 | req->type = EIO_READDIR; |
1319 | req->sv1 = newSVsv (pathname); |
|
|
1320 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1321 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1425 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1322 | |
1426 | |
1323 | if (flags & EIO_READDIR_DENTS) |
1427 | if (flags & EIO_READDIR_DENTS) |
1324 | req->int1 |= EIO_READDIR_CUSTOM2; |
1428 | req->int1 |= EIO_READDIR_CUSTOM2; |
1325 | |
1429 | |
|
|
1430 | req_set_path1 (req, pathname); |
|
|
1431 | |
1326 | 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; |
1327 | } |
1446 | } |
1328 | |
1447 | |
1329 | void |
1448 | void |
1330 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1449 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1331 | ALIAS: |
1450 | ALIAS: |
… | |
… | |
1335 | PPCODE: |
1454 | PPCODE: |
1336 | { |
1455 | { |
1337 | dREQ; |
1456 | dREQ; |
1338 | |
1457 | |
1339 | req->type = ix; |
1458 | req->type = ix; |
1340 | req->sv1 = newSVsv (pathname); |
1459 | req_set_path1 (req, pathname); |
1341 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1342 | |
1460 | |
1343 | REQ_SEND; |
1461 | REQ_SEND; |
1344 | } |
1462 | } |
1345 | |
1463 | |
1346 | void |
1464 | void |
… | |
… | |
1349 | aio_link = EIO_LINK |
1467 | aio_link = EIO_LINK |
1350 | aio_symlink = EIO_SYMLINK |
1468 | aio_symlink = EIO_SYMLINK |
1351 | aio_rename = EIO_RENAME |
1469 | aio_rename = EIO_RENAME |
1352 | PPCODE: |
1470 | PPCODE: |
1353 | { |
1471 | { |
|
|
1472 | eio_wd wd2 = 0; |
1354 | dREQ; |
1473 | dREQ; |
1355 | |
1474 | |
1356 | req->type = ix; |
1475 | req->type = ix; |
1357 | req->sv1 = newSVsv (oldpath); |
1476 | req_set_path1 (req, oldpath); |
1358 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1477 | req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2); |
1359 | req->sv2 = newSVsv (newpath); |
1478 | req->int3 = (long)wd2; |
1360 | req->ptr2 = SvPVbyte_nolen (req->sv2); |
|
|
1361 | |
1479 | |
1362 | REQ_SEND; |
1480 | REQ_SEND; |
1363 | } |
1481 | } |
1364 | |
1482 | |
1365 | void |
1483 | void |
… | |
… | |
1367 | PPCODE: |
1485 | PPCODE: |
1368 | { |
1486 | { |
1369 | dREQ; |
1487 | dREQ; |
1370 | |
1488 | |
1371 | req->type = EIO_MKNOD; |
1489 | req->type = EIO_MKNOD; |
1372 | req->sv1 = newSVsv (pathname); |
|
|
1373 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1374 | req->int2 = (mode_t)mode; |
1490 | req->int2 = (mode_t)mode; |
1375 | req->offs = dev; |
1491 | req->offs = dev; |
|
|
1492 | req_set_path1 (req, pathname); |
1376 | |
1493 | |
1377 | REQ_SEND; |
1494 | REQ_SEND; |
1378 | } |
1495 | } |
1379 | |
1496 | |
1380 | void |
1497 | void |
… | |
… | |
1580 | CODE: |
1697 | CODE: |
1581 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1698 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1582 | OUTPUT: |
1699 | OUTPUT: |
1583 | RETVAL |
1700 | RETVAL |
1584 | |
1701 | |
1585 | ssize_t |
1702 | IV |
1586 | 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) |
1587 | CODE: |
1704 | CODE: |
1588 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1705 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1589 | OUTPUT: |
1706 | OUTPUT: |
1590 | RETVAL |
1707 | RETVAL |
… | |
… | |
1702 | SvREFCNT_dec (on_next_submit); |
1819 | SvREFCNT_dec (on_next_submit); |
1703 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1820 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1704 | |
1821 | |
1705 | PROTOTYPES: DISABLE |
1822 | PROTOTYPES: DISABLE |
1706 | |
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 | |
1707 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1852 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1708 | |
1853 | |
1709 | void |
1854 | void |
1710 | cancel (aio_req_ornot req) |
1855 | cancel (aio_req_ornot req) |
1711 | CODE: |
1856 | CODE: |