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.188 by root, Sun Jul 17 04:20:04 2011 UTC vs.
Revision 1.209 by root, Sun Apr 1 17:46:02 2012 UTC

30#undef opendir 30#undef opendir
31#undef closedir 31#undef closedir
32 32
33#ifdef _WIN32 33#ifdef _WIN32
34 34
35 #define EIO_STRUCT_DIRENT Direntry_t 35 // perl overrides all those nice libc functions
36
36 #undef malloc 37 #undef malloc
37 #undef free 38 #undef free
38
39 // perl overrides all those nice libc functions
40 #undef open 39 #undef open
41 #undef read 40 #undef read
42 #undef write 41 #undef write
43 #undef send 42 #undef send
44 #undef recv 43 #undef recv
63 #undef dup 62 #undef dup
64 #undef dup2 63 #undef dup2
65 #undef abort 64 #undef abort
66 #undef pipe 65 #undef pipe
67 66
67 #define EIO_STRUCT_STAT struct _stati64
68 #define EIO_STRUCT_STATI64
69
68#else 70#else
69 71
70 #include <sys/time.h> 72 #include <sys/time.h>
71 #include <sys/select.h> 73 #include <sys/select.h>
72 #include <unistd.h> 74 #include <unistd.h>
73 #include <utime.h> 75 #include <utime.h>
74 #include <signal.h> 76 #include <signal.h>
75 77
76#endif
77
78#define EIO_STRUCT_STAT Stat_t 78 #define EIO_STRUCT_STAT Stat_t
79
80#endif
79 81
80/* use NV for 32 bit perls as it allows larger offsets */ 82/* use NV for 32 bit perls as it allows larger offsets */
81#if IVSIZE >= 8 83#if IVSIZE >= 8
82# define VAL64 IV 84# define VAL64 IV
83# define SvVAL64 SvIV 85# define SvVAL64 SvIV
103 105
104typedef SV SV8; /* byte-sv, used for argument-checking */ 106typedef SV SV8; /* byte-sv, used for argument-checking */
105typedef int aio_rfd; /* read file desriptor */ 107typedef int aio_rfd; /* read file desriptor */
106typedef int aio_wfd; /* write file descriptor */ 108typedef int aio_wfd; /* write file descriptor */
107 109
108static HV *aio_stash, *aio_req_stash, *aio_grp_stash; 110static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash;
109 111
110#define EIO_REQ_MEMBERS \ 112#define EIO_REQ_MEMBERS \
111 SV *callback; \ 113 SV *callback; \
112 SV *sv1, *sv2; \ 114 SV *sv1, *sv2; \
115 SV *sv3, *sv4; \
113 STRLEN stroffset; \ 116 STRLEN stroffset; \
114 SV *self; 117 SV *self;
115 118
116#define EIO_NO_WRAPPERS 1 119#define EIO_NO_WRAPPERS 1
117 120
330 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 333 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
331}; 334};
332 335
333typedef eio_req *aio_req; 336typedef eio_req *aio_req;
334typedef eio_req *aio_req_ornot; 337typedef eio_req *aio_req_ornot;
338typedef eio_wd aio_wd;
335 339
336static SV *on_next_submit; 340static SV *on_next_submit;
337static int next_pri = EIO_PRI_DEFAULT; 341static int next_pri = EIO_PRI_DEFAULT;
338static int max_outstanding; 342static int max_outstanding;
339 343
340static s_epipe respipe; 344static s_epipe respipe;
341 345
342static void req_destroy (aio_req req); 346static void req_destroy (aio_req req);
343static void req_cancel (aio_req req); 347static void req_cancel (aio_req req);
344 348
345static void want_poll (void) 349static void
350want_poll (void)
346{ 351{
347 /* write a dummy byte to the pipe so fh becomes ready */ 352 /* write a dummy byte to the pipe so fh becomes ready */
348 s_epipe_signal (&respipe); 353 s_epipe_signal (&respipe);
349} 354}
350 355
351static void done_poll (void) 356static void
357done_poll (void)
352{ 358{
353 /* read any signals sent by the worker threads */ 359 /* read any signals sent by the worker threads */
354 s_epipe_drain (&respipe); 360 s_epipe_drain (&respipe);
355} 361}
356 362
357/* must be called at most once */ 363/* must be called at most once */
364static SV *
358static SV *req_sv (aio_req req, HV *stash) 365req_sv (aio_req req, HV *stash)
359{ 366{
360 if (!req->self) 367 if (!req->self)
361 { 368 {
362 req->self = (SV *)newHV (); 369 req->self = (SV *)newHV ();
363 sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); 370 sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0);
364 } 371 }
365 372
366 return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); 373 return sv_2mortal (sv_bless (newRV_inc (req->self), stash));
367} 374}
368 375
369static 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)
370{ 384{
371 MAGIC *mg; 385 MAGIC *mg;
372 386
373 if (!SvROK (sv) 387 if (!SvROK (sv)
388 /* for speed reasons, we do not verify that SvROK actually has a stash ptr */
374 || (SvSTASH (SvRV (sv)) != aio_grp_stash 389 || (SvSTASH (SvRV (sv)) != aio_grp_stash
375 && SvSTASH (SvRV (sv)) != aio_req_stash 390 && SvSTASH (SvRV (sv)) != aio_req_stash
376 && !sv_derived_from (sv, "IO::AIO::REQ"))) 391 && !sv_derived_from (sv, "IO::AIO::REQ")))
377 croak ("object of class IO::AIO::REQ expected"); 392 croak ("object of class IO::AIO::REQ expected");
378 393
379 mg = mg_find (SvRV (sv), PERL_MAGIC_ext); 394 mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
380 395
381 return mg ? (aio_req)mg->mg_ptr : 0; 396 return mg ? (aio_req)mg->mg_ptr : 0;
382} 397}
383 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
384static void aio_grp_feed (aio_req grp) 411aio_grp_feed (aio_req grp)
385{ 412{
386 if (grp->sv2 && SvOK (grp->sv2)) 413 if (grp->sv2 && SvOK (grp->sv2))
387 { 414 {
388 dSP; 415 dSP;
389 416
397 FREETMPS; 424 FREETMPS;
398 LEAVE; 425 LEAVE;
399 } 426 }
400} 427}
401 428
429static void
402static void req_submit (eio_req *req) 430req_submit (eio_req *req)
403{ 431{
404 eio_submit (req); 432 eio_submit (req);
405 433
406 if (expect_false (on_next_submit)) 434 if (expect_false (on_next_submit))
407 { 435 {
414 PUTBACK; 442 PUTBACK;
415 call_sv (cb, G_DISCARD | G_EVAL); 443 call_sv (cb, G_DISCARD | G_EVAL);
416 } 444 }
417} 445}
418 446
447static int
419static int req_invoke (eio_req *req) 448req_invoke (eio_req *req)
420{ 449{
421 if (req->flags & FLAG_SV2_RO_OFF) 450 if (req->flags & FLAG_SV2_RO_OFF)
422 SvREADONLY_off (req->sv2); 451 SvREADONLY_off (req->sv2);
423 452
424 if (!EIO_CANCELLED (req) && req->callback) 453 if (!EIO_CANCELLED (req) && req->callback)
445 SvREADONLY_on (sv_result); 474 SvREADONLY_on (sv_result);
446 } 475 }
447 476
448 switch (req->type) 477 switch (req->type)
449 { 478 {
479 case EIO_WD_OPEN:
480 PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd)));
481 break;
482
450 case EIO_READDIR: 483 case EIO_READDIR:
451 { 484 {
452 SV *rv = &PL_sv_undef; 485 SV *rv = &PL_sv_undef;
453 486
454 if (req->result >= 0) 487 if (req->result >= 0)
596 break; 629 break;
597 630
598 case EIO_STAT: 631 case EIO_STAT:
599 case EIO_LSTAT: 632 case EIO_LSTAT:
600 case EIO_FSTAT: 633 case EIO_FSTAT:
601 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 634 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
635
602 PL_laststatval = req->result; 636 if (!(PL_laststatval = req->result))
603 /* 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 */
604 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 638 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
639
605 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)));
606 break; 645 break;
607 646
608 case EIO_READ: 647 case EIO_READ:
609 { 648 {
610 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));
643 } 682 }
644 683
645 return !!SvTRUE (ERRSV); 684 return !!SvTRUE (ERRSV);
646} 685}
647 686
687static void
648static void req_destroy (aio_req req) 688req_destroy (aio_req req)
649{ 689{
650 if (req->self) 690 if (req->self)
651 { 691 {
652 sv_unmagic (req->self, PERL_MAGIC_ext); 692 sv_unmagic (req->self, PERL_MAGIC_ext);
653 SvREFCNT_dec (req->self); 693 SvREFCNT_dec (req->self);
654 } 694 }
655 695
656 SvREFCNT_dec (req->sv1); 696 SvREFCNT_dec (req->sv1);
657 SvREFCNT_dec (req->sv2); 697 SvREFCNT_dec (req->sv2);
698 SvREFCNT_dec (req->sv3);
699 SvREFCNT_dec (req->sv4);
658 SvREFCNT_dec (req->callback); 700 SvREFCNT_dec (req->callback);
659 701
660 Safefree (req); 702 free (req);
661} 703}
662 704
705static void
663static void req_cancel_subs (aio_req grp) 706req_cancel_subs (aio_req grp)
664{ 707{
665 if (grp->type != EIO_GROUP) 708 if (grp->type != EIO_GROUP)
666 return; 709 return;
667 710
668 SvREFCNT_dec (grp->sv2); 711 SvREFCNT_dec (grp->sv2);
669 grp->sv2 = 0; 712 grp->sv2 = 0;
670 713
671 eio_grp_cancel (grp); 714 eio_grp_cancel (grp);
672} 715}
673 716
717static void ecb_cold
674static void create_respipe (void) 718create_respipe (void)
675{ 719{
676 if (s_epipe_renew (&respipe)) 720 if (s_epipe_renew (&respipe))
677 croak ("IO::AIO: unable to initialize result pipe"); 721 croak ("IO::AIO: unable to initialize result pipe");
678} 722}
679 723
680static void poll_wait (void) 724static void
725poll_wait (void)
681{ 726{
682 while (eio_nreqs ()) 727 while (eio_nreqs ())
683 { 728 {
684 int size; 729 int size;
685 730
694 739
695 s_epipe_wait (&respipe); 740 s_epipe_wait (&respipe);
696 } 741 }
697} 742}
698 743
699static int poll_cb (void) 744static int
745poll_cb (void)
700{ 746{
701 for (;;) 747 for (;;)
702 { 748 {
703 int res = eio_poll (); 749 int res = eio_poll ();
704 750
710 756
711 poll_wait (); 757 poll_wait ();
712 } 758 }
713} 759}
714 760
715static void atfork_child (void) 761static void ecb_cold
762reinit (void)
716{ 763{
717 create_respipe (); 764 create_respipe ();
765
766 if (eio_init (want_poll, done_poll) < 0)
767 croak ("IO::AIO: unable to initialise eio library");
718} 768}
719 769
720/*****************************************************************************/ 770/*****************************************************************************/
721 771
722#if !_POSIX_MAPPED_FILES 772#if !_POSIX_MAPPED_FILES
733# define MAP_FIXED 0 783# define MAP_FIXED 0
734#endif 784#endif
735 785
736#define MMAP_MAGIC PERL_MAGIC_ext 786#define MMAP_MAGIC PERL_MAGIC_ext
737 787
788static int ecb_cold
738static int mmap_free (pTHX_ SV *sv, MAGIC *mg) 789mmap_free (pTHX_ SV *sv, MAGIC *mg)
739{ 790{
740 int old_errno = errno; 791 int old_errno = errno;
741 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 792 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
742 errno = old_errno; 793 errno = old_errno;
743 794
759 0, 0, 0, 0, mmap_free 810 0, 0, 0, 0, mmap_free
760}; 811};
761 812
762/*****************************************************************************/ 813/*****************************************************************************/
763 814
815static SV *
764static SV * get_cb (SV *cb_sv) 816get_cb (SV *cb_sv)
765{ 817{
766 SvGETMAGIC (cb_sv); 818 SvGETMAGIC (cb_sv);
767 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 819 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
768} 820}
769 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
770#define dREQ \ 842#define dREQ \
771 SV *cb_cv; \ 843 aio_req req = dreq (callback); \
772 aio_req req; \
773 int req_pri = next_pri; \
774 next_pri = EIO_PRI_DEFAULT; \
775 \
776 cb_cv = get_cb (callback); \
777 \
778 Newz (0, req, 1, eio_req); \
779 if (!req) \
780 croak ("out of memory during eio_req allocation"); \
781 \
782 req->callback = SvREFCNT_inc (cb_cv); \
783 req->pri = req_pri
784 844
785#define REQ_SEND \ 845#define REQ_SEND \
786 PUTBACK; \ 846 PUTBACK; \
787 req_submit (req); \ 847 req_submit (req); \
788 SPAGAIN; \ 848 SPAGAIN; \
789 \ 849 \
790 if (GIMME_V != G_VOID) \ 850 if (GIMME_V != G_VOID) \
791 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;
792 918
793MODULE = IO::AIO PACKAGE = IO::AIO 919MODULE = IO::AIO PACKAGE = IO::AIO
794 920
795PROTOTYPES: ENABLE 921PROTOTYPES: ENABLE
796 922
880 const_iv (MAP_LOCKED) 1006 const_iv (MAP_LOCKED)
881 const_iv (MAP_NORESERVE) 1007 const_iv (MAP_NORESERVE)
882 const_iv (MAP_POPULATE) 1008 const_iv (MAP_POPULATE)
883 const_iv (MAP_NONBLOCK) 1009 const_iv (MAP_NONBLOCK)
884 1010
1011 const_eio (SEEK_SET)
1012 const_eio (SEEK_CUR)
1013 const_eio (SEEK_END)
1014
885 const_eio (MCL_FUTURE) 1015 const_eio (MCL_FUTURE)
886 const_eio (MCL_CURRENT) 1016 const_eio (MCL_CURRENT)
887 1017
888 const_eio (MS_ASYNC) 1018 const_eio (MS_ASYNC)
889 const_eio (MS_INVALIDATE) 1019 const_eio (MS_INVALIDATE)
914 }; 1044 };
915 1045
916 aio_stash = gv_stashpv ("IO::AIO" , 1); 1046 aio_stash = gv_stashpv ("IO::AIO" , 1);
917 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); 1047 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1);
918 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);
919 1050
920 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--)
921 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); 1052 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
922 1053
923 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 1054 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
924 1055
925 create_respipe (); 1056 reinit ();
926
927 if (eio_init (want_poll, done_poll) < 0)
928 croak ("IO::AIO: unable to initialise eio library");
929
930 /* atfork child called in fifo order, so before eio's handler */
931 X_THREAD_ATFORK (0, 0, atfork_child);
932} 1057}
1058
1059void
1060reinit ()
1061 PROTOTYPE:
933 1062
934void 1063void
935max_poll_reqs (unsigned int nreqs) 1064max_poll_reqs (unsigned int nreqs)
936 PROTOTYPE: $ 1065 PROTOTYPE: $
937 CODE: 1066 CODE:
972 PROTOTYPE: $ 1101 PROTOTYPE: $
973 CODE: 1102 CODE:
974 max_outstanding = maxreqs; 1103 max_outstanding = maxreqs;
975 1104
976void 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
977aio_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)
978 PPCODE: 1119 PPCODE:
979{ 1120{
980 dREQ; 1121 dREQ;
981 1122
982 req->type = EIO_OPEN; 1123 req->type = EIO_OPEN;
983 req->sv1 = newSVsv (pathname); 1124 req_set_path1 (req, pathname);
984 req->ptr1 = SvPVbyte_nolen (req->sv1);
985 req->int1 = flags; 1125 req->int1 = flags;
986 req->int2 = mode; 1126 req->int2 = mode;
987 1127
988 REQ_SEND; 1128 REQ_SEND;
989} 1129}
991void 1131void
992aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 1132aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
993 ALIAS: 1133 ALIAS:
994 aio_fsync = EIO_FSYNC 1134 aio_fsync = EIO_FSYNC
995 aio_fdatasync = EIO_FDATASYNC 1135 aio_fdatasync = EIO_FDATASYNC
1136 aio_syncfs = EIO_SYNCFS
996 PPCODE: 1137 PPCODE:
997{ 1138{
998 int fd = s_fileno_croak (fh, 0); 1139 int fd = s_fileno_croak (fh, 0);
999 dREQ; 1140 dREQ;
1000 1141
1001 req->type = ix; 1142 req->type = ix;
1002 req->sv1 = newSVsv (fh); 1143 req->sv1 = newSVsv (fh);
1003 req->int1 = fd; 1144 req->int1 = fd;
1004 1145
1005 REQ_SEND (req); 1146 REQ_SEND;
1006} 1147}
1007 1148
1008void 1149void
1009aio_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)
1010 PPCODE: 1151 PPCODE:
1017 req->int1 = fd; 1158 req->int1 = fd;
1018 req->offs = offset; 1159 req->offs = offset;
1019 req->size = nbytes; 1160 req->size = nbytes;
1020 req->int2 = flags; 1161 req->int2 = flags;
1021 1162
1022 REQ_SEND (req); 1163 REQ_SEND;
1023} 1164}
1024 1165
1025void 1166void
1026aio_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)
1027 PPCODE: 1168 PPCODE:
1034 req->int1 = fd; 1175 req->int1 = fd;
1035 req->int2 = mode; 1176 req->int2 = mode;
1036 req->offs = offset; 1177 req->offs = offset;
1037 req->size = len; 1178 req->size = len;
1038 1179
1039 REQ_SEND (req); 1180 REQ_SEND;
1040} 1181}
1041 1182
1042void 1183void
1043aio_close (SV *fh, SV *callback=&PL_sv_undef) 1184aio_close (SV *fh, SV *callback=&PL_sv_undef)
1044 PPCODE: 1185 PPCODE:
1068 req->type = EIO_DUP2; 1209 req->type = EIO_DUP2;
1069 req->int1 = close_fd; 1210 req->int1 = close_fd;
1070 req->sv2 = newSVsv (fh); 1211 req->sv2 = newSVsv (fh);
1071 req->int2 = fd; 1212 req->int2 = fd;
1072 1213
1073 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;
1074} 1232}
1075 1233
1076void 1234void
1077aio_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)
1078 ALIAS: 1236 ALIAS:
1125 REQ_SEND; 1283 REQ_SEND;
1126 } 1284 }
1127} 1285}
1128 1286
1129void 1287void
1130aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1288aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1131 ALIAS: 1289 ALIAS:
1132 aio_readlink = EIO_READLINK 1290 aio_readlink = EIO_READLINK
1133 aio_realpath = EIO_REALPATH 1291 aio_realpath = EIO_REALPATH
1134 PPCODE: 1292 PPCODE:
1135{ 1293{
1136 dREQ; 1294 dREQ;
1137 1295
1138 req->type = ix; 1296 req->type = ix;
1139 req->sv1 = newSVsv (path); 1297 req_set_path1 (req, pathname);
1140 req->ptr1 = SvPVbyte_nolen (req->sv1);
1141 1298
1142 REQ_SEND; 1299 REQ_SEND;
1143} 1300}
1144 1301
1145void 1302void
1185 aio_statvfs = EIO_STATVFS 1342 aio_statvfs = EIO_STATVFS
1186 PPCODE: 1343 PPCODE:
1187{ 1344{
1188 dREQ; 1345 dREQ;
1189 1346
1190 req->sv1 = newSVsv (fh_or_path); 1347 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1191
1192 if (SvPOK (req->sv1))
1193 {
1194 req->type = ix;
1195 req->ptr1 = SvPVbyte_nolen (req->sv1);
1196 }
1197 else
1198 {
1199 req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT;
1200 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1201 }
1202 1348
1203 REQ_SEND; 1349 REQ_SEND;
1204} 1350}
1205 1351
1206UV 1352UV
1225{ 1371{
1226 dREQ; 1372 dREQ;
1227 1373
1228 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; 1374 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.;
1229 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; 1375 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.;
1230 req->sv1 = newSVsv (fh_or_path); 1376 req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path);
1231
1232 if (SvPOK (req->sv1))
1233 {
1234 req->type = EIO_UTIME;
1235 req->ptr1 = SvPVbyte_nolen (req->sv1);
1236 }
1237 else
1238 {
1239 req->type = EIO_FUTIME;
1240 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1241 }
1242 1377
1243 REQ_SEND; 1378 REQ_SEND;
1244} 1379}
1245 1380
1246void 1381void
1247aio_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)
1248 PPCODE: 1383 PPCODE:
1249{ 1384{
1250 dREQ; 1385 dREQ;
1251 1386
1252 req->sv1 = newSVsv (fh_or_path);
1253 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 1387 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1254 1388 req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path);
1255 if (SvPOK (req->sv1))
1256 {
1257 req->type = EIO_TRUNCATE;
1258 req->ptr1 = SvPVbyte_nolen (req->sv1);
1259 }
1260 else
1261 {
1262 req->type = EIO_FTRUNCATE;
1263 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1264 }
1265 1389
1266 REQ_SEND; 1390 REQ_SEND;
1267} 1391}
1268 1392
1269void 1393void
1270aio_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)
1271 ALIAS:
1272 aio_chmod = EIO_CHMOD
1273 aio_mkdir = EIO_MKDIR
1274 PPCODE: 1395 PPCODE:
1275{ 1396{
1276 dREQ; 1397 dREQ;
1277 1398
1278 req->int2 = mode; 1399 req->int2 = mode;
1279 req->sv1 = newSVsv (fh_or_path); 1400 req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path);
1280
1281 if (SvPOK (req->sv1))
1282 {
1283 req->type = ix;
1284 req->ptr1 = SvPVbyte_nolen (req->sv1);
1285 }
1286 else
1287 {
1288 req->type = EIO_FCHMOD;
1289 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1290 }
1291 1401
1292 REQ_SEND; 1402 REQ_SEND;
1293} 1403}
1294 1404
1295void 1405void
1298{ 1408{
1299 dREQ; 1409 dREQ;
1300 1410
1301 req->int2 = SvOK (uid) ? SvIV (uid) : -1; 1411 req->int2 = SvOK (uid) ? SvIV (uid) : -1;
1302 req->int3 = SvOK (gid) ? SvIV (gid) : -1; 1412 req->int3 = SvOK (gid) ? SvIV (gid) : -1;
1303 req->sv1 = newSVsv (fh_or_path); 1413 req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path);
1304
1305 if (SvPOK (req->sv1))
1306 {
1307 req->type = EIO_CHOWN;
1308 req->ptr1 = SvPVbyte_nolen (req->sv1);
1309 }
1310 else
1311 {
1312 req->type = EIO_FCHOWN;
1313 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1314 }
1315 1414
1316 REQ_SEND; 1415 REQ_SEND;
1317} 1416}
1318 1417
1319void 1418void
1321 PPCODE: 1420 PPCODE:
1322{ 1421{
1323 dREQ; 1422 dREQ;
1324 1423
1325 req->type = EIO_READDIR; 1424 req->type = EIO_READDIR;
1326 req->sv1 = newSVsv (pathname);
1327 req->ptr1 = SvPVbyte_nolen (req->sv1);
1328 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; 1425 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1;
1329 1426
1330 if (flags & EIO_READDIR_DENTS) 1427 if (flags & EIO_READDIR_DENTS)
1331 req->int1 |= EIO_READDIR_CUSTOM2; 1428 req->int1 |= EIO_READDIR_CUSTOM2;
1332 1429
1430 req_set_path1 (req, pathname);
1431
1333 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;
1334} 1446}
1335 1447
1336void 1448void
1337aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) 1449aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1338 ALIAS: 1450 ALIAS:
1342 PPCODE: 1454 PPCODE:
1343{ 1455{
1344 dREQ; 1456 dREQ;
1345 1457
1346 req->type = ix; 1458 req->type = ix;
1347 req->sv1 = newSVsv (pathname); 1459 req_set_path1 (req, pathname);
1348 req->ptr1 = SvPVbyte_nolen (req->sv1);
1349 1460
1350 REQ_SEND; 1461 REQ_SEND;
1351} 1462}
1352 1463
1353void 1464void
1356 aio_link = EIO_LINK 1467 aio_link = EIO_LINK
1357 aio_symlink = EIO_SYMLINK 1468 aio_symlink = EIO_SYMLINK
1358 aio_rename = EIO_RENAME 1469 aio_rename = EIO_RENAME
1359 PPCODE: 1470 PPCODE:
1360{ 1471{
1472 eio_wd wd2 = 0;
1361 dREQ; 1473 dREQ;
1362 1474
1363 req->type = ix; 1475 req->type = ix;
1364 req->sv1 = newSVsv (oldpath); 1476 req_set_path1 (req, oldpath);
1365 req->ptr1 = SvPVbyte_nolen (req->sv1); 1477 req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2);
1366 req->sv2 = newSVsv (newpath); 1478 req->int3 = (long)wd2;
1367 req->ptr2 = SvPVbyte_nolen (req->sv2);
1368 1479
1369 REQ_SEND; 1480 REQ_SEND;
1370} 1481}
1371 1482
1372void 1483void
1374 PPCODE: 1485 PPCODE:
1375{ 1486{
1376 dREQ; 1487 dREQ;
1377 1488
1378 req->type = EIO_MKNOD; 1489 req->type = EIO_MKNOD;
1379 req->sv1 = newSVsv (pathname);
1380 req->ptr1 = SvPVbyte_nolen (req->sv1);
1381 req->int2 = (mode_t)mode; 1490 req->int2 = (mode_t)mode;
1382 req->offs = dev; 1491 req->offs = dev;
1492 req_set_path1 (req, pathname);
1383 1493
1384 REQ_SEND; 1494 REQ_SEND;
1385} 1495}
1386 1496
1387void 1497void
1587 CODE: 1697 CODE:
1588 RETVAL = posix_fadvise (fh, offset, length, advice); 1698 RETVAL = posix_fadvise (fh, offset, length, advice);
1589 OUTPUT: 1699 OUTPUT:
1590 RETVAL 1700 RETVAL
1591 1701
1592ssize_t 1702IV
1593sendfile (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)
1594 CODE: 1704 CODE:
1595 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1705 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1596 OUTPUT: 1706 OUTPUT:
1597 RETVAL 1707 RETVAL
1709 SvREFCNT_dec (on_next_submit); 1819 SvREFCNT_dec (on_next_submit);
1710 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1820 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1711 1821
1712PROTOTYPES: DISABLE 1822PROTOTYPES: DISABLE
1713 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
1714MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1852MODULE = IO::AIO PACKAGE = IO::AIO::REQ
1715 1853
1716void 1854void
1717cancel (aio_req_ornot req) 1855cancel (aio_req_ornot req)
1718 CODE: 1856 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines