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.190 by root, Mon Jul 18 02:02:26 2011 UTC vs.
Revision 1.209 by root, Sun Apr 1 17:46:02 2012 UTC

62 #undef dup 62 #undef dup
63 #undef dup2 63 #undef dup2
64 #undef abort 64 #undef abort
65 #undef pipe 65 #undef pipe
66 66
67 #define EIO_STRUCT_STAT struct _stati64
68 #define EIO_STRUCT_STATI64
69
67#else 70#else
68 71
69 #include <sys/time.h> 72 #include <sys/time.h>
70 #include <sys/select.h> 73 #include <sys/select.h>
71 #include <unistd.h> 74 #include <unistd.h>
72 #include <utime.h> 75 #include <utime.h>
73 #include <signal.h> 76 #include <signal.h>
74 77
75#endif
76
77#define EIO_STRUCT_STAT Stat_t 78 #define EIO_STRUCT_STAT Stat_t
79
80#endif
78 81
79/* use NV for 32 bit perls as it allows larger offsets */ 82/* use NV for 32 bit perls as it allows larger offsets */
80#if IVSIZE >= 8 83#if IVSIZE >= 8
81# define VAL64 IV 84# define VAL64 IV
82# define SvVAL64 SvIV 85# define SvVAL64 SvIV
102 105
103typedef SV SV8; /* byte-sv, used for argument-checking */ 106typedef SV SV8; /* byte-sv, used for argument-checking */
104typedef int aio_rfd; /* read file desriptor */ 107typedef int aio_rfd; /* read file desriptor */
105typedef int aio_wfd; /* write file descriptor */ 108typedef int aio_wfd; /* write file descriptor */
106 109
107static HV *aio_stash, *aio_req_stash, *aio_grp_stash; 110static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash;
108 111
109#define EIO_REQ_MEMBERS \ 112#define EIO_REQ_MEMBERS \
110 SV *callback; \ 113 SV *callback; \
111 SV *sv1, *sv2; \ 114 SV *sv1, *sv2; \
115 SV *sv3, *sv4; \
112 STRLEN stroffset; \ 116 STRLEN stroffset; \
113 SV *self; 117 SV *self;
114 118
115#define EIO_NO_WRAPPERS 1 119#define EIO_NO_WRAPPERS 1
116 120
329 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 333 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
330}; 334};
331 335
332typedef eio_req *aio_req; 336typedef eio_req *aio_req;
333typedef eio_req *aio_req_ornot; 337typedef eio_req *aio_req_ornot;
338typedef eio_wd aio_wd;
334 339
335static SV *on_next_submit; 340static SV *on_next_submit;
336static int next_pri = EIO_PRI_DEFAULT; 341static int next_pri = EIO_PRI_DEFAULT;
337static int max_outstanding; 342static int max_outstanding;
338 343
339static s_epipe respipe; 344static s_epipe respipe;
340 345
341static void req_destroy (aio_req req); 346static void req_destroy (aio_req req);
342static void req_cancel (aio_req req); 347static void req_cancel (aio_req req);
343 348
344static void want_poll (void) 349static void
350want_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
350static void done_poll (void) 356static void
357done_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 */
364static SV *
357static SV *req_sv (aio_req req, HV *stash) 365req_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
368static aio_req SvAIO_REQ (SV *sv) 376static SV *
377newSVaio_wd (aio_wd wd)
378{
379 return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash);
380}
381
382static aio_req
383SvAIO_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
399static aio_wd
400SvAIO_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
410static void
383static void aio_grp_feed (aio_req grp) 411aio_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
429static void
401static void req_submit (eio_req *req) 430req_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
447static int
418static int req_invoke (eio_req *req) 448req_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)
595 break; 629 break;
596 630
597 case EIO_STAT: 631 case EIO_STAT:
598 case EIO_LSTAT: 632 case EIO_LSTAT:
599 case EIO_FSTAT: 633 case EIO_FSTAT:
600 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 634 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
635
601 PL_laststatval = req->result; 636 if (!(PL_laststatval = req->result))
602 /* if compilation fails here then perl's Stat_t is not struct _stati64 */ 637 /* if compilation fails here then perl's Stat_t is not struct _stati64 */
603 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 638 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
639
604 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)));
605 break; 645 break;
606 646
607 case EIO_READ: 647 case EIO_READ:
608 { 648 {
609 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));
642 } 682 }
643 683
644 return !!SvTRUE (ERRSV); 684 return !!SvTRUE (ERRSV);
645} 685}
646 686
687static void
647static void req_destroy (aio_req req) 688req_destroy (aio_req req)
648{ 689{
649 if (req->self) 690 if (req->self)
650 { 691 {
651 sv_unmagic (req->self, PERL_MAGIC_ext); 692 sv_unmagic (req->self, PERL_MAGIC_ext);
652 SvREFCNT_dec (req->self); 693 SvREFCNT_dec (req->self);
653 } 694 }
654 695
655 SvREFCNT_dec (req->sv1); 696 SvREFCNT_dec (req->sv1);
656 SvREFCNT_dec (req->sv2); 697 SvREFCNT_dec (req->sv2);
698 SvREFCNT_dec (req->sv3);
699 SvREFCNT_dec (req->sv4);
657 SvREFCNT_dec (req->callback); 700 SvREFCNT_dec (req->callback);
658 701
659 Safefree (req); 702 free (req);
660} 703}
661 704
705static void
662static void req_cancel_subs (aio_req grp) 706req_cancel_subs (aio_req grp)
663{ 707{
664 if (grp->type != EIO_GROUP) 708 if (grp->type != EIO_GROUP)
665 return; 709 return;
666 710
667 SvREFCNT_dec (grp->sv2); 711 SvREFCNT_dec (grp->sv2);
668 grp->sv2 = 0; 712 grp->sv2 = 0;
669 713
670 eio_grp_cancel (grp); 714 eio_grp_cancel (grp);
671} 715}
672 716
717static void ecb_cold
673static void create_respipe (void) 718create_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
679static void poll_wait (void) 724static void
725poll_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
698static int poll_cb (void) 744static int
745poll_cb (void)
699{ 746{
700 for (;;) 747 for (;;)
701 { 748 {
702 int res = eio_poll (); 749 int res = eio_poll ();
703 750
736# define MAP_FIXED 0 783# define MAP_FIXED 0
737#endif 784#endif
738 785
739#define MMAP_MAGIC PERL_MAGIC_ext 786#define MMAP_MAGIC PERL_MAGIC_ext
740 787
788static int ecb_cold
741static int mmap_free (pTHX_ SV *sv, MAGIC *mg) 789mmap_free (pTHX_ SV *sv, MAGIC *mg)
742{ 790{
743 int old_errno = errno; 791 int old_errno = errno;
744 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 792 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
745 errno = old_errno; 793 errno = old_errno;
746 794
762 0, 0, 0, 0, mmap_free 810 0, 0, 0, 0, mmap_free
763}; 811};
764 812
765/*****************************************************************************/ 813/*****************************************************************************/
766 814
815static SV *
767static SV * get_cb (SV *cb_sv) 816get_cb (SV *cb_sv)
768{ 817{
769 SvGETMAGIC (cb_sv); 818 SvGETMAGIC (cb_sv);
770 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 819 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
771} 820}
772 821
822static aio_req ecb_noinline
823dreq (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
773#define dREQ \ 842#define dREQ \
774 SV *cb_cv; \ 843 aio_req req = dreq (callback); \
775 aio_req req; \
776 int req_pri = next_pri; \
777 next_pri = EIO_PRI_DEFAULT; \
778 \
779 cb_cv = get_cb (callback); \
780 \
781 Newz (0, req, 1, eio_req); \
782 if (!req) \
783 croak ("out of memory during eio_req allocation"); \
784 \
785 req->callback = SvREFCNT_inc (cb_cv); \
786 req->pri = req_pri
787 844
788#define REQ_SEND \ 845#define REQ_SEND \
789 PUTBACK; \ 846 PUTBACK; \
790 req_submit (req); \ 847 req_submit (req); \
791 SPAGAIN; \ 848 SPAGAIN; \
792 \ 849 \
793 if (GIMME_V != G_VOID) \ 850 if (GIMME_V != G_VOID) \
794 XPUSHs (req_sv (req, aio_req_stash)); 851 XPUSHs (req_sv (req, aio_req_stash));
852
853ecb_inline void
854req_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
889static void ecb_noinline
890req_set_path1 (aio_req req, SV *path)
891{
892 req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1);
893}
894
895static void ecb_noinline
896req_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
917XS(boot_IO__AIO) ecb_cold;
795 918
796MODULE = IO::AIO PACKAGE = IO::AIO 919MODULE = IO::AIO PACKAGE = IO::AIO
797 920
798PROTOTYPES: ENABLE 921PROTOTYPES: ENABLE
799 922
883 const_iv (MAP_LOCKED) 1006 const_iv (MAP_LOCKED)
884 const_iv (MAP_NORESERVE) 1007 const_iv (MAP_NORESERVE)
885 const_iv (MAP_POPULATE) 1008 const_iv (MAP_POPULATE)
886 const_iv (MAP_NONBLOCK) 1009 const_iv (MAP_NONBLOCK)
887 1010
1011 const_eio (SEEK_SET)
1012 const_eio (SEEK_CUR)
1013 const_eio (SEEK_END)
1014
888 const_eio (MCL_FUTURE) 1015 const_eio (MCL_FUTURE)
889 const_eio (MCL_CURRENT) 1016 const_eio (MCL_CURRENT)
890 1017
891 const_eio (MS_ASYNC) 1018 const_eio (MS_ASYNC)
892 const_eio (MS_INVALIDATE) 1019 const_eio (MS_INVALIDATE)
917 }; 1044 };
918 1045
919 aio_stash = gv_stashpv ("IO::AIO" , 1); 1046 aio_stash = gv_stashpv ("IO::AIO" , 1);
920 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); 1047 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1);
921 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);
922 1050
923 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--)
924 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); 1052 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
925 1053
926 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 1054 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
927 1055
928 reinit (); 1056 reinit ();
929} 1057}
930 1058
931void 1059void
932reinit () 1060reinit ()
933 PROTOTYPE: 1061 PROTOTYPE:
934 CODE:
935 reinit ();
936 1062
937void 1063void
938max_poll_reqs (unsigned int nreqs) 1064max_poll_reqs (unsigned int nreqs)
939 PROTOTYPE: $ 1065 PROTOTYPE: $
940 CODE: 1066 CODE:
975 PROTOTYPE: $ 1101 PROTOTYPE: $
976 CODE: 1102 CODE:
977 max_outstanding = maxreqs; 1103 max_outstanding = maxreqs;
978 1104
979void 1105void
1106aio_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
1117void
980aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 1118aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
981 PPCODE: 1119 PPCODE:
982{ 1120{
983 dREQ; 1121 dREQ;
984 1122
985 req->type = EIO_OPEN; 1123 req->type = EIO_OPEN;
986 req->sv1 = newSVsv (pathname); 1124 req_set_path1 (req, pathname);
987 req->ptr1 = SvPVbyte_nolen (req->sv1);
988 req->int1 = flags; 1125 req->int1 = flags;
989 req->int2 = mode; 1126 req->int2 = mode;
990 1127
991 REQ_SEND; 1128 REQ_SEND;
992} 1129}
994void 1131void
995aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 1132aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
996 ALIAS: 1133 ALIAS:
997 aio_fsync = EIO_FSYNC 1134 aio_fsync = EIO_FSYNC
998 aio_fdatasync = EIO_FDATASYNC 1135 aio_fdatasync = EIO_FDATASYNC
1136 aio_syncfs = EIO_SYNCFS
999 PPCODE: 1137 PPCODE:
1000{ 1138{
1001 int fd = s_fileno_croak (fh, 0); 1139 int fd = s_fileno_croak (fh, 0);
1002 dREQ; 1140 dREQ;
1003 1141
1004 req->type = ix; 1142 req->type = ix;
1005 req->sv1 = newSVsv (fh); 1143 req->sv1 = newSVsv (fh);
1006 req->int1 = fd; 1144 req->int1 = fd;
1007 1145
1008 REQ_SEND (req); 1146 REQ_SEND;
1009} 1147}
1010 1148
1011void 1149void
1012aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 1150aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef)
1013 PPCODE: 1151 PPCODE:
1020 req->int1 = fd; 1158 req->int1 = fd;
1021 req->offs = offset; 1159 req->offs = offset;
1022 req->size = nbytes; 1160 req->size = nbytes;
1023 req->int2 = flags; 1161 req->int2 = flags;
1024 1162
1025 REQ_SEND (req); 1163 REQ_SEND;
1026} 1164}
1027 1165
1028void 1166void
1029aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) 1167aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef)
1030 PPCODE: 1168 PPCODE:
1037 req->int1 = fd; 1175 req->int1 = fd;
1038 req->int2 = mode; 1176 req->int2 = mode;
1039 req->offs = offset; 1177 req->offs = offset;
1040 req->size = len; 1178 req->size = len;
1041 1179
1042 REQ_SEND (req); 1180 REQ_SEND;
1043} 1181}
1044 1182
1045void 1183void
1046aio_close (SV *fh, SV *callback=&PL_sv_undef) 1184aio_close (SV *fh, SV *callback=&PL_sv_undef)
1047 PPCODE: 1185 PPCODE:
1071 req->type = EIO_DUP2; 1209 req->type = EIO_DUP2;
1072 req->int1 = close_fd; 1210 req->int1 = close_fd;
1073 req->sv2 = newSVsv (fh); 1211 req->sv2 = newSVsv (fh);
1074 req->int2 = fd; 1212 req->int2 = fd;
1075 1213
1076 REQ_SEND (req); 1214 REQ_SEND;
1215}
1216
1217void
1218aio_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;
1077} 1232}
1078 1233
1079void 1234void
1080aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 1235aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
1081 ALIAS: 1236 ALIAS:
1128 REQ_SEND; 1283 REQ_SEND;
1129 } 1284 }
1130} 1285}
1131 1286
1132void 1287void
1133aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1288aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1134 ALIAS: 1289 ALIAS:
1135 aio_readlink = EIO_READLINK 1290 aio_readlink = EIO_READLINK
1136 aio_realpath = EIO_REALPATH 1291 aio_realpath = EIO_REALPATH
1137 PPCODE: 1292 PPCODE:
1138{ 1293{
1139 dREQ; 1294 dREQ;
1140 1295
1141 req->type = ix; 1296 req->type = ix;
1142 req->sv1 = newSVsv (path); 1297 req_set_path1 (req, pathname);
1143 req->ptr1 = SvPVbyte_nolen (req->sv1);
1144 1298
1145 REQ_SEND; 1299 REQ_SEND;
1146} 1300}
1147 1301
1148void 1302void
1188 aio_statvfs = EIO_STATVFS 1342 aio_statvfs = EIO_STATVFS
1189 PPCODE: 1343 PPCODE:
1190{ 1344{
1191 dREQ; 1345 dREQ;
1192 1346
1193 req->sv1 = newSVsv (fh_or_path); 1347 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1194
1195 if (SvPOK (req->sv1))
1196 {
1197 req->type = ix;
1198 req->ptr1 = SvPVbyte_nolen (req->sv1);
1199 }
1200 else
1201 {
1202 req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT;
1203 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1204 }
1205 1348
1206 REQ_SEND; 1349 REQ_SEND;
1207} 1350}
1208 1351
1209UV 1352UV
1228{ 1371{
1229 dREQ; 1372 dREQ;
1230 1373
1231 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; 1374 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.;
1232 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; 1375 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.;
1233 req->sv1 = newSVsv (fh_or_path); 1376 req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path);
1234
1235 if (SvPOK (req->sv1))
1236 {
1237 req->type = EIO_UTIME;
1238 req->ptr1 = SvPVbyte_nolen (req->sv1);
1239 }
1240 else
1241 {
1242 req->type = EIO_FUTIME;
1243 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1244 }
1245 1377
1246 REQ_SEND; 1378 REQ_SEND;
1247} 1379}
1248 1380
1249void 1381void
1250aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) 1382aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef)
1251 PPCODE: 1383 PPCODE:
1252{ 1384{
1253 dREQ; 1385 dREQ;
1254 1386
1255 req->sv1 = newSVsv (fh_or_path);
1256 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 1387 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1257 1388 req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path);
1258 if (SvPOK (req->sv1))
1259 {
1260 req->type = EIO_TRUNCATE;
1261 req->ptr1 = SvPVbyte_nolen (req->sv1);
1262 }
1263 else
1264 {
1265 req->type = EIO_FTRUNCATE;
1266 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1267 }
1268 1389
1269 REQ_SEND; 1390 REQ_SEND;
1270} 1391}
1271 1392
1272void 1393void
1273aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) 1394aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef)
1274 ALIAS:
1275 aio_chmod = EIO_CHMOD
1276 aio_mkdir = EIO_MKDIR
1277 PPCODE: 1395 PPCODE:
1278{ 1396{
1279 dREQ; 1397 dREQ;
1280 1398
1281 req->int2 = mode; 1399 req->int2 = mode;
1282 req->sv1 = newSVsv (fh_or_path); 1400 req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path);
1283
1284 if (SvPOK (req->sv1))
1285 {
1286 req->type = ix;
1287 req->ptr1 = SvPVbyte_nolen (req->sv1);
1288 }
1289 else
1290 {
1291 req->type = EIO_FCHMOD;
1292 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1293 }
1294 1401
1295 REQ_SEND; 1402 REQ_SEND;
1296} 1403}
1297 1404
1298void 1405void
1301{ 1408{
1302 dREQ; 1409 dREQ;
1303 1410
1304 req->int2 = SvOK (uid) ? SvIV (uid) : -1; 1411 req->int2 = SvOK (uid) ? SvIV (uid) : -1;
1305 req->int3 = SvOK (gid) ? SvIV (gid) : -1; 1412 req->int3 = SvOK (gid) ? SvIV (gid) : -1;
1306 req->sv1 = newSVsv (fh_or_path); 1413 req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path);
1307
1308 if (SvPOK (req->sv1))
1309 {
1310 req->type = EIO_CHOWN;
1311 req->ptr1 = SvPVbyte_nolen (req->sv1);
1312 }
1313 else
1314 {
1315 req->type = EIO_FCHOWN;
1316 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1317 }
1318 1414
1319 REQ_SEND; 1415 REQ_SEND;
1320} 1416}
1321 1417
1322void 1418void
1324 PPCODE: 1420 PPCODE:
1325{ 1421{
1326 dREQ; 1422 dREQ;
1327 1423
1328 req->type = EIO_READDIR; 1424 req->type = EIO_READDIR;
1329 req->sv1 = newSVsv (pathname);
1330 req->ptr1 = SvPVbyte_nolen (req->sv1);
1331 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; 1425 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1;
1332 1426
1333 if (flags & EIO_READDIR_DENTS) 1427 if (flags & EIO_READDIR_DENTS)
1334 req->int1 |= EIO_READDIR_CUSTOM2; 1428 req->int1 |= EIO_READDIR_CUSTOM2;
1335 1429
1430 req_set_path1 (req, pathname);
1431
1336 REQ_SEND; 1432 REQ_SEND;
1433}
1434
1435void
1436aio_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;
1337} 1446}
1338 1447
1339void 1448void
1340aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) 1449aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1341 ALIAS: 1450 ALIAS:
1345 PPCODE: 1454 PPCODE:
1346{ 1455{
1347 dREQ; 1456 dREQ;
1348 1457
1349 req->type = ix; 1458 req->type = ix;
1350 req->sv1 = newSVsv (pathname); 1459 req_set_path1 (req, pathname);
1351 req->ptr1 = SvPVbyte_nolen (req->sv1);
1352 1460
1353 REQ_SEND; 1461 REQ_SEND;
1354} 1462}
1355 1463
1356void 1464void
1359 aio_link = EIO_LINK 1467 aio_link = EIO_LINK
1360 aio_symlink = EIO_SYMLINK 1468 aio_symlink = EIO_SYMLINK
1361 aio_rename = EIO_RENAME 1469 aio_rename = EIO_RENAME
1362 PPCODE: 1470 PPCODE:
1363{ 1471{
1472 eio_wd wd2 = 0;
1364 dREQ; 1473 dREQ;
1365 1474
1366 req->type = ix; 1475 req->type = ix;
1367 req->sv1 = newSVsv (oldpath); 1476 req_set_path1 (req, oldpath);
1368 req->ptr1 = SvPVbyte_nolen (req->sv1); 1477 req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2);
1369 req->sv2 = newSVsv (newpath); 1478 req->int3 = (long)wd2;
1370 req->ptr2 = SvPVbyte_nolen (req->sv2);
1371 1479
1372 REQ_SEND; 1480 REQ_SEND;
1373} 1481}
1374 1482
1375void 1483void
1377 PPCODE: 1485 PPCODE:
1378{ 1486{
1379 dREQ; 1487 dREQ;
1380 1488
1381 req->type = EIO_MKNOD; 1489 req->type = EIO_MKNOD;
1382 req->sv1 = newSVsv (pathname);
1383 req->ptr1 = SvPVbyte_nolen (req->sv1);
1384 req->int2 = (mode_t)mode; 1490 req->int2 = (mode_t)mode;
1385 req->offs = dev; 1491 req->offs = dev;
1492 req_set_path1 (req, pathname);
1386 1493
1387 REQ_SEND; 1494 REQ_SEND;
1388} 1495}
1389 1496
1390void 1497void
1590 CODE: 1697 CODE:
1591 RETVAL = posix_fadvise (fh, offset, length, advice); 1698 RETVAL = posix_fadvise (fh, offset, length, advice);
1592 OUTPUT: 1699 OUTPUT:
1593 RETVAL 1700 RETVAL
1594 1701
1595ssize_t 1702IV
1596sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1703sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1597 CODE: 1704 CODE:
1598 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1705 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1599 OUTPUT: 1706 OUTPUT:
1600 RETVAL 1707 RETVAL
1712 SvREFCNT_dec (on_next_submit); 1819 SvREFCNT_dec (on_next_submit);
1713 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1820 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1714 1821
1715PROTOTYPES: DISABLE 1822PROTOTYPES: DISABLE
1716 1823
1824MODULE = IO::AIO PACKAGE = IO::AIO::WD
1825
1826BOOT:
1827{
1828 newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD ));
1829 newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD));
1830}
1831
1832void
1833DESTROY (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
1717MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1852MODULE = IO::AIO PACKAGE = IO::AIO::REQ
1718 1853
1719void 1854void
1720cancel (aio_req_ornot req) 1855cancel (aio_req_ornot req)
1721 CODE: 1856 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines