… | |
… | |
8 | #include "autoconf/config.h" |
8 | #include "autoconf/config.h" |
9 | |
9 | |
10 | #include <pthread.h> |
10 | #include <pthread.h> |
11 | |
11 | |
12 | #include <stddef.h> |
12 | #include <stddef.h> |
|
|
13 | #include <errno.h> |
13 | #include <sys/types.h> |
14 | #include <sys/types.h> |
14 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
15 | #include <limits.h> |
16 | #include <limits.h> |
16 | #include <unistd.h> |
17 | #include <unistd.h> |
17 | #include <fcntl.h> |
18 | #include <fcntl.h> |
… | |
… | |
31 | # else |
32 | # else |
32 | # error sendfile support requested but not available |
33 | # error sendfile support requested but not available |
33 | # endif |
34 | # endif |
34 | #endif |
35 | #endif |
35 | |
36 | |
|
|
37 | /* used for struct dirent, AIX doesn't provide it */ |
|
|
38 | #ifndef NAME_MAX |
|
|
39 | # define NAME_MAX 4096 |
|
|
40 | #endif |
|
|
41 | |
36 | #if __ia64 |
42 | #if __ia64 |
37 | # define STACKSIZE 65536 |
43 | # define STACKSIZE 65536 |
38 | #else |
44 | #else |
39 | # define STACKSIZE 8192 |
45 | # define STACKSIZE 8192 |
40 | #endif |
46 | #endif |
… | |
… | |
44 | REQ_OPEN, REQ_CLOSE, |
50 | REQ_OPEN, REQ_CLOSE, |
45 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
51 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
46 | REQ_SENDFILE, |
52 | REQ_SENDFILE, |
47 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
53 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
48 | REQ_FSYNC, REQ_FDATASYNC, |
54 | REQ_FSYNC, REQ_FDATASYNC, |
49 | REQ_UNLINK, REQ_RMDIR, |
55 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
50 | REQ_READDIR, |
56 | REQ_READDIR, |
51 | REQ_SYMLINK, |
57 | REQ_LINK, REQ_SYMLINK, |
|
|
58 | REQ_GROUP, |
52 | }; |
59 | }; |
53 | |
60 | |
|
|
61 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
|
|
62 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
63 | |
54 | typedef struct aio_cb { |
64 | typedef struct aio_cb |
|
|
65 | { |
|
|
66 | struct aio_cb *grp, *grp_prev, *grp_next; |
|
|
67 | |
55 | struct aio_cb *volatile next; |
68 | struct aio_cb *volatile next; |
56 | |
69 | |
57 | int type; |
70 | SV *self; /* the perl counterpart of this request, if any */ |
58 | |
71 | |
59 | /* should receive a cleanup, with unions */ |
72 | SV *data, *callback; |
60 | int fd, fd2; |
73 | SV *fh, *fh2; |
|
|
74 | void *dataptr, *data2ptr; |
|
|
75 | Stat_t *statdata; |
61 | off_t offset; |
76 | off_t offset; |
62 | size_t length; |
77 | size_t length; |
63 | ssize_t result; |
78 | ssize_t result; |
|
|
79 | |
|
|
80 | int type; |
|
|
81 | int fd, fd2; |
|
|
82 | int errorno; |
|
|
83 | STRLEN dataoffset; |
64 | mode_t mode; /* open */ |
84 | mode_t mode; /* open */ |
65 | int errorno; |
85 | unsigned char cancelled; |
66 | SV *data, *callback; |
|
|
67 | SV *fh, *fh2; |
|
|
68 | void *dataptr, *data2ptr; |
|
|
69 | STRLEN dataoffset; |
|
|
70 | |
|
|
71 | Stat_t *statdata; |
|
|
72 | } aio_cb; |
86 | } aio_cb; |
73 | |
87 | |
74 | typedef aio_cb *aio_req; |
88 | typedef aio_cb *aio_req; |
|
|
89 | typedef aio_cb *aio_req_ornot; |
|
|
90 | typedef aio_cb *aio_group; |
75 | |
91 | |
76 | static int started, wanted; |
92 | static int started, wanted; |
77 | static volatile int nreqs; |
93 | static volatile int nreqs; |
78 | static int max_outstanding = 1<<30; |
94 | static int max_outstanding = 1<<30; |
79 | static int respipe [2]; |
95 | static int respipe [2]; |
… | |
… | |
83 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
99 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
84 | |
100 | |
85 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
101 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
86 | static volatile aio_req ress, rese; /* queue start, queue end */ |
102 | static volatile aio_req ress, rese; /* queue start, queue end */ |
87 | |
103 | |
|
|
104 | /* must be called at most once */ |
|
|
105 | static SV *req_sv (aio_req req, const char *klass) |
|
|
106 | { |
|
|
107 | req->self = (SV *)newHV (); |
|
|
108 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
|
|
109 | |
|
|
110 | return sv_2mortal (sv_bless (newRV_noinc (req->self), gv_stashpv (klass, 1))); |
|
|
111 | } |
|
|
112 | |
|
|
113 | static aio_req SvAIO_REQ (SV *sv, const char *klass) |
|
|
114 | { |
|
|
115 | if (!sv_derived_from (sv, klass) || !SvROK (sv)) |
|
|
116 | croak ("object of class %s expected", klass); |
|
|
117 | |
|
|
118 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
|
|
119 | |
|
|
120 | return mg ? (aio_req)mg->mg_ptr : 0; |
|
|
121 | } |
|
|
122 | |
88 | static void free_req (aio_req req) |
123 | static void req_free (aio_req req) |
89 | { |
124 | { |
|
|
125 | if (req->self) |
|
|
126 | { |
|
|
127 | sv_unmagic (req->self, PERL_MAGIC_ext); |
|
|
128 | SvREFCNT_dec (req->self); |
|
|
129 | } |
|
|
130 | |
90 | if (req->data) |
131 | if (req->data) |
91 | SvREFCNT_dec (req->data); |
132 | SvREFCNT_dec (req->data); |
92 | |
133 | |
93 | if (req->fh) |
134 | if (req->fh) |
94 | SvREFCNT_dec (req->fh); |
135 | SvREFCNT_dec (req->fh); |
… | |
… | |
220 | PUSHMARK (SP); |
261 | PUSHMARK (SP); |
221 | XPUSHs (sv_2mortal (fh)); |
262 | XPUSHs (sv_2mortal (fh)); |
222 | } |
263 | } |
223 | } |
264 | } |
224 | |
265 | |
225 | if (SvOK (req->callback)) |
266 | if (SvOK (req->callback) && !req->cancelled) |
226 | { |
267 | { |
227 | PUTBACK; |
268 | PUTBACK; |
228 | call_sv (req->callback, G_VOID | G_EVAL); |
269 | call_sv (req->callback, G_VOID | G_EVAL); |
229 | SPAGAIN; |
270 | SPAGAIN; |
230 | |
271 | |
231 | if (SvTRUE (ERRSV)) |
272 | if (SvTRUE (ERRSV)) |
232 | { |
273 | { |
233 | free_req (req); |
274 | req_free (req); |
234 | croak (0); |
275 | croak (0); |
235 | } |
276 | } |
236 | } |
277 | } |
237 | |
278 | |
238 | LEAVE; |
279 | LEAVE; |
239 | |
280 | |
240 | errno = errorno; |
281 | errno = errorno; |
241 | count++; |
282 | count++; |
242 | } |
283 | } |
243 | |
284 | |
244 | free_req (req); |
285 | req_free (req); |
245 | } |
286 | } |
246 | |
287 | |
247 | return count; |
288 | return count; |
248 | } |
289 | } |
249 | |
290 | |
… | |
… | |
268 | |
309 | |
269 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
310 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
270 | } |
311 | } |
271 | |
312 | |
272 | static void |
313 | static void |
273 | send_req (aio_req req) |
314 | req_send (aio_req req) |
274 | { |
315 | { |
275 | while (started < wanted && nreqs >= started) |
316 | while (started < wanted && nreqs >= started) |
276 | start_thread (); |
317 | start_thread (); |
277 | |
318 | |
278 | nreqs++; |
319 | nreqs++; |
… | |
… | |
309 | { |
350 | { |
310 | aio_req req; |
351 | aio_req req; |
311 | Newz (0, req, 1, aio_cb); |
352 | Newz (0, req, 1, aio_cb); |
312 | req->type = REQ_QUIT; |
353 | req->type = REQ_QUIT; |
313 | |
354 | |
314 | send_req (req); |
355 | req_send (req); |
315 | } |
356 | } |
316 | |
357 | |
317 | static void min_parallel (int nthreads) |
358 | static void min_parallel (int nthreads) |
318 | { |
359 | { |
319 | if (wanted < nthreads) |
360 | if (wanted < nthreads) |
… | |
… | |
642 | |
683 | |
643 | pthread_mutex_unlock (&reqlock); |
684 | pthread_mutex_unlock (&reqlock); |
644 | |
685 | |
645 | errno = 0; /* strictly unnecessary */ |
686 | errno = 0; /* strictly unnecessary */ |
646 | |
687 | |
647 | type = req->type; |
688 | if (!req->cancelled) |
648 | |
|
|
649 | switch (type) |
689 | switch (req->type) |
650 | { |
690 | { |
651 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
691 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
652 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
692 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
653 | |
693 | |
654 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
694 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
655 | case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length); break; |
695 | case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length); break; |
656 | |
696 | |
657 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
697 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
658 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
698 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
659 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
699 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
660 | |
700 | |
661 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
701 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
662 | case REQ_CLOSE: req->result = close (req->fd); break; |
702 | case REQ_CLOSE: req->result = close (req->fd); break; |
663 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
703 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
664 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
704 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
|
|
705 | case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break; |
|
|
706 | case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break; |
665 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
707 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
666 | |
708 | |
667 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
709 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
668 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
710 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
669 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
711 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
670 | |
712 | |
671 | case REQ_QUIT: |
713 | case REQ_QUIT: |
672 | break; |
714 | break; |
673 | |
715 | |
674 | default: |
716 | default: |
675 | req->result = ENOSYS; |
717 | req->result = ENOSYS; |
676 | break; |
718 | break; |
677 | } |
719 | } |
678 | |
720 | |
679 | req->errorno = errno; |
721 | req->errorno = errno; |
680 | |
722 | |
681 | pthread_mutex_lock (&reslock); |
723 | pthread_mutex_lock (&reslock); |
682 | |
724 | |
… | |
… | |
736 | |
778 | |
737 | while (reqs) |
779 | while (reqs) |
738 | { |
780 | { |
739 | prv = reqs; |
781 | prv = reqs; |
740 | reqs = prv->next; |
782 | reqs = prv->next; |
741 | free_req (prv); |
783 | req_free (prv); |
742 | } |
784 | } |
743 | |
785 | |
744 | reqs = reqe = 0; |
786 | reqs = reqe = 0; |
745 | |
787 | |
746 | while (ress) |
788 | while (ress) |
747 | { |
789 | { |
748 | prv = ress; |
790 | prv = ress; |
749 | ress = prv->next; |
791 | ress = prv->next; |
750 | free_req (prv); |
792 | req_free (prv); |
751 | } |
793 | } |
752 | |
794 | |
753 | ress = rese = 0; |
795 | ress = rese = 0; |
754 | |
796 | |
755 | close (respipe [0]); |
797 | close (respipe [0]); |
… | |
… | |
761 | |
803 | |
762 | #define dREQ \ |
804 | #define dREQ \ |
763 | aio_req req; \ |
805 | aio_req req; \ |
764 | \ |
806 | \ |
765 | if (SvOK (callback) && !SvROK (callback)) \ |
807 | if (SvOK (callback) && !SvROK (callback)) \ |
766 | croak ("clalback must be undef or of reference type"); \ |
808 | croak ("callback must be undef or of reference type"); \ |
767 | \ |
809 | \ |
768 | Newz (0, req, 1, aio_cb); \ |
810 | Newz (0, req, 1, aio_cb); \ |
769 | if (!req) \ |
811 | if (!req) \ |
770 | croak ("out of memory during aio_req allocation"); \ |
812 | croak ("out of memory during aio_req allocation"); \ |
771 | \ |
813 | \ |
772 | req->callback = newSVsv (callback); |
814 | req->callback = newSVsv (callback) |
|
|
815 | |
|
|
816 | #define REQ_SEND \ |
|
|
817 | req_send (req); \ |
|
|
818 | \ |
|
|
819 | if (GIMME_V != G_VOID) \ |
|
|
820 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
773 | |
821 | |
774 | MODULE = IO::AIO PACKAGE = IO::AIO |
822 | MODULE = IO::AIO PACKAGE = IO::AIO |
775 | |
823 | |
776 | PROTOTYPES: ENABLE |
824 | PROTOTYPES: ENABLE |
777 | |
825 | |
778 | BOOT: |
826 | BOOT: |
779 | { |
827 | { |
|
|
828 | HV *stash = gv_stashpv ("IO::AIO", 1); |
|
|
829 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
|
|
830 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
|
|
831 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
|
|
832 | |
780 | create_pipe (); |
833 | create_pipe (); |
781 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
834 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
782 | } |
835 | } |
783 | |
836 | |
784 | void |
837 | void |
785 | min_parallel(nthreads) |
838 | min_parallel (nthreads) |
786 | int nthreads |
839 | int nthreads |
787 | PROTOTYPE: $ |
840 | PROTOTYPE: $ |
788 | |
841 | |
789 | void |
842 | void |
790 | max_parallel(nthreads) |
843 | max_parallel (nthreads) |
791 | int nthreads |
844 | int nthreads |
792 | PROTOTYPE: $ |
845 | PROTOTYPE: $ |
793 | |
846 | |
794 | int |
847 | int |
795 | max_outstanding(nreqs) |
848 | max_outstanding (nreqs) |
796 | int nreqs |
849 | int nreqs |
797 | PROTOTYPE: $ |
850 | PROTOTYPE: $ |
798 | CODE: |
851 | CODE: |
799 | RETVAL = max_outstanding; |
852 | RETVAL = max_outstanding; |
800 | max_outstanding = nreqs; |
853 | max_outstanding = nreqs; |
801 | |
854 | |
802 | void |
855 | void |
803 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
856 | aio_open (pathname,flags,mode,callback=&PL_sv_undef) |
804 | SV * pathname |
857 | SV * pathname |
805 | int flags |
858 | int flags |
806 | int mode |
859 | int mode |
807 | SV * callback |
860 | SV * callback |
808 | PROTOTYPE: $$$;$ |
861 | PROTOTYPE: $$$;$ |
809 | CODE: |
862 | PPCODE: |
810 | { |
863 | { |
811 | dREQ; |
864 | dREQ; |
812 | |
865 | |
813 | req->type = REQ_OPEN; |
866 | req->type = REQ_OPEN; |
814 | req->data = newSVsv (pathname); |
867 | req->data = newSVsv (pathname); |
815 | req->dataptr = SvPVbyte_nolen (req->data); |
868 | req->dataptr = SvPVbyte_nolen (req->data); |
816 | req->fd = flags; |
869 | req->fd = flags; |
817 | req->mode = mode; |
870 | req->mode = mode; |
818 | |
871 | |
819 | send_req (req); |
872 | REQ_SEND; |
820 | } |
873 | } |
821 | |
874 | |
822 | void |
875 | void |
823 | aio_close(fh,callback=&PL_sv_undef) |
876 | aio_close (fh,callback=&PL_sv_undef) |
824 | SV * fh |
877 | SV * fh |
825 | SV * callback |
878 | SV * callback |
826 | PROTOTYPE: $;$ |
879 | PROTOTYPE: $;$ |
827 | ALIAS: |
880 | ALIAS: |
828 | aio_close = REQ_CLOSE |
881 | aio_close = REQ_CLOSE |
829 | aio_fsync = REQ_FSYNC |
882 | aio_fsync = REQ_FSYNC |
830 | aio_fdatasync = REQ_FDATASYNC |
883 | aio_fdatasync = REQ_FDATASYNC |
831 | CODE: |
884 | PPCODE: |
832 | { |
885 | { |
833 | dREQ; |
886 | dREQ; |
834 | |
887 | |
835 | req->type = ix; |
888 | req->type = ix; |
836 | req->fh = newSVsv (fh); |
889 | req->fh = newSVsv (fh); |
837 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
890 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
838 | |
891 | |
839 | send_req (req); |
892 | REQ_SEND (req); |
840 | } |
893 | } |
841 | |
894 | |
842 | void |
895 | void |
843 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
896 | aio_read (fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
844 | SV * fh |
897 | SV * fh |
845 | UV offset |
898 | UV offset |
846 | UV length |
899 | UV length |
847 | SV * data |
900 | SV * data |
848 | UV dataoffset |
901 | UV dataoffset |
849 | SV * callback |
902 | SV * callback |
850 | ALIAS: |
903 | ALIAS: |
851 | aio_read = REQ_READ |
904 | aio_read = REQ_READ |
852 | aio_write = REQ_WRITE |
905 | aio_write = REQ_WRITE |
853 | PROTOTYPE: $$$$$;$ |
906 | PROTOTYPE: $$$$$;$ |
854 | CODE: |
907 | PPCODE: |
855 | { |
908 | { |
856 | aio_req req; |
909 | aio_req req; |
857 | STRLEN svlen; |
910 | STRLEN svlen; |
858 | char *svptr = SvPVbyte (data, svlen); |
911 | char *svptr = SvPVbyte (data, svlen); |
859 | |
912 | |
… | |
… | |
897 | { |
950 | { |
898 | SvREADONLY_on (data); |
951 | SvREADONLY_on (data); |
899 | req->data2ptr = (void *)data; |
952 | req->data2ptr = (void *)data; |
900 | } |
953 | } |
901 | |
954 | |
902 | send_req (req); |
955 | REQ_SEND; |
903 | } |
956 | } |
904 | } |
957 | } |
905 | |
958 | |
906 | void |
959 | void |
907 | aio_sendfile(out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) |
960 | aio_sendfile (out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) |
908 | SV * out_fh |
961 | SV * out_fh |
909 | SV * in_fh |
962 | SV * in_fh |
910 | UV in_offset |
963 | UV in_offset |
911 | UV length |
964 | UV length |
912 | SV * callback |
965 | SV * callback |
913 | PROTOTYPE: $$$$;$ |
966 | PROTOTYPE: $$$$;$ |
914 | CODE: |
967 | PPCODE: |
915 | { |
968 | { |
916 | dREQ; |
969 | dREQ; |
917 | |
970 | |
918 | req->type = REQ_SENDFILE; |
971 | req->type = REQ_SENDFILE; |
919 | req->fh = newSVsv (out_fh); |
972 | req->fh = newSVsv (out_fh); |
… | |
… | |
921 | req->fh2 = newSVsv (in_fh); |
974 | req->fh2 = newSVsv (in_fh); |
922 | req->fd2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
975 | req->fd2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
923 | req->offset = in_offset; |
976 | req->offset = in_offset; |
924 | req->length = length; |
977 | req->length = length; |
925 | |
978 | |
926 | send_req (req); |
979 | REQ_SEND; |
927 | } |
980 | } |
928 | |
981 | |
929 | void |
982 | void |
930 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
983 | aio_readahead (fh,offset,length,callback=&PL_sv_undef) |
931 | SV * fh |
984 | SV * fh |
932 | UV offset |
985 | UV offset |
933 | IV length |
986 | IV length |
934 | SV * callback |
987 | SV * callback |
935 | PROTOTYPE: $$$;$ |
988 | PROTOTYPE: $$$;$ |
936 | CODE: |
989 | PPCODE: |
937 | { |
990 | { |
938 | dREQ; |
991 | dREQ; |
939 | |
992 | |
940 | req->type = REQ_READAHEAD; |
993 | req->type = REQ_READAHEAD; |
941 | req->fh = newSVsv (fh); |
994 | req->fh = newSVsv (fh); |
942 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
995 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
943 | req->offset = offset; |
996 | req->offset = offset; |
944 | req->length = length; |
997 | req->length = length; |
945 | |
998 | |
946 | send_req (req); |
999 | REQ_SEND; |
947 | } |
1000 | } |
948 | |
1001 | |
949 | void |
1002 | void |
950 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
1003 | aio_stat (fh_or_path,callback=&PL_sv_undef) |
951 | SV * fh_or_path |
1004 | SV * fh_or_path |
952 | SV * callback |
1005 | SV * callback |
953 | ALIAS: |
1006 | ALIAS: |
954 | aio_stat = REQ_STAT |
1007 | aio_stat = REQ_STAT |
955 | aio_lstat = REQ_LSTAT |
1008 | aio_lstat = REQ_LSTAT |
956 | CODE: |
1009 | PPCODE: |
957 | { |
1010 | { |
958 | dREQ; |
1011 | dREQ; |
959 | |
1012 | |
960 | New (0, req->statdata, 1, Stat_t); |
1013 | New (0, req->statdata, 1, Stat_t); |
961 | if (!req->statdata) |
1014 | if (!req->statdata) |
962 | { |
1015 | { |
963 | free_req (req); |
1016 | req_free (req); |
964 | croak ("out of memory during aio_req->statdata allocation"); |
1017 | croak ("out of memory during aio_req->statdata allocation"); |
965 | } |
1018 | } |
966 | |
1019 | |
967 | if (SvPOK (fh_or_path)) |
1020 | if (SvPOK (fh_or_path)) |
968 | { |
1021 | { |
… | |
… | |
975 | req->type = REQ_FSTAT; |
1028 | req->type = REQ_FSTAT; |
976 | req->fh = newSVsv (fh_or_path); |
1029 | req->fh = newSVsv (fh_or_path); |
977 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
1030 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
978 | } |
1031 | } |
979 | |
1032 | |
980 | send_req (req); |
1033 | REQ_SEND; |
981 | } |
1034 | } |
982 | |
1035 | |
983 | void |
1036 | void |
984 | aio_unlink(pathname,callback=&PL_sv_undef) |
1037 | aio_unlink (pathname,callback=&PL_sv_undef) |
985 | SV * pathname |
1038 | SV * pathname |
986 | SV * callback |
1039 | SV * callback |
987 | ALIAS: |
1040 | ALIAS: |
988 | aio_unlink = REQ_UNLINK |
1041 | aio_unlink = REQ_UNLINK |
989 | aio_rmdir = REQ_RMDIR |
1042 | aio_rmdir = REQ_RMDIR |
|
|
1043 | aio_readdir = REQ_READDIR |
990 | CODE: |
1044 | PPCODE: |
991 | { |
1045 | { |
992 | dREQ; |
1046 | dREQ; |
993 | |
1047 | |
994 | req->type = ix; |
1048 | req->type = ix; |
995 | req->data = newSVsv (pathname); |
1049 | req->data = newSVsv (pathname); |
996 | req->dataptr = SvPVbyte_nolen (req->data); |
1050 | req->dataptr = SvPVbyte_nolen (req->data); |
997 | |
1051 | |
998 | send_req (req); |
1052 | REQ_SEND; |
999 | } |
1053 | } |
1000 | |
1054 | |
1001 | void |
1055 | void |
1002 | aio_symlink(oldpath,newpath,callback=&PL_sv_undef) |
1056 | aio_link (oldpath,newpath,callback=&PL_sv_undef) |
1003 | SV * oldpath |
1057 | SV * oldpath |
1004 | SV * newpath |
1058 | SV * newpath |
1005 | SV * callback |
1059 | SV * callback |
|
|
1060 | ALIAS: |
|
|
1061 | aio_link = REQ_LINK |
|
|
1062 | aio_symlink = REQ_SYMLINK |
|
|
1063 | aio_rename = REQ_RENAME |
1006 | CODE: |
1064 | PPCODE: |
1007 | { |
1065 | { |
1008 | dREQ; |
1066 | dREQ; |
1009 | |
1067 | |
1010 | req->type = REQ_SYMLINK; |
1068 | req->type = ix; |
1011 | req->fh = newSVsv (oldpath); |
1069 | req->fh = newSVsv (oldpath); |
1012 | req->data2ptr = SvPVbyte_nolen (req->fh); |
1070 | req->data2ptr = SvPVbyte_nolen (req->fh); |
1013 | req->data = newSVsv (newpath); |
1071 | req->data = newSVsv (newpath); |
1014 | req->dataptr = SvPVbyte_nolen (req->data); |
1072 | req->dataptr = SvPVbyte_nolen (req->data); |
1015 | |
1073 | |
1016 | send_req (req); |
1074 | REQ_SEND; |
1017 | } |
1075 | } |
1018 | |
1076 | |
1019 | void |
1077 | void |
1020 | aio_readdir(pathname,callback=&PL_sv_undef) |
1078 | aio_group (callback=&PL_sv_undef) |
1021 | SV * pathname |
1079 | SV * callback |
1022 | SV * callback |
1080 | PROTOTYPE: ;& |
1023 | CODE: |
1081 | PPCODE: |
1024 | { |
1082 | { |
1025 | dREQ; |
1083 | dREQ; |
1026 | |
|
|
1027 | req->type = REQ_READDIR; |
1084 | req->type = REQ_GROUP; |
1028 | req->data = newSVsv (pathname); |
1085 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1029 | req->dataptr = SvPVbyte_nolen (req->data); |
|
|
1030 | |
|
|
1031 | send_req (req); |
|
|
1032 | } |
1086 | } |
1033 | |
1087 | |
1034 | void |
1088 | void |
1035 | flush() |
1089 | flush () |
1036 | PROTOTYPE: |
1090 | PROTOTYPE: |
1037 | CODE: |
1091 | CODE: |
1038 | while (nreqs) |
1092 | while (nreqs) |
1039 | { |
1093 | { |
1040 | poll_wait (); |
1094 | poll_wait (); |
… | |
… | |
1080 | CODE: |
1134 | CODE: |
1081 | RETVAL = nreqs; |
1135 | RETVAL = nreqs; |
1082 | OUTPUT: |
1136 | OUTPUT: |
1083 | RETVAL |
1137 | RETVAL |
1084 | |
1138 | |
|
|
1139 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
|
|
1140 | |
|
|
1141 | void |
|
|
1142 | cancel (aio_req_ornot req) |
|
|
1143 | PROTOTYPE: |
|
|
1144 | CODE: |
|
|
1145 | req->cancelled = 1; |
|
|
1146 | |