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.187 by root, Sat Jul 16 16:46:10 2011 UTC vs.
Revision 1.207 by root, Fri Dec 30 07:40:54 2011 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
36# undef malloc
37# undef free
38
39// perl overrides all those nice win32 functions 35 // perl overrides all those nice libc functions
36
37 #undef malloc
38 #undef free
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
44 #undef stat
45# undef lstat 45 #undef lstat
46 #undef fstat
46# undef truncate 47 #undef truncate
47# undef ftruncate 48 #undef ftruncate
48# undef open 49 #undef open
49# undef link 50 #undef link
50# undef close 51 #undef close
51# undef unlink 52 #undef unlink
52# undef mkdir 53 #undef mkdir
53# undef rmdir 54 #undef rmdir
54# undef rename 55 #undef rename
55# undef lseek 56 #undef lseek
56# undef opendir 57 #undef opendir
57# undef readdir 58 #undef readdir
58# undef closedir 59 #undef closedir
59# undef chmod 60 #undef chmod
60# undef fchmod 61 #undef fchmod
61 62 #undef dup
62# define opendir(fd) EIO_ERRNO (ENOSYS, 0) 63 #undef dup2
63# define readdir(fd) EIO_ENOSYS () 64 #undef abort
64# define closedir(fd) EIO_ENOSYS () 65 #undef pipe
65 66
66#else 67#else
67 68
68# include <sys/time.h> 69 #include <sys/time.h>
69# include <sys/select.h> 70 #include <sys/select.h>
70# include <unistd.h> 71 #include <unistd.h>
71# include <utime.h> 72 #include <utime.h>
72# include <signal.h> 73 #include <signal.h>
73 74
74#endif 75#endif
75 76
76#define EIO_STRUCT_STAT Stat_t 77#define EIO_STRUCT_STAT Stat_t
77 78
101 102
102typedef SV SV8; /* byte-sv, used for argument-checking */ 103typedef SV SV8; /* byte-sv, used for argument-checking */
103typedef int aio_rfd; /* read file desriptor */ 104typedef int aio_rfd; /* read file desriptor */
104typedef int aio_wfd; /* write file descriptor */ 105typedef int aio_wfd; /* write file descriptor */
105 106
106static HV *aio_stash, *aio_req_stash, *aio_grp_stash; 107static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash;
107 108
108#define EIO_REQ_MEMBERS \ 109#define EIO_REQ_MEMBERS \
109 SV *callback; \ 110 SV *callback; \
110 SV *sv1, *sv2; \ 111 SV *sv1, *sv2; \
112 SV *sv3, *sv4; \
111 STRLEN stroffset; \ 113 STRLEN stroffset; \
112 SV *self; 114 SV *self;
113 115
114#define EIO_NO_WRAPPERS 1 116#define EIO_NO_WRAPPERS 1
115 117
116#include "libeio/config.h" 118#include "libeio/config.h"
117#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"
118 127
119/* Linux/others */ 128/* Linux/others */
120#ifndef O_ASYNC 129#ifndef O_ASYNC
121# define O_ASYNC 0 130# define O_ASYNC 0
122#endif 131#endif
315 324
316#ifndef PAGESIZE 325#ifndef PAGESIZE
317# define PAGESIZE sysconf (_SC_PAGESIZE) 326# define PAGESIZE sysconf (_SC_PAGESIZE)
318#endif 327#endif
319 328
320static int req_invoke (eio_req *req);
321#define EIO_FINISH(req) req_invoke (req)
322static void req_destroy (eio_req *grp);
323#define EIO_DESTROY(req) req_destroy (req)
324
325enum { 329enum {
326 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 330 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
327}; 331};
328 332
329#include "libeio/eio.c"
330
331typedef eio_req *aio_req; 333typedef eio_req *aio_req;
332typedef eio_req *aio_req_ornot; 334typedef eio_req *aio_req_ornot;
335typedef eio_wd aio_wd;
333 336
334static SV *on_next_submit; 337static SV *on_next_submit;
335static int next_pri = EIO_PRI_DEFAULT; 338static int next_pri = EIO_PRI_DEFAULT;
336static int max_outstanding; 339static int max_outstanding;
337 340
338static s_epipe respipe; 341static s_epipe respipe;
339 342
340static void req_destroy (aio_req req); 343static void req_destroy (aio_req req);
341static void req_cancel (aio_req req); 344static void req_cancel (aio_req req);
342 345
343static void want_poll (void) 346static void
347want_poll (void)
344{ 348{
345 /* write a dummy byte to the pipe so fh becomes ready */ 349 /* write a dummy byte to the pipe so fh becomes ready */
346 s_epipe_signal (&respipe); 350 s_epipe_signal (&respipe);
347} 351}
348 352
349static void done_poll (void) 353static void
354done_poll (void)
350{ 355{
351 /* read any signals sent by the worker threads */ 356 /* read any signals sent by the worker threads */
352 s_epipe_drain (&respipe); 357 s_epipe_drain (&respipe);
353} 358}
354 359
355/* must be called at most once */ 360/* must be called at most once */
361static SV *
356static SV *req_sv (aio_req req, HV *stash) 362req_sv (aio_req req, HV *stash)
357{ 363{
358 if (!req->self) 364 if (!req->self)
359 { 365 {
360 req->self = (SV *)newHV (); 366 req->self = (SV *)newHV ();
361 sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); 367 sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0);
362 } 368 }
363 369
364 return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); 370 return sv_2mortal (sv_bless (newRV_inc (req->self), stash));
365} 371}
366 372
367static aio_req SvAIO_REQ (SV *sv) 373static SV *
374newSVaio_wd (aio_wd wd)
375{
376 return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash);
377}
378
379static aio_req
380SvAIO_REQ (SV *sv)
368{ 381{
369 MAGIC *mg; 382 MAGIC *mg;
370 383
371 if (!SvROK (sv) 384 if (!SvROK (sv)
385 /* for speed reasons, we do not verify that SvROK actually has a stash ptr */
372 || (SvSTASH (SvRV (sv)) != aio_grp_stash 386 || (SvSTASH (SvRV (sv)) != aio_grp_stash
373 && SvSTASH (SvRV (sv)) != aio_req_stash 387 && SvSTASH (SvRV (sv)) != aio_req_stash
374 && !sv_derived_from (sv, "IO::AIO::REQ"))) 388 && !sv_derived_from (sv, "IO::AIO::REQ")))
375 croak ("object of class IO::AIO::REQ expected"); 389 croak ("object of class IO::AIO::REQ expected");
376 390
377 mg = mg_find (SvRV (sv), PERL_MAGIC_ext); 391 mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
378 392
379 return mg ? (aio_req)mg->mg_ptr : 0; 393 return mg ? (aio_req)mg->mg_ptr : 0;
380} 394}
381 395
396static aio_wd
397SvAIO_WD (SV *sv)
398{
399 if (!SvROK (sv)
400 || SvTYPE (SvRV (sv)) != SVt_PVMG
401 || SvSTASH (SvRV (sv)) != aio_wd_stash)
402 croak ("IO::AIO: expected a working directory object as returned by aio_wd");
403
404 return (aio_wd)(long)SvIVX (SvRV (sv));
405}
406
407static void
382static void aio_grp_feed (aio_req grp) 408aio_grp_feed (aio_req grp)
383{ 409{
384 if (grp->sv2 && SvOK (grp->sv2)) 410 if (grp->sv2 && SvOK (grp->sv2))
385 { 411 {
386 dSP; 412 dSP;
387 413
395 FREETMPS; 421 FREETMPS;
396 LEAVE; 422 LEAVE;
397 } 423 }
398} 424}
399 425
426static void
400static void req_submit (eio_req *req) 427req_submit (eio_req *req)
401{ 428{
402 eio_submit (req); 429 eio_submit (req);
403 430
404 if (expect_false (on_next_submit)) 431 if (expect_false (on_next_submit))
405 { 432 {
412 PUTBACK; 439 PUTBACK;
413 call_sv (cb, G_DISCARD | G_EVAL); 440 call_sv (cb, G_DISCARD | G_EVAL);
414 } 441 }
415} 442}
416 443
444static int
417static int req_invoke (eio_req *req) 445req_invoke (eio_req *req)
418{ 446{
419 if (req->flags & FLAG_SV2_RO_OFF) 447 if (req->flags & FLAG_SV2_RO_OFF)
420 SvREADONLY_off (req->sv2); 448 SvREADONLY_off (req->sv2);
421 449
422 if (!EIO_CANCELLED (req) && req->callback) 450 if (!EIO_CANCELLED (req) && req->callback)
443 SvREADONLY_on (sv_result); 471 SvREADONLY_on (sv_result);
444 } 472 }
445 473
446 switch (req->type) 474 switch (req->type)
447 { 475 {
476 case EIO_WD_OPEN:
477 PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd)));
478 break;
479
448 case EIO_READDIR: 480 case EIO_READDIR:
449 { 481 {
450 SV *rv = &PL_sv_undef; 482 SV *rv = &PL_sv_undef;
451 483
452 if (req->result >= 0) 484 if (req->result >= 0)
594 break; 626 break;
595 627
596 case EIO_STAT: 628 case EIO_STAT:
597 case EIO_LSTAT: 629 case EIO_LSTAT:
598 case EIO_FSTAT: 630 case EIO_FSTAT:
599 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 631 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
632
600 PL_laststatval = req->result; 633 if (!(PL_laststatval = req->result))
634 /* if compilation fails here then perl's Stat_t is not struct _stati64 */
601 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 635 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
636
602 PUSHs (sv_result); 637 PUSHs (sv_result);
603 break; 638 break;
604 639
605 case EIO_READ: 640 case EIO_READ:
606 { 641 {
640 } 675 }
641 676
642 return !!SvTRUE (ERRSV); 677 return !!SvTRUE (ERRSV);
643} 678}
644 679
680static void
645static void req_destroy (aio_req req) 681req_destroy (aio_req req)
646{ 682{
647 if (req->self) 683 if (req->self)
648 { 684 {
649 sv_unmagic (req->self, PERL_MAGIC_ext); 685 sv_unmagic (req->self, PERL_MAGIC_ext);
650 SvREFCNT_dec (req->self); 686 SvREFCNT_dec (req->self);
651 } 687 }
652 688
653 SvREFCNT_dec (req->sv1); 689 SvREFCNT_dec (req->sv1);
654 SvREFCNT_dec (req->sv2); 690 SvREFCNT_dec (req->sv2);
691 SvREFCNT_dec (req->sv3);
692 SvREFCNT_dec (req->sv4);
655 SvREFCNT_dec (req->callback); 693 SvREFCNT_dec (req->callback);
656 694
657 Safefree (req); 695 free (req);
658} 696}
659 697
698static void
660static void req_cancel_subs (aio_req grp) 699req_cancel_subs (aio_req grp)
661{ 700{
662 aio_req sub;
663
664 if (grp->type != EIO_GROUP) 701 if (grp->type != EIO_GROUP)
665 return; 702 return;
666 703
667 SvREFCNT_dec (grp->sv2); 704 SvREFCNT_dec (grp->sv2);
668 grp->sv2 = 0; 705 grp->sv2 = 0;
669 706
670 eio_grp_cancel (grp); 707 eio_grp_cancel (grp);
671} 708}
672 709
710static void ecb_cold
673static void create_respipe (void) 711create_respipe (void)
674{ 712{
675 if (s_epipe_renew (&respipe)) 713 if (s_epipe_renew (&respipe))
676 croak ("IO::AIO: unable to initialize result pipe"); 714 croak ("IO::AIO: unable to initialize result pipe");
677} 715}
678 716
679static void poll_wait (void) 717static void
718poll_wait (void)
680{ 719{
681 while (eio_nreqs ()) 720 while (eio_nreqs ())
682 { 721 {
683 int size; 722 int size;
684 723
693 732
694 s_epipe_wait (&respipe); 733 s_epipe_wait (&respipe);
695 } 734 }
696} 735}
697 736
698static int poll_cb (void) 737static int
738poll_cb (void)
699{ 739{
700 for (;;) 740 for (;;)
701 { 741 {
702 int res = eio_poll (); 742 int res = eio_poll ();
703 743
709 749
710 poll_wait (); 750 poll_wait ();
711 } 751 }
712} 752}
713 753
714static void atfork_child (void) 754static void ecb_cold
755reinit (void)
715{ 756{
716 create_respipe (); 757 create_respipe ();
758
759 if (eio_init (want_poll, done_poll) < 0)
760 croak ("IO::AIO: unable to initialise eio library");
717} 761}
718 762
719/*****************************************************************************/ 763/*****************************************************************************/
720 764
721#if !_POSIX_MAPPED_FILES 765#if !_POSIX_MAPPED_FILES
732# define MAP_FIXED 0 776# define MAP_FIXED 0
733#endif 777#endif
734 778
735#define MMAP_MAGIC PERL_MAGIC_ext 779#define MMAP_MAGIC PERL_MAGIC_ext
736 780
781static int ecb_cold
737static int mmap_free (pTHX_ SV *sv, MAGIC *mg) 782mmap_free (pTHX_ SV *sv, MAGIC *mg)
738{ 783{
739 int old_errno = errno; 784 int old_errno = errno;
740 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 785 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
741 errno = old_errno; 786 errno = old_errno;
742 787
758 0, 0, 0, 0, mmap_free 803 0, 0, 0, 0, mmap_free
759}; 804};
760 805
761/*****************************************************************************/ 806/*****************************************************************************/
762 807
808static SV *
763static SV * get_cb (SV *cb_sv) 809get_cb (SV *cb_sv)
764{ 810{
765 SvGETMAGIC (cb_sv); 811 SvGETMAGIC (cb_sv);
766 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 812 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
767} 813}
768 814
815static aio_req ecb_noinline
816dreq (SV *callback)
817{
818 SV *cb_cv;
819 aio_req req;
820 int req_pri = next_pri;
821 next_pri = EIO_PRI_DEFAULT;
822
823 cb_cv = get_cb (callback);
824
825 req = calloc (sizeof (*req), 1);
826 if (!req)
827 croak ("out of memory during eio_req allocation");
828
829 req->callback = SvREFCNT_inc (cb_cv);
830 req->pri = req_pri;
831
832 return req;
833}
834
769#define dREQ \ 835#define dREQ \
770 SV *cb_cv; \ 836 aio_req req = dreq (callback); \
771 aio_req req; \
772 int req_pri = next_pri; \
773 next_pri = EIO_PRI_DEFAULT; \
774 \
775 cb_cv = get_cb (callback); \
776 \
777 Newz (0, req, 1, eio_req); \
778 if (!req) \
779 croak ("out of memory during eio_req allocation"); \
780 \
781 req->callback = SvREFCNT_inc (cb_cv); \
782 req->pri = req_pri
783 837
784#define REQ_SEND \ 838#define REQ_SEND \
785 PUTBACK; \ 839 PUTBACK; \
786 req_submit (req); \ 840 req_submit (req); \
787 SPAGAIN; \ 841 SPAGAIN; \
788 \ 842 \
789 if (GIMME_V != G_VOID) \ 843 if (GIMME_V != G_VOID) \
790 XPUSHs (req_sv (req, aio_req_stash)); 844 XPUSHs (req_sv (req, aio_req_stash));
845
846ecb_inline void
847req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr)
848{
849 if (expect_false (SvROK (path)))
850 {
851 SV *rv = SvRV (path);
852 SV *wdob;
853
854 if (SvTYPE (rv) == SVt_PVAV && AvFILLp (rv) == 1)
855 {
856 path = AvARRAY (rv)[1];
857 wdob = AvARRAY (rv)[0];
858
859 if (SvOK (wdob))
860 {
861 *wd = SvAIO_WD (wdob);
862 *wdsv = SvREFCNT_inc_NN (SvRV (wdob));
863 }
864 else
865 *wd = EIO_INVALID_WD;
866 }
867 else if (SvTYPE (rv) == SVt_PVMG && SvSTASH (rv) == aio_wd_stash)
868 {
869 *wd = (aio_wd)(long)SvIVX (rv);
870 *wdsv = SvREFCNT_inc_NN (rv);
871 *ptr = ".";
872 return; /* path set to "." */
873 }
874 else
875 croak ("IO::AIO: pathname arguments must be specified as a string, an IO::AIO::WD object or a [IO::AIO::WD, path] pair");
876 }
877
878 *pathsv = newSVsv (path);
879 *ptr = SvPVbyte_nolen (*pathsv);
880}
881
882static void ecb_noinline
883req_set_path1 (aio_req req, SV *path)
884{
885 req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1);
886}
887
888static void ecb_noinline
889req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path)
890{
891 SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path;
892
893 switch (SvTYPE (rv))
894 {
895 case SVt_PVIO:
896 case SVt_PVLV:
897 case SVt_PVGV:
898 req->type = type_fh;
899 req->sv1 = newSVsv (fh_or_path);
900 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
901 break;
902
903 default:
904 req->type = type_path;
905 req_set_path1 (req, fh_or_path);
906 break;
907 }
908}
909
910XS(boot_IO__AIO) ecb_cold;
791 911
792MODULE = IO::AIO PACKAGE = IO::AIO 912MODULE = IO::AIO PACKAGE = IO::AIO
793 913
794PROTOTYPES: ENABLE 914PROTOTYPES: ENABLE
795 915
913 }; 1033 };
914 1034
915 aio_stash = gv_stashpv ("IO::AIO" , 1); 1035 aio_stash = gv_stashpv ("IO::AIO" , 1);
916 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); 1036 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1);
917 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); 1037 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1);
1038 aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1);
918 1039
919 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1040 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)); 1041 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
921 1042
922 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 1043 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
923 1044
924 create_respipe (); 1045 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} 1046}
1047
1048void
1049reinit ()
1050 PROTOTYPE:
932 1051
933void 1052void
934max_poll_reqs (unsigned int nreqs) 1053max_poll_reqs (unsigned int nreqs)
935 PROTOTYPE: $ 1054 PROTOTYPE: $
936 CODE: 1055 CODE:
971 PROTOTYPE: $ 1090 PROTOTYPE: $
972 CODE: 1091 CODE:
973 max_outstanding = maxreqs; 1092 max_outstanding = maxreqs;
974 1093
975void 1094void
1095aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef)
1096 PPCODE:
1097{
1098 dREQ;
1099
1100 req->type = EIO_WD_OPEN;
1101 req_set_path1 (req, pathname);
1102
1103 REQ_SEND;
1104}
1105
1106void
976aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 1107aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
977 PPCODE: 1108 PPCODE:
978{ 1109{
979 dREQ; 1110 dREQ;
980 1111
981 req->type = EIO_OPEN; 1112 req->type = EIO_OPEN;
982 req->sv1 = newSVsv (pathname); 1113 req_set_path1 (req, pathname);
983 req->ptr1 = SvPVbyte_nolen (req->sv1);
984 req->int1 = flags; 1114 req->int1 = flags;
985 req->int2 = mode; 1115 req->int2 = mode;
986 1116
987 REQ_SEND; 1117 REQ_SEND;
988} 1118}
990void 1120void
991aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 1121aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
992 ALIAS: 1122 ALIAS:
993 aio_fsync = EIO_FSYNC 1123 aio_fsync = EIO_FSYNC
994 aio_fdatasync = EIO_FDATASYNC 1124 aio_fdatasync = EIO_FDATASYNC
1125 aio_syncfs = EIO_SYNCFS
995 PPCODE: 1126 PPCODE:
996{ 1127{
997 int fd = s_fileno_croak (fh, 0); 1128 int fd = s_fileno_croak (fh, 0);
998 dREQ; 1129 dREQ;
999 1130
1046 int fd = s_fileno_croak (fh, 0); 1177 int fd = s_fileno_croak (fh, 0);
1047 dREQ; 1178 dREQ;
1048 1179
1049 if (expect_false (close_fd < 0)) 1180 if (expect_false (close_fd < 0))
1050 { 1181 {
1182 int pipefd [2];
1183
1184 if (
1051#ifdef _WIN32 1185#ifdef _WIN32
1052 close_fd = _open_osfhandle (socket (AF_INET, SOCK_STREAM, 0), 0); 1186 _pipe (pipefd, 1, _O_BINARY) < 0
1053#else 1187#else
1054 int pipefd [2];
1055
1056 if (pipe (pipefd) < 0 1188 pipe (pipefd) < 0
1057 || close (pipefd [1]) < 0
1058 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) 1189 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0
1190#endif
1191 || close (pipefd [1]) < 0
1192 )
1059 abort (); /*D*/ 1193 abort (); /*D*/
1060 1194
1061 close_fd = pipefd [0]; 1195 close_fd = pipefd [0];
1062#endif
1063 } 1196 }
1064 1197
1065 req->type = EIO_DUP2; 1198 req->type = EIO_DUP2;
1066 req->int1 = close_fd; 1199 req->int1 = close_fd;
1067 req->sv2 = newSVsv (fh); 1200 req->sv2 = newSVsv (fh);
1122 REQ_SEND; 1255 REQ_SEND;
1123 } 1256 }
1124} 1257}
1125 1258
1126void 1259void
1127aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1260aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1128 ALIAS: 1261 ALIAS:
1129 aio_readlink = EIO_READLINK 1262 aio_readlink = EIO_READLINK
1130 aio_realpath = EIO_REALPATH 1263 aio_realpath = EIO_REALPATH
1131 PPCODE: 1264 PPCODE:
1132{ 1265{
1133 SV *data;
1134 dREQ; 1266 dREQ;
1135 1267
1136 req->type = ix; 1268 req->type = ix;
1137 req->sv1 = newSVsv (path); 1269 req_set_path1 (req, pathname);
1138 req->ptr1 = SvPVbyte_nolen (req->sv1);
1139 1270
1140 REQ_SEND; 1271 REQ_SEND;
1141} 1272}
1142 1273
1143void 1274void
1183 aio_statvfs = EIO_STATVFS 1314 aio_statvfs = EIO_STATVFS
1184 PPCODE: 1315 PPCODE:
1185{ 1316{
1186 dREQ; 1317 dREQ;
1187 1318
1188 req->sv1 = newSVsv (fh_or_path); 1319 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1189
1190 if (SvPOK (req->sv1))
1191 {
1192 req->type = ix;
1193 req->ptr1 = SvPVbyte_nolen (req->sv1);
1194 }
1195 else
1196 {
1197 req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT;
1198 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1199 }
1200 1320
1201 REQ_SEND; 1321 REQ_SEND;
1202} 1322}
1203 1323
1204UV 1324UV
1223{ 1343{
1224 dREQ; 1344 dREQ;
1225 1345
1226 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; 1346 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.;
1227 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; 1347 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.;
1228 req->sv1 = newSVsv (fh_or_path); 1348 req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path);
1229
1230 if (SvPOK (req->sv1))
1231 {
1232 req->type = EIO_UTIME;
1233 req->ptr1 = SvPVbyte_nolen (req->sv1);
1234 }
1235 else
1236 {
1237 req->type = EIO_FUTIME;
1238 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1239 }
1240 1349
1241 REQ_SEND; 1350 REQ_SEND;
1242} 1351}
1243 1352
1244void 1353void
1245aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) 1354aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef)
1246 PPCODE: 1355 PPCODE:
1247{ 1356{
1248 dREQ; 1357 dREQ;
1249 1358
1250 req->sv1 = newSVsv (fh_or_path);
1251 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 1359 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1252 1360 req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path);
1253 if (SvPOK (req->sv1))
1254 {
1255 req->type = EIO_TRUNCATE;
1256 req->ptr1 = SvPVbyte_nolen (req->sv1);
1257 }
1258 else
1259 {
1260 req->type = EIO_FTRUNCATE;
1261 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1262 }
1263 1361
1264 REQ_SEND; 1362 REQ_SEND;
1265} 1363}
1266 1364
1267void 1365void
1268aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) 1366aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef)
1269 ALIAS:
1270 aio_chmod = EIO_CHMOD
1271 aio_mkdir = EIO_MKDIR
1272 PPCODE: 1367 PPCODE:
1273{ 1368{
1274 dREQ; 1369 dREQ;
1275 1370
1276 req->int2 = mode; 1371 req->int2 = mode;
1277 req->sv1 = newSVsv (fh_or_path); 1372 req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path);
1278
1279 if (SvPOK (req->sv1))
1280 {
1281 req->type = ix;
1282 req->ptr1 = SvPVbyte_nolen (req->sv1);
1283 }
1284 else
1285 {
1286 req->type = EIO_FCHMOD;
1287 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1288 }
1289 1373
1290 REQ_SEND; 1374 REQ_SEND;
1291} 1375}
1292 1376
1293void 1377void
1296{ 1380{
1297 dREQ; 1381 dREQ;
1298 1382
1299 req->int2 = SvOK (uid) ? SvIV (uid) : -1; 1383 req->int2 = SvOK (uid) ? SvIV (uid) : -1;
1300 req->int3 = SvOK (gid) ? SvIV (gid) : -1; 1384 req->int3 = SvOK (gid) ? SvIV (gid) : -1;
1301 req->sv1 = newSVsv (fh_or_path); 1385 req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path);
1302
1303 if (SvPOK (req->sv1))
1304 {
1305 req->type = EIO_CHOWN;
1306 req->ptr1 = SvPVbyte_nolen (req->sv1);
1307 }
1308 else
1309 {
1310 req->type = EIO_FCHOWN;
1311 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1312 }
1313 1386
1314 REQ_SEND; 1387 REQ_SEND;
1315} 1388}
1316 1389
1317void 1390void
1319 PPCODE: 1392 PPCODE:
1320{ 1393{
1321 dREQ; 1394 dREQ;
1322 1395
1323 req->type = EIO_READDIR; 1396 req->type = EIO_READDIR;
1324 req->sv1 = newSVsv (pathname);
1325 req->ptr1 = SvPVbyte_nolen (req->sv1);
1326 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; 1397 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1;
1327 1398
1328 if (flags & EIO_READDIR_DENTS) 1399 if (flags & EIO_READDIR_DENTS)
1329 req->int1 |= EIO_READDIR_CUSTOM2; 1400 req->int1 |= EIO_READDIR_CUSTOM2;
1330 1401
1402 req_set_path1 (req, pathname);
1403
1331 REQ_SEND; 1404 REQ_SEND;
1405}
1406
1407void
1408aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef)
1409 PPCODE:
1410{
1411 dREQ;
1412
1413 req->type = EIO_MKDIR;
1414 req->int2 = mode;
1415 req_set_path1 (req, pathname);
1416
1417 REQ_SEND;
1332} 1418}
1333 1419
1334void 1420void
1335aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) 1421aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1336 ALIAS: 1422 ALIAS:
1340 PPCODE: 1426 PPCODE:
1341{ 1427{
1342 dREQ; 1428 dREQ;
1343 1429
1344 req->type = ix; 1430 req->type = ix;
1345 req->sv1 = newSVsv (pathname); 1431 req_set_path1 (req, pathname);
1346 req->ptr1 = SvPVbyte_nolen (req->sv1);
1347 1432
1348 REQ_SEND; 1433 REQ_SEND;
1349} 1434}
1350 1435
1351void 1436void
1354 aio_link = EIO_LINK 1439 aio_link = EIO_LINK
1355 aio_symlink = EIO_SYMLINK 1440 aio_symlink = EIO_SYMLINK
1356 aio_rename = EIO_RENAME 1441 aio_rename = EIO_RENAME
1357 PPCODE: 1442 PPCODE:
1358{ 1443{
1444 eio_wd wd2 = 0;
1359 dREQ; 1445 dREQ;
1360 1446
1361 req->type = ix; 1447 req->type = ix;
1362 req->sv1 = newSVsv (oldpath); 1448 req_set_path1 (req, oldpath);
1363 req->ptr1 = SvPVbyte_nolen (req->sv1); 1449 req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2);
1364 req->sv2 = newSVsv (newpath); 1450 req->int3 = (long)wd2;
1365 req->ptr2 = SvPVbyte_nolen (req->sv2);
1366 1451
1367 REQ_SEND; 1452 REQ_SEND;
1368} 1453}
1369 1454
1370void 1455void
1372 PPCODE: 1457 PPCODE:
1373{ 1458{
1374 dREQ; 1459 dREQ;
1375 1460
1376 req->type = EIO_MKNOD; 1461 req->type = EIO_MKNOD;
1377 req->sv1 = newSVsv (pathname);
1378 req->ptr1 = SvPVbyte_nolen (req->sv1);
1379 req->int2 = (mode_t)mode; 1462 req->int2 = (mode_t)mode;
1380 req->offs = dev; 1463 req->offs = dev;
1464 req_set_path1 (req, pathname);
1381 1465
1382 REQ_SEND; 1466 REQ_SEND;
1383} 1467}
1384 1468
1385void 1469void
1585 CODE: 1669 CODE:
1586 RETVAL = posix_fadvise (fh, offset, length, advice); 1670 RETVAL = posix_fadvise (fh, offset, length, advice);
1587 OUTPUT: 1671 OUTPUT:
1588 RETVAL 1672 RETVAL
1589 1673
1590ssize_t 1674IV
1591sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1675sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1592 CODE: 1676 CODE:
1593 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1677 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1594 OUTPUT: 1678 OUTPUT:
1595 RETVAL 1679 RETVAL
1707 SvREFCNT_dec (on_next_submit); 1791 SvREFCNT_dec (on_next_submit);
1708 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1792 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1709 1793
1710PROTOTYPES: DISABLE 1794PROTOTYPES: DISABLE
1711 1795
1796MODULE = IO::AIO PACKAGE = IO::AIO::WD
1797
1798BOOT:
1799{
1800 newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD ));
1801 newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD));
1802}
1803
1804void
1805DESTROY (SV *self)
1806 CODE:
1807{
1808 aio_wd wd = SvAIO_WD (self);
1809#if HAVE_AT
1810 {
1811 SV *callback = &PL_sv_undef;
1812 dREQ; /* clobbers next_pri :/ */
1813 next_pri = req->pri; /* restore next_pri */
1814 req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */
1815 req->type = EIO_WD_CLOSE;
1816 req->wd = wd;
1817 REQ_SEND;
1818 }
1819#else
1820 eio_wd_close_sync (wd);
1821#endif
1822}
1823
1712MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1824MODULE = IO::AIO PACKAGE = IO::AIO::REQ
1713 1825
1714void 1826void
1715cancel (aio_req_ornot req) 1827cancel (aio_req_ornot req)
1716 CODE: 1828 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines