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.203 by root, Thu Sep 29 23:06:24 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)
372 || (SvSTASH (SvRV (sv)) != aio_grp_stash 385 || (SvSTASH (SvRV (sv)) != aio_grp_stash
377 mg = mg_find (SvRV (sv), PERL_MAGIC_ext); 390 mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
378 391
379 return mg ? (aio_req)mg->mg_ptr : 0; 392 return mg ? (aio_req)mg->mg_ptr : 0;
380} 393}
381 394
395static aio_wd
396SvAIO_WD (SV *sv)
397{
398 if (!SvROK (sv)
399 || SvSTASH (SvRV (sv)) != aio_wd_stash
400 || SvTYPE (SvRV (sv)) != SVt_PVMG)
401 croak ("IO::AIO: expected a working directory object as returned by aio_wd");
402
403 return (aio_wd)(long)SvIVX (SvRV (sv));
404}
405
406static void
382static void aio_grp_feed (aio_req grp) 407aio_grp_feed (aio_req grp)
383{ 408{
384 if (grp->sv2 && SvOK (grp->sv2)) 409 if (grp->sv2 && SvOK (grp->sv2))
385 { 410 {
386 dSP; 411 dSP;
387 412
395 FREETMPS; 420 FREETMPS;
396 LEAVE; 421 LEAVE;
397 } 422 }
398} 423}
399 424
425static void
400static void req_submit (eio_req *req) 426req_submit (eio_req *req)
401{ 427{
402 eio_submit (req); 428 eio_submit (req);
403 429
404 if (expect_false (on_next_submit)) 430 if (expect_false (on_next_submit))
405 { 431 {
412 PUTBACK; 438 PUTBACK;
413 call_sv (cb, G_DISCARD | G_EVAL); 439 call_sv (cb, G_DISCARD | G_EVAL);
414 } 440 }
415} 441}
416 442
443static int
417static int req_invoke (eio_req *req) 444req_invoke (eio_req *req)
418{ 445{
419 if (req->flags & FLAG_SV2_RO_OFF) 446 if (req->flags & FLAG_SV2_RO_OFF)
420 SvREADONLY_off (req->sv2); 447 SvREADONLY_off (req->sv2);
421 448
422 if (!EIO_CANCELLED (req) && req->callback) 449 if (!EIO_CANCELLED (req) && req->callback)
443 SvREADONLY_on (sv_result); 470 SvREADONLY_on (sv_result);
444 } 471 }
445 472
446 switch (req->type) 473 switch (req->type)
447 { 474 {
475 case EIO_WD_OPEN:
476 PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd)));
477 break;
478
448 case EIO_READDIR: 479 case EIO_READDIR:
449 { 480 {
450 SV *rv = &PL_sv_undef; 481 SV *rv = &PL_sv_undef;
451 482
452 if (req->result >= 0) 483 if (req->result >= 0)
594 break; 625 break;
595 626
596 case EIO_STAT: 627 case EIO_STAT:
597 case EIO_LSTAT: 628 case EIO_LSTAT:
598 case EIO_FSTAT: 629 case EIO_FSTAT:
599 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 630 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
631
600 PL_laststatval = req->result; 632 if (!(PL_laststatval = req->result))
633 /* if compilation fails here then perl's Stat_t is not struct _stati64 */
601 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 634 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
635
602 PUSHs (sv_result); 636 PUSHs (sv_result);
603 break; 637 break;
604 638
605 case EIO_READ: 639 case EIO_READ:
606 { 640 {
640 } 674 }
641 675
642 return !!SvTRUE (ERRSV); 676 return !!SvTRUE (ERRSV);
643} 677}
644 678
679static void
645static void req_destroy (aio_req req) 680req_destroy (aio_req req)
646{ 681{
647 if (req->self) 682 if (req->self)
648 { 683 {
649 sv_unmagic (req->self, PERL_MAGIC_ext); 684 sv_unmagic (req->self, PERL_MAGIC_ext);
650 SvREFCNT_dec (req->self); 685 SvREFCNT_dec (req->self);
651 } 686 }
652 687
653 SvREFCNT_dec (req->sv1); 688 SvREFCNT_dec (req->sv1);
654 SvREFCNT_dec (req->sv2); 689 SvREFCNT_dec (req->sv2);
690 SvREFCNT_dec (req->sv3);
691 SvREFCNT_dec (req->sv4);
655 SvREFCNT_dec (req->callback); 692 SvREFCNT_dec (req->callback);
656 693
657 Safefree (req); 694 Safefree (req);
658} 695}
659 696
697static void
660static void req_cancel_subs (aio_req grp) 698req_cancel_subs (aio_req grp)
661{ 699{
662 aio_req sub;
663
664 if (grp->type != EIO_GROUP) 700 if (grp->type != EIO_GROUP)
665 return; 701 return;
666 702
667 SvREFCNT_dec (grp->sv2); 703 SvREFCNT_dec (grp->sv2);
668 grp->sv2 = 0; 704 grp->sv2 = 0;
669 705
670 eio_grp_cancel (grp); 706 eio_grp_cancel (grp);
671} 707}
672 708
709static void ecb_cold
673static void create_respipe (void) 710create_respipe (void)
674{ 711{
675 if (s_epipe_renew (&respipe)) 712 if (s_epipe_renew (&respipe))
676 croak ("IO::AIO: unable to initialize result pipe"); 713 croak ("IO::AIO: unable to initialize result pipe");
677} 714}
678 715
679static void poll_wait (void) 716static void
717poll_wait (void)
680{ 718{
681 while (eio_nreqs ()) 719 while (eio_nreqs ())
682 { 720 {
683 int size; 721 int size;
684 722
693 731
694 s_epipe_wait (&respipe); 732 s_epipe_wait (&respipe);
695 } 733 }
696} 734}
697 735
698static int poll_cb (void) 736static int
737poll_cb (void)
699{ 738{
700 for (;;) 739 for (;;)
701 { 740 {
702 int res = eio_poll (); 741 int res = eio_poll ();
703 742
709 748
710 poll_wait (); 749 poll_wait ();
711 } 750 }
712} 751}
713 752
714static void atfork_child (void) 753static void ecb_cold
754reinit (void)
715{ 755{
716 create_respipe (); 756 create_respipe ();
757
758 if (eio_init (want_poll, done_poll) < 0)
759 croak ("IO::AIO: unable to initialise eio library");
717} 760}
718 761
719/*****************************************************************************/ 762/*****************************************************************************/
720 763
721#if !_POSIX_MAPPED_FILES 764#if !_POSIX_MAPPED_FILES
732# define MAP_FIXED 0 775# define MAP_FIXED 0
733#endif 776#endif
734 777
735#define MMAP_MAGIC PERL_MAGIC_ext 778#define MMAP_MAGIC PERL_MAGIC_ext
736 779
780static int ecb_cold
737static int mmap_free (pTHX_ SV *sv, MAGIC *mg) 781mmap_free (pTHX_ SV *sv, MAGIC *mg)
738{ 782{
739 int old_errno = errno; 783 int old_errno = errno;
740 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 784 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
741 errno = old_errno; 785 errno = old_errno;
742 786
758 0, 0, 0, 0, mmap_free 802 0, 0, 0, 0, mmap_free
759}; 803};
760 804
761/*****************************************************************************/ 805/*****************************************************************************/
762 806
807static SV *
763static SV * get_cb (SV *cb_sv) 808get_cb (SV *cb_sv)
764{ 809{
765 SvGETMAGIC (cb_sv); 810 SvGETMAGIC (cb_sv);
766 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 811 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
767} 812}
768 813
814static aio_req ecb_noinline
815dreq (SV *callback)
816{
817 SV *cb_cv;
818 aio_req req;
819 int req_pri = next_pri;
820 next_pri = EIO_PRI_DEFAULT;
821
822 cb_cv = get_cb (callback);
823
824 Newz (0, req, 1, eio_req);
825 if (!req)
826 croak ("out of memory during eio_req allocation");
827
828 req->callback = SvREFCNT_inc (cb_cv);
829 req->pri = req_pri;
830
831 return req;
832}
833
769#define dREQ \ 834#define dREQ \
770 SV *cb_cv; \ 835 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 836
784#define REQ_SEND \ 837#define REQ_SEND \
785 PUTBACK; \ 838 PUTBACK; \
786 req_submit (req); \ 839 req_submit (req); \
787 SPAGAIN; \ 840 SPAGAIN; \
788 \ 841 \
789 if (GIMME_V != G_VOID) \ 842 if (GIMME_V != G_VOID) \
790 XPUSHs (req_sv (req, aio_req_stash)); 843 XPUSHs (req_sv (req, aio_req_stash));
844
845ecb_inline void
846req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr)
847{
848 if (expect_false (SvROK (path)))
849 {
850 AV *av = (AV *)SvRV (path);
851 SV *wdob;
852
853 if (SvTYPE (av) != SVt_PVAV || AvFILLp (av) != 1)
854 croak ("IO::AIO: pathname arguments must be specified as strings or [wd, path] arrayrefs");
855
856 path = AvARRAY (av)[1];
857 wdob = AvARRAY (av)[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
868 *pathsv = newSVsv (path);
869 *ptr = SvPVbyte_nolen (*pathsv);
870}
871
872static void ecb_noinline
873req_set_path1 (aio_req req, SV *path)
874{
875 req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1);
876}
877
878static void ecb_noinline
879req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path)
880{
881 SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path;
882
883 switch (SvTYPE (rv))
884 {
885 case SVt_PVIO:
886 case SVt_PVLV:
887 case SVt_PVGV:
888 req->type = type_fh;
889 req->sv1 = newSVsv (fh_or_path);
890 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
891 break;
892
893 default:
894 req->type = type_path;
895 req_set_path1 (req, fh_or_path);
896 break;
897 }
898}
899
900XS(boot_IO__AIO) ecb_cold;
791 901
792MODULE = IO::AIO PACKAGE = IO::AIO 902MODULE = IO::AIO PACKAGE = IO::AIO
793 903
794PROTOTYPES: ENABLE 904PROTOTYPES: ENABLE
795 905
913 }; 1023 };
914 1024
915 aio_stash = gv_stashpv ("IO::AIO" , 1); 1025 aio_stash = gv_stashpv ("IO::AIO" , 1);
916 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); 1026 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1);
917 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); 1027 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1);
1028 aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1);
918 1029
919 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1030 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)); 1031 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
921 1032
922 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 1033 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
923 1034
924 create_respipe (); 1035 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} 1036}
1037
1038void
1039reinit ()
1040 PROTOTYPE:
932 1041
933void 1042void
934max_poll_reqs (unsigned int nreqs) 1043max_poll_reqs (unsigned int nreqs)
935 PROTOTYPE: $ 1044 PROTOTYPE: $
936 CODE: 1045 CODE:
971 PROTOTYPE: $ 1080 PROTOTYPE: $
972 CODE: 1081 CODE:
973 max_outstanding = maxreqs; 1082 max_outstanding = maxreqs;
974 1083
975void 1084void
1085aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef)
1086 PPCODE:
1087{
1088 dREQ;
1089
1090 req->type = EIO_WD_OPEN;
1091 req_set_path1 (req, pathname);
1092
1093 REQ_SEND;
1094}
1095
1096void
976aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 1097aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
977 PPCODE: 1098 PPCODE:
978{ 1099{
979 dREQ; 1100 dREQ;
980 1101
981 req->type = EIO_OPEN; 1102 req->type = EIO_OPEN;
982 req->sv1 = newSVsv (pathname); 1103 req_set_path1 (req, pathname);
983 req->ptr1 = SvPVbyte_nolen (req->sv1);
984 req->int1 = flags; 1104 req->int1 = flags;
985 req->int2 = mode; 1105 req->int2 = mode;
986 1106
987 REQ_SEND; 1107 REQ_SEND;
988} 1108}
990void 1110void
991aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 1111aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
992 ALIAS: 1112 ALIAS:
993 aio_fsync = EIO_FSYNC 1113 aio_fsync = EIO_FSYNC
994 aio_fdatasync = EIO_FDATASYNC 1114 aio_fdatasync = EIO_FDATASYNC
1115 aio_syncfs = EIO_SYNCFS
995 PPCODE: 1116 PPCODE:
996{ 1117{
997 int fd = s_fileno_croak (fh, 0); 1118 int fd = s_fileno_croak (fh, 0);
998 dREQ; 1119 dREQ;
999 1120
1046 int fd = s_fileno_croak (fh, 0); 1167 int fd = s_fileno_croak (fh, 0);
1047 dREQ; 1168 dREQ;
1048 1169
1049 if (expect_false (close_fd < 0)) 1170 if (expect_false (close_fd < 0))
1050 { 1171 {
1172 int pipefd [2];
1173
1174 if (
1051#ifdef _WIN32 1175#ifdef _WIN32
1052 close_fd = _open_osfhandle (socket (AF_INET, SOCK_STREAM, 0), 0); 1176 _pipe (pipefd, 1, _O_BINARY) < 0
1053#else 1177#else
1054 int pipefd [2];
1055
1056 if (pipe (pipefd) < 0 1178 pipe (pipefd) < 0
1057 || close (pipefd [1]) < 0
1058 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) 1179 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0
1180#endif
1181 || close (pipefd [1]) < 0
1182 )
1059 abort (); /*D*/ 1183 abort (); /*D*/
1060 1184
1061 close_fd = pipefd [0]; 1185 close_fd = pipefd [0];
1062#endif
1063 } 1186 }
1064 1187
1065 req->type = EIO_DUP2; 1188 req->type = EIO_DUP2;
1066 req->int1 = close_fd; 1189 req->int1 = close_fd;
1067 req->sv2 = newSVsv (fh); 1190 req->sv2 = newSVsv (fh);
1122 REQ_SEND; 1245 REQ_SEND;
1123 } 1246 }
1124} 1247}
1125 1248
1126void 1249void
1127aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1250aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1128 ALIAS: 1251 ALIAS:
1129 aio_readlink = EIO_READLINK 1252 aio_readlink = EIO_READLINK
1130 aio_realpath = EIO_REALPATH 1253 aio_realpath = EIO_REALPATH
1131 PPCODE: 1254 PPCODE:
1132{ 1255{
1133 SV *data;
1134 dREQ; 1256 dREQ;
1135 1257
1136 req->type = ix; 1258 req->type = ix;
1137 req->sv1 = newSVsv (path); 1259 req_set_path1 (req, pathname);
1138 req->ptr1 = SvPVbyte_nolen (req->sv1);
1139 1260
1140 REQ_SEND; 1261 REQ_SEND;
1141} 1262}
1142 1263
1143void 1264void
1183 aio_statvfs = EIO_STATVFS 1304 aio_statvfs = EIO_STATVFS
1184 PPCODE: 1305 PPCODE:
1185{ 1306{
1186 dREQ; 1307 dREQ;
1187 1308
1188 req->sv1 = newSVsv (fh_or_path); 1309 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 1310
1201 REQ_SEND; 1311 REQ_SEND;
1202} 1312}
1203 1313
1204UV 1314UV
1223{ 1333{
1224 dREQ; 1334 dREQ;
1225 1335
1226 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; 1336 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.;
1227 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; 1337 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.;
1228 req->sv1 = newSVsv (fh_or_path); 1338 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 1339
1241 REQ_SEND; 1340 REQ_SEND;
1242} 1341}
1243 1342
1244void 1343void
1245aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) 1344aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef)
1246 PPCODE: 1345 PPCODE:
1247{ 1346{
1248 dREQ; 1347 dREQ;
1249 1348
1250 req->sv1 = newSVsv (fh_or_path);
1251 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 1349 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1252 1350 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 1351
1264 REQ_SEND; 1352 REQ_SEND;
1265} 1353}
1266 1354
1267void 1355void
1268aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) 1356aio_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: 1357 PPCODE:
1273{ 1358{
1274 dREQ; 1359 dREQ;
1275 1360
1276 req->int2 = mode; 1361 req->int2 = mode;
1277 req->sv1 = newSVsv (fh_or_path); 1362 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 1363
1290 REQ_SEND; 1364 REQ_SEND;
1291} 1365}
1292 1366
1293void 1367void
1296{ 1370{
1297 dREQ; 1371 dREQ;
1298 1372
1299 req->int2 = SvOK (uid) ? SvIV (uid) : -1; 1373 req->int2 = SvOK (uid) ? SvIV (uid) : -1;
1300 req->int3 = SvOK (gid) ? SvIV (gid) : -1; 1374 req->int3 = SvOK (gid) ? SvIV (gid) : -1;
1301 req->sv1 = newSVsv (fh_or_path); 1375 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 1376
1314 REQ_SEND; 1377 REQ_SEND;
1315} 1378}
1316 1379
1317void 1380void
1319 PPCODE: 1382 PPCODE:
1320{ 1383{
1321 dREQ; 1384 dREQ;
1322 1385
1323 req->type = EIO_READDIR; 1386 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; 1387 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1;
1327 1388
1328 if (flags & EIO_READDIR_DENTS) 1389 if (flags & EIO_READDIR_DENTS)
1329 req->int1 |= EIO_READDIR_CUSTOM2; 1390 req->int1 |= EIO_READDIR_CUSTOM2;
1330 1391
1392 req_set_path1 (req, pathname);
1393
1331 REQ_SEND; 1394 REQ_SEND;
1395}
1396
1397void
1398aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef)
1399 PPCODE:
1400{
1401 dREQ;
1402
1403 req->type = EIO_MKDIR;
1404 req->int2 = mode;
1405 req_set_path1 (req, pathname);
1406
1407 REQ_SEND;
1332} 1408}
1333 1409
1334void 1410void
1335aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) 1411aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1336 ALIAS: 1412 ALIAS:
1340 PPCODE: 1416 PPCODE:
1341{ 1417{
1342 dREQ; 1418 dREQ;
1343 1419
1344 req->type = ix; 1420 req->type = ix;
1345 req->sv1 = newSVsv (pathname); 1421 req_set_path1 (req, pathname);
1346 req->ptr1 = SvPVbyte_nolen (req->sv1);
1347 1422
1348 REQ_SEND; 1423 REQ_SEND;
1349} 1424}
1350 1425
1351void 1426void
1355 aio_symlink = EIO_SYMLINK 1430 aio_symlink = EIO_SYMLINK
1356 aio_rename = EIO_RENAME 1431 aio_rename = EIO_RENAME
1357 PPCODE: 1432 PPCODE:
1358{ 1433{
1359 dREQ; 1434 dREQ;
1435 eio_wd wd2 = 0;
1360 1436
1361 req->type = ix; 1437 req->type = ix;
1362 req->sv1 = newSVsv (oldpath); 1438 req_set_path1 (req, oldpath);
1363 req->ptr1 = SvPVbyte_nolen (req->sv1); 1439 req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2);
1364 req->sv2 = newSVsv (newpath); 1440 req->int3 = (long)wd2;
1365 req->ptr2 = SvPVbyte_nolen (req->sv2);
1366 1441
1367 REQ_SEND; 1442 REQ_SEND;
1368} 1443}
1369 1444
1370void 1445void
1372 PPCODE: 1447 PPCODE:
1373{ 1448{
1374 dREQ; 1449 dREQ;
1375 1450
1376 req->type = EIO_MKNOD; 1451 req->type = EIO_MKNOD;
1377 req->sv1 = newSVsv (pathname);
1378 req->ptr1 = SvPVbyte_nolen (req->sv1);
1379 req->int2 = (mode_t)mode; 1452 req->int2 = (mode_t)mode;
1380 req->offs = dev; 1453 req->offs = dev;
1454 req_set_path1 (req, pathname);
1381 1455
1382 REQ_SEND; 1456 REQ_SEND;
1383} 1457}
1384 1458
1385void 1459void
1585 CODE: 1659 CODE:
1586 RETVAL = posix_fadvise (fh, offset, length, advice); 1660 RETVAL = posix_fadvise (fh, offset, length, advice);
1587 OUTPUT: 1661 OUTPUT:
1588 RETVAL 1662 RETVAL
1589 1663
1590ssize_t 1664IV
1591sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1665sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1592 CODE: 1666 CODE:
1593 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1667 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1594 OUTPUT: 1668 OUTPUT:
1595 RETVAL 1669 RETVAL
1707 SvREFCNT_dec (on_next_submit); 1781 SvREFCNT_dec (on_next_submit);
1708 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1782 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1709 1783
1710PROTOTYPES: DISABLE 1784PROTOTYPES: DISABLE
1711 1785
1786MODULE = IO::AIO PACKAGE = IO::AIO::WD
1787
1788BOOT:
1789{
1790 newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD ));
1791 newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD));
1792}
1793
1794void
1795DESTROY (SV *self)
1796 CODE:
1797{
1798 aio_wd wd = SvAIO_WD (self);
1799#if HAVE_AT
1800 {
1801 SV *callback = &PL_sv_undef;
1802 dREQ; /* clobbers next_pri :/ */
1803 next_pri = req->pri; /* restore next_pri */
1804 req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */
1805 req->type = EIO_WD_CLOSE;
1806 req->wd = wd;
1807 REQ_SEND;
1808 }
1809#else
1810 eio_wd_close_sync (wd);
1811#endif
1812}
1813
1712MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1814MODULE = IO::AIO PACKAGE = IO::AIO::REQ
1713 1815
1714void 1816void
1715cancel (aio_req_ornot req) 1817cancel (aio_req_ornot req)
1716 CODE: 1818 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines