ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.183 by root, Tue Jul 5 09:24:11 2011 UTC vs.
Revision 1.196 by root, Tue Sep 27 00:41:51 2011 UTC

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
32
33#ifdef _WIN32
34
35 // perl overrides all those nice libc functions
36
37 #undef malloc
38 #undef free
39 #undef open
40 #undef read
41 #undef write
42 #undef send
43 #undef recv
44 #undef stat
45 #undef lstat
46 #undef fstat
47 #undef truncate
48 #undef ftruncate
49 #undef open
50 #undef link
51 #undef close
52 #undef unlink
53 #undef mkdir
54 #undef rmdir
55 #undef rename
56 #undef lseek
57 #undef opendir
58 #undef readdir
59 #undef closedir
60 #undef chmod
61 #undef fchmod
62 #undef dup
63 #undef dup2
64 #undef abort
65 #undef pipe
66
67#else
68
69 #include <sys/time.h>
70 #include <sys/select.h>
71 #include <unistd.h>
72 #include <utime.h>
73 #include <signal.h>
74
75#endif
82 76
83#define EIO_STRUCT_STAT Stat_t 77#define EIO_STRUCT_STAT Stat_t
84 78
85/* use NV for 32 bit perls as it allows larger offsets */ 79/* use NV for 32 bit perls as it allows larger offsets */
86#if IVSIZE >= 8 80#if IVSIZE >= 8
108 102
109typedef SV SV8; /* byte-sv, used for argument-checking */ 103typedef SV SV8; /* byte-sv, used for argument-checking */
110typedef int aio_rfd; /* read file desriptor */ 104typedef int aio_rfd; /* read file desriptor */
111typedef int aio_wfd; /* write file descriptor */ 105typedef int aio_wfd; /* write file descriptor */
112 106
113static HV *aio_stash, *aio_req_stash, *aio_grp_stash; 107static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash;
114 108
115#define EIO_REQ_MEMBERS \ 109#define EIO_REQ_MEMBERS \
116 SV *callback; \ 110 SV *callback; \
117 SV *sv1, *sv2; \ 111 SV *sv1, *sv2; \
112 SV *sv3, *sv4; \
118 STRLEN stroffset; \ 113 STRLEN stroffset; \
119 SV *self; 114 SV *self;
120 115
121#define EIO_NO_WRAPPERS 1 116#define EIO_NO_WRAPPERS 1
122 117
123#include "libeio/config.h" 118#include "libeio/config.h"
124#include "libeio/eio.h" 119#include "libeio/eio.h"
120
121static int req_invoke (eio_req *req);
122#define EIO_FINISH(req) req_invoke (req)
123static void req_destroy (eio_req *grp);
124#define EIO_DESTROY(req) req_destroy (req)
125
126#include "libeio/eio.c"
125 127
126/* Linux/others */ 128/* Linux/others */
127#ifndef O_ASYNC 129#ifndef O_ASYNC
128# define O_ASYNC 0 130# define O_ASYNC 0
129#endif 131#endif
223#endif 225#endif
224#ifndef PROT_EXEC 226#ifndef PROT_EXEC
225# define PROT_EXEC 0 227# define PROT_EXEC 0
226#endif 228#endif
227 229
230#ifndef ST_RDONLY
231# define ST_RDONLY 0
232#endif
233#ifndef ST_NOSUID
234# define ST_NOSUID 0
235#endif
228#ifndef ST_NODEV 236#ifndef ST_NODEV
229# define ST_NODEV 0 237# define ST_NODEV 0
230#endif 238#endif
231#ifndef ST_NOEXEC 239#ifndef ST_NOEXEC
232# define ST_NOEXEC 0 240# define ST_NOEXEC 0
316 324
317#ifndef PAGESIZE 325#ifndef PAGESIZE
318# define PAGESIZE sysconf (_SC_PAGESIZE) 326# define PAGESIZE sysconf (_SC_PAGESIZE)
319#endif 327#endif
320 328
321static int req_invoke (eio_req *req);
322#define EIO_FINISH(req) req_invoke (req)
323static void req_destroy (eio_req *grp);
324#define EIO_DESTROY(req) req_destroy (req)
325
326enum { 329enum {
327 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 330 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
328}; 331};
329 332
330#include "libeio/eio.c"
331
332typedef eio_req *aio_req; 333typedef eio_req *aio_req;
333typedef eio_req *aio_req_ornot; 334typedef eio_req *aio_req_ornot;
335typedef eio_wd aio_wd;
334 336
335static SV *on_next_submit; 337static SV *on_next_submit;
336static int next_pri = EIO_PRI_DEFAULT; 338static int next_pri = EIO_PRI_DEFAULT;
337static int max_outstanding; 339static int max_outstanding;
338 340
363 } 365 }
364 366
365 return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); 367 return sv_2mortal (sv_bless (newRV_inc (req->self), stash));
366} 368}
367 369
370static SV *
371newSVaio_wd (aio_wd wd)
372{
373 return sv_bless (newRV_noinc (newSViv ((long)wd)), aio_wd_stash);
374}
375
368static aio_req SvAIO_REQ (SV *sv) 376static aio_req SvAIO_REQ (SV *sv)
369{ 377{
370 MAGIC *mg; 378 MAGIC *mg;
371 379
372 if (!SvROK (sv) 380 if (!SvROK (sv)
376 croak ("object of class IO::AIO::REQ expected"); 384 croak ("object of class IO::AIO::REQ expected");
377 385
378 mg = mg_find (SvRV (sv), PERL_MAGIC_ext); 386 mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
379 387
380 return mg ? (aio_req)mg->mg_ptr : 0; 388 return mg ? (aio_req)mg->mg_ptr : 0;
389}
390
391static aio_wd SvAIO_WD (SV *sv)
392{
393 if (!SvROK (sv)
394 || SvSTASH (SvRV (sv)) != aio_wd_stash
395 || SvTYPE (SvRV (sv)) != SVt_PVMG)
396 croak ("IO::AIO: expected a working directory object as returned by aio_wd");
397
398 return (aio_wd)(long)SvIVX (SvRV (sv));
381} 399}
382 400
383static void aio_grp_feed (aio_req grp) 401static void aio_grp_feed (aio_req grp)
384{ 402{
385 if (grp->sv2 && SvOK (grp->sv2)) 403 if (grp->sv2 && SvOK (grp->sv2))
444 SvREADONLY_on (sv_result); 462 SvREADONLY_on (sv_result);
445 } 463 }
446 464
447 switch (req->type) 465 switch (req->type)
448 { 466 {
467 case EIO_WD_OPEN:
468 PUSHs (sv_2mortal (newSVaio_wd (req->wd)));
469 break;
470
449 case EIO_READDIR: 471 case EIO_READDIR:
450 { 472 {
451 SV *rv = &PL_sv_undef; 473 SV *rv = &PL_sv_undef;
452 474
453 if (req->result >= 0) 475 if (req->result >= 0)
541 case EIO_STATVFS: 563 case EIO_STATVFS:
542 case EIO_FSTATVFS: 564 case EIO_FSTATVFS:
543 { 565 {
544 SV *rv = &PL_sv_undef; 566 SV *rv = &PL_sv_undef;
545 567
568#ifndef _WIN32
546 if (req->result >= 0) 569 if (req->result >= 0)
547 { 570 {
548 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); 571 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req);
549 HV *hv = newHV (); 572 HV *hv = newHV ();
550 573
560 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); 583 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); 584 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); 585 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); 586 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0);
564 } 587 }
588#endif
565 589
566 PUSHs (rv); 590 PUSHs (rv);
567 } 591 }
568 592
569 break; 593 break;
595 case EIO_STAT: 619 case EIO_STAT:
596 case EIO_LSTAT: 620 case EIO_LSTAT:
597 case EIO_FSTAT: 621 case EIO_FSTAT:
598 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 622 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
599 PL_laststatval = req->result; 623 PL_laststatval = req->result;
624 /* if compilation fails here then perl's Stat_t is not struct _stati64 */
600 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 625 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
601 PUSHs (sv_result); 626 PUSHs (sv_result);
602 break; 627 break;
603 628
604 case EIO_READ: 629 case EIO_READ:
649 SvREFCNT_dec (req->self); 674 SvREFCNT_dec (req->self);
650 } 675 }
651 676
652 SvREFCNT_dec (req->sv1); 677 SvREFCNT_dec (req->sv1);
653 SvREFCNT_dec (req->sv2); 678 SvREFCNT_dec (req->sv2);
679 SvREFCNT_dec (req->sv3);
680 SvREFCNT_dec (req->sv4);
654 SvREFCNT_dec (req->callback); 681 SvREFCNT_dec (req->callback);
655 682
656 Safefree (req); 683 Safefree (req);
657} 684}
658 685
659static void req_cancel_subs (aio_req grp) 686static void req_cancel_subs (aio_req grp)
660{ 687{
661 aio_req sub;
662
663 if (grp->type != EIO_GROUP) 688 if (grp->type != EIO_GROUP)
664 return; 689 return;
665 690
666 SvREFCNT_dec (grp->sv2); 691 SvREFCNT_dec (grp->sv2);
667 grp->sv2 = 0; 692 grp->sv2 = 0;
668 693
669 eio_grp_cancel (grp); 694 eio_grp_cancel (grp);
670} 695}
671 696
672static void
673create_respipe (void) 697static void create_respipe (void)
674{ 698{
675 if (s_epipe_renew (&respipe)) 699 if (s_epipe_renew (&respipe))
676 croak ("IO::AIO: unable to initialize result pipe"); 700 croak ("IO::AIO: unable to initialize result pipe");
677} 701}
678 702
709 733
710 poll_wait (); 734 poll_wait ();
711 } 735 }
712} 736}
713 737
714static void atfork_child (void) 738static void ecb_cold
739reinit (void)
715{ 740{
716 create_respipe (); 741 create_respipe ();
742
743 if (eio_init (want_poll, done_poll) < 0)
744 croak ("IO::AIO: unable to initialise eio library");
717} 745}
718 746
719/*****************************************************************************/ 747/*****************************************************************************/
720 748
721#if !_POSIX_MAPPED_FILES 749#if !_POSIX_MAPPED_FILES
732# define MAP_FIXED 0 760# define MAP_FIXED 0
733#endif 761#endif
734 762
735#define MMAP_MAGIC PERL_MAGIC_ext 763#define MMAP_MAGIC PERL_MAGIC_ext
736 764
737static int
738mmap_free (pTHX_ SV *sv, MAGIC *mg) 765static int mmap_free (pTHX_ SV *sv, MAGIC *mg)
739{ 766{
740 int old_errno = errno; 767 int old_errno = errno;
741 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 768 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
742 errno = old_errno; 769 errno = old_errno;
743 770
759 0, 0, 0, 0, mmap_free 786 0, 0, 0, 0, mmap_free
760}; 787};
761 788
762/*****************************************************************************/ 789/*****************************************************************************/
763 790
764static SV *
765get_cb (SV *cb_sv) 791static SV * get_cb (SV *cb_sv)
766{ 792{
767 SvGETMAGIC (cb_sv); 793 SvGETMAGIC (cb_sv);
768 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 794 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
769} 795}
770 796
788 req_submit (req); \ 814 req_submit (req); \
789 SPAGAIN; \ 815 SPAGAIN; \
790 \ 816 \
791 if (GIMME_V != G_VOID) \ 817 if (GIMME_V != G_VOID) \
792 XPUSHs (req_sv (req, aio_req_stash)); 818 XPUSHs (req_sv (req, aio_req_stash));
819
820static void
821req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr)
822{
823 if (SvROK (path))
824 {
825 AV *av = (AV *)SvRV (path);
826 SV *wdob;
827
828 if (SvTYPE (av) != SVt_PVAV || AvFILLp (av) != 1)
829 croak ("IO::AIO: pathname arguments must be specified as strings or [wd, path] arrayrefs");
830
831 path = AvARRAY (av)[1];
832 wdob = AvARRAY (av)[0];
833
834 if (SvOK (wdob))
835 {
836 *wd = SvAIO_WD (wdob);
837 *wdsv = SvREFCNT_inc_NN (SvRV (wdob));
838 }
839 else
840 *wd = EIO_INVALID_WD;
841 }
842
843 *pathsv = newSVsv (path);
844 *ptr = SvPVbyte_nolen (*pathsv);
845}
846
847static void
848req_set_path1 (aio_req req, SV *path)
849{
850 req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1);
851}
852
853static void
854req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path)
855{
856 SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path;
857
858 switch (SvTYPE (rv))
859 {
860 case SVt_PVIO:
861 case SVt_PVLV:
862 case SVt_PVGV:
863 req->type = type_fh;
864 req->sv1 = newSVsv (fh_or_path);
865 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
866 break;
867
868 default:
869 req->type = type_path;
870 req_set_path1 (req, fh_or_path);
871 break;
872 }
873
874}
793 875
794MODULE = IO::AIO PACKAGE = IO::AIO 876MODULE = IO::AIO PACKAGE = IO::AIO
795 877
796PROTOTYPES: ENABLE 878PROTOTYPES: ENABLE
797 879
894 976
895 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) 977 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE)
896 const_eio (SYNC_FILE_RANGE_WRITE) 978 const_eio (SYNC_FILE_RANGE_WRITE)
897 const_eio (SYNC_FILE_RANGE_WAIT_AFTER) 979 const_eio (SYNC_FILE_RANGE_WAIT_AFTER)
898 980
981 const_eio (FALLOC_FL_KEEP_SIZE)
982
899 const_eio (READDIR_DENTS) 983 const_eio (READDIR_DENTS)
900 const_eio (READDIR_DIRS_FIRST) 984 const_eio (READDIR_DIRS_FIRST)
901 const_eio (READDIR_STAT_ORDER) 985 const_eio (READDIR_STAT_ORDER)
902 const_eio (READDIR_FOUND_UNKNOWN) 986 const_eio (READDIR_FOUND_UNKNOWN)
903 987
913 }; 997 };
914 998
915 aio_stash = gv_stashpv ("IO::AIO" , 1); 999 aio_stash = gv_stashpv ("IO::AIO" , 1);
916 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); 1000 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1);
917 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); 1001 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1);
1002 aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1);
918 1003
919 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1004 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)); 1005 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
921 1006
922 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 1007 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
923 1008
924 create_respipe (); 1009 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} 1010}
1011
1012void
1013reinit ()
1014 PROTOTYPE:
932 1015
933void 1016void
934max_poll_reqs (unsigned int nreqs) 1017max_poll_reqs (unsigned int nreqs)
935 PROTOTYPE: $ 1018 PROTOTYPE: $
936 CODE: 1019 CODE:
971 PROTOTYPE: $ 1054 PROTOTYPE: $
972 CODE: 1055 CODE:
973 max_outstanding = maxreqs; 1056 max_outstanding = maxreqs;
974 1057
975void 1058void
1059aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef)
1060 PPCODE:
1061{
1062 dREQ;
1063
1064 req->type = EIO_WD_OPEN;
1065 req_set_path1 (req, pathname);
1066
1067 REQ_SEND;
1068}
1069
1070void
976aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 1071aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
977 PPCODE: 1072 PPCODE:
978{ 1073{
979 dREQ; 1074 dREQ;
980 1075
981 req->type = EIO_OPEN; 1076 req->type = EIO_OPEN;
982 req->sv1 = newSVsv (pathname); 1077 req_set_path1 (req, pathname);
983 req->ptr1 = SvPVbyte_nolen (req->sv1);
984 req->int1 = flags; 1078 req->int1 = flags;
985 req->int2 = mode; 1079 req->int2 = mode;
986 1080
987 REQ_SEND; 1081 REQ_SEND;
988} 1082}
990void 1084void
991aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 1085aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
992 ALIAS: 1086 ALIAS:
993 aio_fsync = EIO_FSYNC 1087 aio_fsync = EIO_FSYNC
994 aio_fdatasync = EIO_FDATASYNC 1088 aio_fdatasync = EIO_FDATASYNC
1089 aio_syncfs = EIO_SYNCFS
995 PPCODE: 1090 PPCODE:
996{ 1091{
997 int fd = s_fileno_croak (fh, 0); 1092 int fd = s_fileno_croak (fh, 0);
998 dREQ; 1093 dREQ;
999 1094
1020 1115
1021 REQ_SEND (req); 1116 REQ_SEND (req);
1022} 1117}
1023 1118
1024void 1119void
1120aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef)
1121 PPCODE:
1122{
1123 int fd = s_fileno_croak (fh, 0);
1124 dREQ;
1125
1126 req->type = EIO_FALLOCATE;
1127 req->sv1 = newSVsv (fh);
1128 req->int1 = fd;
1129 req->int2 = mode;
1130 req->offs = offset;
1131 req->size = len;
1132
1133 REQ_SEND (req);
1134}
1135
1136void
1025aio_close (SV *fh, SV *callback=&PL_sv_undef) 1137aio_close (SV *fh, SV *callback=&PL_sv_undef)
1026 PPCODE: 1138 PPCODE:
1027{ 1139{
1028 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 1140 static int close_fd = -1; /* dummy fd to close fds via dup2 */
1029 int fd = s_fileno_croak (fh, 0); 1141 int fd = s_fileno_croak (fh, 0);
1030 dREQ; 1142 dREQ;
1031 1143
1032 if (close_pipe < 0) 1144 if (expect_false (close_fd < 0))
1033 { 1145 {
1034 int pipefd [2]; 1146 int pipefd [2];
1035 1147
1148 if (
1149#ifdef _WIN32
1150 _pipe (pipefd, 1, _O_BINARY) < 0
1151#else
1036 if (pipe (pipefd) < 0 1152 pipe (pipefd) < 0
1037 || close (pipefd [1]) < 0
1038 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) 1153 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0
1154#endif
1155 || close (pipefd [1]) < 0
1156 )
1039 abort (); /*D*/ 1157 abort (); /*D*/
1040 1158
1041 close_pipe = pipefd [0]; 1159 close_fd = pipefd [0];
1042 } 1160 }
1043 1161
1044 req->type = EIO_DUP2; 1162 req->type = EIO_DUP2;
1045 req->int1 = close_pipe; 1163 req->int1 = close_fd;
1046 req->sv2 = newSVsv (fh); 1164 req->sv2 = newSVsv (fh);
1047 req->int2 = fd; 1165 req->int2 = fd;
1048 1166
1049 REQ_SEND (req); 1167 REQ_SEND (req);
1050} 1168}
1101 REQ_SEND; 1219 REQ_SEND;
1102 } 1220 }
1103} 1221}
1104 1222
1105void 1223void
1106aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1224aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1107 ALIAS: 1225 ALIAS:
1108 aio_readlink = EIO_READLINK 1226 aio_readlink = EIO_READLINK
1109 aio_realpath = EIO_REALPATH 1227 aio_realpath = EIO_REALPATH
1110 PPCODE: 1228 PPCODE:
1111{ 1229{
1112 SV *data;
1113 dREQ; 1230 dREQ;
1114 1231
1115 req->type = ix; 1232 req->type = ix;
1116 req->sv1 = newSVsv (path); 1233 req_set_path1 (req, pathname);
1117 req->ptr1 = SvPVbyte_nolen (req->sv1);
1118 1234
1119 REQ_SEND; 1235 REQ_SEND;
1120} 1236}
1121 1237
1122void 1238void
1163 PPCODE: 1279 PPCODE:
1164{ 1280{
1165 dREQ; 1281 dREQ;
1166 1282
1167 req->sv1 = newSVsv (fh_or_path); 1283 req->sv1 = newSVsv (fh_or_path);
1168 1284 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
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
1180 REQ_SEND; 1285 REQ_SEND;
1181} 1286}
1182 1287
1183UV 1288UV
1184major (UV dev) 1289major (UV dev)
1202{ 1307{
1203 dREQ; 1308 dREQ;
1204 1309
1205 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; 1310 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.;
1206 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; 1311 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.;
1207 req->sv1 = newSVsv (fh_or_path); 1312 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 1313
1220 REQ_SEND; 1314 REQ_SEND;
1221} 1315}
1222 1316
1223void 1317void
1224aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) 1318aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef)
1225 PPCODE: 1319 PPCODE:
1226{ 1320{
1227 dREQ; 1321 dREQ;
1228 1322
1229 req->sv1 = newSVsv (fh_or_path);
1230 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 1323 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1231 1324 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 1325
1243 REQ_SEND; 1326 REQ_SEND;
1244} 1327}
1245 1328
1246void 1329void
1251 PPCODE: 1334 PPCODE:
1252{ 1335{
1253 dREQ; 1336 dREQ;
1254 1337
1255 req->int2 = mode; 1338 req->int2 = mode;
1256 req->sv1 = newSVsv (fh_or_path); 1339 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 1340
1269 REQ_SEND; 1341 REQ_SEND;
1270} 1342}
1271 1343
1272void 1344void
1275{ 1347{
1276 dREQ; 1348 dREQ;
1277 1349
1278 req->int2 = SvOK (uid) ? SvIV (uid) : -1; 1350 req->int2 = SvOK (uid) ? SvIV (uid) : -1;
1279 req->int3 = SvOK (gid) ? SvIV (gid) : -1; 1351 req->int3 = SvOK (gid) ? SvIV (gid) : -1;
1280 req->sv1 = newSVsv (fh_or_path); 1352 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 1353
1293 REQ_SEND; 1354 REQ_SEND;
1294} 1355}
1295 1356
1296void 1357void
1319 PPCODE: 1380 PPCODE:
1320{ 1381{
1321 dREQ; 1382 dREQ;
1322 1383
1323 req->type = ix; 1384 req->type = ix;
1324 req->sv1 = newSVsv (pathname); 1385 req_set_path1 (req, pathname);
1325 req->ptr1 = SvPVbyte_nolen (req->sv1);
1326 1386
1327 REQ_SEND; 1387 REQ_SEND;
1328} 1388}
1329 1389
1330void 1390void
1334 aio_symlink = EIO_SYMLINK 1394 aio_symlink = EIO_SYMLINK
1335 aio_rename = EIO_RENAME 1395 aio_rename = EIO_RENAME
1336 PPCODE: 1396 PPCODE:
1337{ 1397{
1338 dREQ; 1398 dREQ;
1399 eio_wd wd2;
1339 1400
1340 req->type = ix; 1401 req->type = ix;
1341 req->sv1 = newSVsv (oldpath); 1402 req_set_path1 (req, oldpath);
1342 req->ptr1 = SvPVbyte_nolen (req->sv1); 1403 req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2);
1343 req->sv2 = newSVsv (newpath); 1404 req->int3 = (long)wd2;
1344 req->ptr2 = SvPVbyte_nolen (req->sv2);
1345 1405
1346 REQ_SEND; 1406 REQ_SEND;
1347} 1407}
1348 1408
1349void 1409void
1351 PPCODE: 1411 PPCODE:
1352{ 1412{
1353 dREQ; 1413 dREQ;
1354 1414
1355 req->type = EIO_MKNOD; 1415 req->type = EIO_MKNOD;
1356 req->sv1 = newSVsv (pathname);
1357 req->ptr1 = SvPVbyte_nolen (req->sv1);
1358 req->int2 = (mode_t)mode; 1416 req->int2 = (mode_t)mode;
1359 req->offs = dev; 1417 req->offs = dev;
1418 req_set_path1 (req, pathname);
1360 1419
1361 REQ_SEND; 1420 REQ_SEND;
1362} 1421}
1363 1422
1364void 1423void
1564 CODE: 1623 CODE:
1565 RETVAL = posix_fadvise (fh, offset, length, advice); 1624 RETVAL = posix_fadvise (fh, offset, length, advice);
1566 OUTPUT: 1625 OUTPUT:
1567 RETVAL 1626 RETVAL
1568 1627
1569ssize_t 1628IV
1570sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1629sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1571 CODE: 1630 CODE:
1572 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1631 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1573 OUTPUT: 1632 OUTPUT:
1574 RETVAL 1633 RETVAL
1686 SvREFCNT_dec (on_next_submit); 1745 SvREFCNT_dec (on_next_submit);
1687 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1746 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1688 1747
1689PROTOTYPES: DISABLE 1748PROTOTYPES: DISABLE
1690 1749
1750MODULE = IO::AIO PACKAGE = IO::AIO::WD
1751
1752BOOT:
1753{
1754 newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD ));
1755 newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD));
1756}
1757
1758void
1759DESTROY (SV *self)
1760 CODE:
1761{
1762 aio_wd wd = SvAIO_WD (self);
1763#if HAVE_AT
1764 SV *callback = &PL_sv_undef;
1765 dREQ; /* clobbers next_pri :/ */
1766 req->type = EIO_WD_CLOSE;
1767 req->wd = wd;
1768 REQ_SEND;
1769#else
1770 eio_wd_close_sync (wd);
1771#endif
1772}
1773
1691MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1774MODULE = IO::AIO PACKAGE = IO::AIO::REQ
1692 1775
1693void 1776void
1694cancel (aio_req_ornot req) 1777cancel (aio_req_ornot req)
1695 CODE: 1778 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines