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.194 by root, Fri Jul 29 08:35:36 2011 UTC vs.
Revision 1.218 by root, Fri Jul 27 17:54:40 2012 UTC

17#include <fcntl.h> 17#include <fcntl.h>
18#include <sched.h> 18#include <sched.h>
19 19
20#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES 20#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
21# include <sys/mman.h> 21# include <sys/mman.h>
22#endif
23
24#if __linux__
25# include <linux/fs.h>
26# ifdef FS_IOC_FIEMAP
27# include <linux/types.h>
28# include <linux/fiemap.h>
29# define HAVE_FIEMAP 1
30# endif
22#endif 31#endif
23 32
24/* perl namespace pollution */ 33/* perl namespace pollution */
25#undef VERSION 34#undef VERSION
26 35
62 #undef dup 71 #undef dup
63 #undef dup2 72 #undef dup2
64 #undef abort 73 #undef abort
65 #undef pipe 74 #undef pipe
66 75
76 #define EIO_STRUCT_STAT struct _stati64
77 #define EIO_STRUCT_STATI64
78
67#else 79#else
68 80
69 #include <sys/time.h> 81 #include <sys/time.h>
70 #include <sys/select.h> 82 #include <sys/select.h>
71 #include <unistd.h> 83 #include <unistd.h>
72 #include <utime.h> 84 #include <utime.h>
73 #include <signal.h> 85 #include <signal.h>
74 86
75#endif
76
77#define EIO_STRUCT_STAT Stat_t 87 #define EIO_STRUCT_STAT Stat_t
78 88
79/* use NV for 32 bit perls as it allows larger offsets */
80#if IVSIZE >= 8
81# define VAL64 IV
82# define SvVAL64 SvIV
83# define newSVval64 newSViv
84#else
85# define VAL64 NV
86# define SvVAL64 SvNV
87# define newSVval64 newSVnv
88#endif 89#endif
89 90
90/*****************************************************************************/ 91/*****************************************************************************/
91 92
92#if __GNUC__ >= 3 93#if __GNUC__ >= 3
102 103
103typedef SV SV8; /* byte-sv, used for argument-checking */ 104typedef SV SV8; /* byte-sv, used for argument-checking */
104typedef int aio_rfd; /* read file desriptor */ 105typedef int aio_rfd; /* read file desriptor */
105typedef int aio_wfd; /* write file descriptor */ 106typedef int aio_wfd; /* write file descriptor */
106 107
107static HV *aio_stash, *aio_req_stash, *aio_grp_stash; 108static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash;
108 109
109#define EIO_REQ_MEMBERS \ 110#define EIO_REQ_MEMBERS \
110 SV *callback; \ 111 SV *callback; \
111 SV *sv1, *sv2; \ 112 SV *sv1, *sv2; \
113 SV *sv3, *sv4; \
112 STRLEN stroffset; \ 114 STRLEN stroffset; \
113 SV *self; 115 SV *self;
114 116
115#define EIO_NO_WRAPPERS 1 117#define EIO_NO_WRAPPERS 1
116 118
122static void req_destroy (eio_req *grp); 124static void req_destroy (eio_req *grp);
123#define EIO_DESTROY(req) req_destroy (req) 125#define EIO_DESTROY(req) req_destroy (req)
124 126
125#include "libeio/eio.c" 127#include "libeio/eio.c"
126 128
127/* Linux/others */
128#ifndef O_ASYNC
129# define O_ASYNC 0
130#endif
131#ifndef O_DIRECT
132# define O_DIRECT 0
133#endif
134#ifndef O_NOATIME
135# define O_NOATIME 0
136#endif
137
138/* POSIX */
139#ifndef O_CLOEXEC
140# define O_CLOEXEC 0
141#endif
142#ifndef O_NOFOLLOW
143# define O_NOFOLLOW 0
144#endif
145#ifndef O_NOCTTY
146# define O_NOCTTY 0
147#endif
148#ifndef O_NONBLOCK
149# define O_NONBLOCK 0
150#endif
151#ifndef O_EXEC
152# define O_EXEC 0
153#endif
154#ifndef O_SEARCH
155# define O_SEARCH 0
156#endif
157#ifndef O_DIRECTORY
158# define O_DIRECTORY 0
159#endif
160#ifndef O_DSYNC
161# define O_DSYNC 0
162#endif
163#ifndef O_RSYNC
164# define O_RSYNC 0
165#endif
166#ifndef O_SYNC
167# define O_SYNC 0
168#endif
169#ifndef O_TTY_INIT
170# define O_TTY_INIT 0
171#endif
172
173#ifndef POSIX_FADV_NORMAL
174# define POSIX_FADV_NORMAL 0
175#endif
176#ifndef POSIX_FADV_SEQUENTIAL
177# define POSIX_FADV_SEQUENTIAL 0
178#endif
179#ifndef POSIX_FADV_RANDOM
180# define POSIX_FADV_RANDOM 0
181#endif
182#ifndef POSIX_FADV_NOREUSE
183# define POSIX_FADV_NOREUSE 0
184#endif
185#ifndef POSIX_FADV_WILLNEED
186# define POSIX_FADV_WILLNEED 0
187#endif
188#ifndef POSIX_FADV_DONTNEED
189# define POSIX_FADV_DONTNEED 0
190#endif
191
192#if !HAVE_POSIX_FADVISE 129#if !HAVE_POSIX_FADVISE
193# define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ 130# define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */
194#endif 131#endif
195 132
196#ifndef POSIX_MADV_NORMAL
197# define POSIX_MADV_NORMAL 0
198#endif
199#ifndef POSIX_MADV_SEQUENTIAL
200# define POSIX_MADV_SEQUENTIAL 0
201#endif
202#ifndef POSIX_MADV_RANDOM
203# define POSIX_MADV_RANDOM 0
204#endif
205#ifndef POSIX_MADV_WILLNEED
206# define POSIX_MADV_WILLNEED 0
207#endif
208#ifndef POSIX_MADV_DONTNEED
209# define POSIX_MADV_DONTNEED 0
210#endif
211
212#if !HAVE_POSIX_MADVISE 133#if !HAVE_POSIX_MADVISE
213# define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ 134# define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */
214#endif
215
216#ifndef PROT_NONE
217# define PROT_NONE 0
218#endif
219#ifndef PROT_READ
220# define PROT_READ 0
221#endif
222#ifndef PROT_WRITE
223# define PROT_READ 0
224#endif
225#ifndef PROT_EXEC
226# define PROT_EXEC 0
227#endif
228
229#ifndef ST_RDONLY
230# define ST_RDONLY 0
231#endif
232#ifndef ST_NOSUID
233# define ST_NOSUID 0
234#endif
235#ifndef ST_NODEV
236# define ST_NODEV 0
237#endif
238#ifndef ST_NOEXEC
239# define ST_NOEXEC 0
240#endif
241#ifndef ST_SYNCHRONOUS
242# define ST_SYNCHRONOUS 0
243#endif
244#ifndef ST_MANDLOCK
245# define ST_MANDLOCK 0
246#endif
247#ifndef ST_WRITE
248# define ST_WRITE 0
249#endif
250#ifndef ST_APPEND
251# define ST_APPEND 0
252#endif
253#ifndef ST_IMMUTABLE
254# define ST_IMMUTABLE 0
255#endif
256#ifndef ST_NOATIME
257# define ST_NOATIME 0
258#endif
259#ifndef ST_NODIRATIME
260# define ST_NODIRATIME 0
261#endif
262#ifndef ST_RELATIME
263# define ST_RELATIME 0
264#endif
265
266#ifndef S_IFIFO
267# define S_IFIFO 0
268#endif
269#ifndef S_IFCHR
270# define S_IFCHR 0
271#endif
272#ifndef S_IFBLK
273# define S_IFBLK 0
274#endif
275#ifndef S_IFLNK
276# define S_IFLNK 0
277#endif
278#ifndef S_IFREG
279# define S_IFREG 0
280#endif
281#ifndef S_IFDIR
282# define S_IFDIR 0
283#endif
284#ifndef S_IFWHT
285# define S_IFWHT 0
286#endif
287#ifndef S_IFSOCK
288# define S_IFSOCK 0
289#endif 135#endif
290 136
291#ifndef MAP_ANONYMOUS 137#ifndef MAP_ANONYMOUS
292# ifdef MAP_ANON 138# ifdef MAP_ANON
293# define MAP_ANONYMOUS MAP_ANON 139# define MAP_ANONYMOUS MAP_ANON
294# else 140# else
295# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 141# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
296# endif 142# endif
297#endif 143#endif
298#ifndef MAP_HUGETLB 144
299# define MAP_HUGETLB 0 145/* defines all sorts of constants to 0 unless they are already defined */
300#endif 146#include "def0.h"
301#ifndef MAP_LOCKED
302# define MAP_LOCKED 0
303#endif
304#ifndef MAP_NORESERVE
305# define MAP_NORESERVE 0
306#endif
307#ifndef MAP_POPULATE
308# define MAP_POPULATE 0
309#endif
310#ifndef MAP_NONBLOCK
311# define MAP_NONBLOCK 0
312#endif
313 147
314#ifndef makedev 148#ifndef makedev
315# define makedev(maj,min) (((maj) << 8) | (min)) 149# define makedev(maj,min) (((maj) << 8) | (min))
316#endif 150#endif
317#ifndef major 151#ifndef major
322#endif 156#endif
323 157
324#ifndef PAGESIZE 158#ifndef PAGESIZE
325# define PAGESIZE sysconf (_SC_PAGESIZE) 159# define PAGESIZE sysconf (_SC_PAGESIZE)
326#endif 160#endif
161
162/*****************************************************************************/
163
164static void
165fiemap (eio_req *req)
166{
167 req->result = -1;
168
169#if HAVE_FIEMAP
170 int count = req->int3;
171
172 /* heuristic: first try with 72 extents if we don't know how many, */
173 /* as most files have (hopefully) fewer than this many extents */
174 /* in fact, most should have <= 2, so the 72 below is probably overkill */
175 if (count < 0)
176 count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */
177
178 for (;;)
179 {
180 struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count);
181 errno = ENOMEM;
182 if (!fiemap)
183 return;
184
185 req->ptr1 = fiemap;
186 req->flags |= EIO_FLAG_PTR1_FREE;
187
188 fiemap->fm_start = req->offs;
189 fiemap->fm_length = req->size;
190 fiemap->fm_flags = req->int2;
191 fiemap->fm_extent_count = count;
192
193 if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap))
194 return;
195
196 if (req->int3 >= 0)
197 break; /* when not autosizing we are done */
198
199 if (!fiemap->fm_mapped_extents)
200 break; /* if file has no segments, we are done */
201
202 if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST)
203 break; /* autosizing successful, we are done */
204
205 fiemap->fm_flags = req->int2;
206 fiemap->fm_extent_count = 0;
207
208 if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap))
209 return;
210
211 count = fiemap->fm_mapped_extents;
212
213 free (fiemap);
214 }
215
216 req->result = 0;
217
218#else
219 errno = ENOSYS;
220#endif
221}
222
223/*****************************************************************************/
327 224
328enum { 225enum {
329 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 226 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
330}; 227};
331 228
332typedef eio_req *aio_req; 229typedef eio_req *aio_req;
333typedef eio_req *aio_req_ornot; 230typedef eio_req *aio_req_ornot;
231typedef eio_wd aio_wd;
334 232
335static SV *on_next_submit; 233static SV *on_next_submit;
336static int next_pri = EIO_PRI_DEFAULT; 234static int next_pri = EIO_PRI_DEFAULT;
337static int max_outstanding; 235static int max_outstanding;
338 236
339static s_epipe respipe; 237static s_epipe respipe;
340 238
341static void req_destroy (aio_req req); 239static void req_destroy (aio_req req);
342static void req_cancel (aio_req req); 240static void req_cancel (aio_req req);
343 241
344static void want_poll (void) 242static void
243want_poll (void)
345{ 244{
346 /* write a dummy byte to the pipe so fh becomes ready */ 245 /* write a dummy byte to the pipe so fh becomes ready */
347 s_epipe_signal (&respipe); 246 s_epipe_signal (&respipe);
348} 247}
349 248
350static void done_poll (void) 249static void
250done_poll (void)
351{ 251{
352 /* read any signals sent by the worker threads */ 252 /* read any signals sent by the worker threads */
353 s_epipe_drain (&respipe); 253 s_epipe_drain (&respipe);
354} 254}
355 255
356/* must be called at most once */ 256/* must be called at most once */
257static SV *
357static SV *req_sv (aio_req req, HV *stash) 258req_sv (aio_req req, HV *stash)
358{ 259{
359 if (!req->self) 260 if (!req->self)
360 { 261 {
361 req->self = (SV *)newHV (); 262 req->self = (SV *)newHV ();
362 sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); 263 sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0);
363 } 264 }
364 265
365 return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); 266 return sv_2mortal (sv_bless (newRV_inc (req->self), stash));
366} 267}
367 268
368static aio_req SvAIO_REQ (SV *sv) 269static SV *
270newSVaio_wd (aio_wd wd)
271{
272 return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash);
273}
274
275static aio_req
276SvAIO_REQ (SV *sv)
369{ 277{
370 MAGIC *mg; 278 MAGIC *mg;
371 279
372 if (!SvROK (sv) 280 if (!SvROK (sv)
281 /* for speed reasons, we do not verify that SvROK actually has a stash ptr */
373 || (SvSTASH (SvRV (sv)) != aio_grp_stash 282 || (SvSTASH (SvRV (sv)) != aio_grp_stash
374 && SvSTASH (SvRV (sv)) != aio_req_stash 283 && SvSTASH (SvRV (sv)) != aio_req_stash
375 && !sv_derived_from (sv, "IO::AIO::REQ"))) 284 && !sv_derived_from (sv, "IO::AIO::REQ")))
376 croak ("object of class IO::AIO::REQ expected"); 285 croak ("object of class IO::AIO::REQ expected");
377 286
378 mg = mg_find (SvRV (sv), PERL_MAGIC_ext); 287 mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
379 288
380 return mg ? (aio_req)mg->mg_ptr : 0; 289 return mg ? (aio_req)mg->mg_ptr : 0;
381} 290}
382 291
292static aio_wd
293SvAIO_WD (SV *sv)
294{
295 if (!SvROK (sv)
296 || SvTYPE (SvRV (sv)) != SVt_PVMG
297 || SvSTASH (SvRV (sv)) != aio_wd_stash)
298 croak ("IO::AIO: expected a working directory object as returned by aio_wd");
299
300 return (aio_wd)(long)SvIVX (SvRV (sv));
301}
302
303static void
383static void aio_grp_feed (aio_req grp) 304aio_grp_feed (aio_req grp)
384{ 305{
385 if (grp->sv2 && SvOK (grp->sv2)) 306 if (grp->sv2 && SvOK (grp->sv2))
386 { 307 {
387 dSP; 308 dSP;
388 309
396 FREETMPS; 317 FREETMPS;
397 LEAVE; 318 LEAVE;
398 } 319 }
399} 320}
400 321
322static void
401static void req_submit (eio_req *req) 323req_submit (eio_req *req)
402{ 324{
403 eio_submit (req); 325 eio_submit (req);
404 326
405 if (expect_false (on_next_submit)) 327 if (expect_false (on_next_submit))
406 { 328 {
413 PUTBACK; 335 PUTBACK;
414 call_sv (cb, G_DISCARD | G_EVAL); 336 call_sv (cb, G_DISCARD | G_EVAL);
415 } 337 }
416} 338}
417 339
340static int
418static int req_invoke (eio_req *req) 341req_invoke (eio_req *req)
419{ 342{
420 if (req->flags & FLAG_SV2_RO_OFF) 343 if (req->flags & FLAG_SV2_RO_OFF)
421 SvREADONLY_off (req->sv2); 344 SvREADONLY_off (req->sv2);
422 345
423 if (!EIO_CANCELLED (req) && req->callback) 346 if (!EIO_CANCELLED (req) && req->callback)
444 SvREADONLY_on (sv_result); 367 SvREADONLY_on (sv_result);
445 } 368 }
446 369
447 switch (req->type) 370 switch (req->type)
448 { 371 {
372 case EIO_WD_OPEN:
373 PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd)));
374 break;
375
449 case EIO_READDIR: 376 case EIO_READDIR:
450 { 377 {
451 SV *rv = &PL_sv_undef; 378 SV *rv = &PL_sv_undef;
452 379
453 if (req->result >= 0) 380 if (req->result >= 0)
595 break; 522 break;
596 523
597 case EIO_STAT: 524 case EIO_STAT:
598 case EIO_LSTAT: 525 case EIO_LSTAT:
599 case EIO_FSTAT: 526 case EIO_FSTAT:
600 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 527 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
528
601 PL_laststatval = req->result; 529 if (!(PL_laststatval = req->result))
602 /* if compilation fails here then perl's Stat_t is not struct _stati64 */ 530 /* if compilation fails here then perl's Stat_t is not struct _stati64 */
603 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 531 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
532
604 PUSHs (sv_result); 533 PUSHs (sv_result);
534 break;
535
536 case EIO_SEEK:
537 PUSHs (req->result ? sv_result : sv_2mortal (newSVval64 (req->offs)));
605 break; 538 break;
606 539
607 case EIO_READ: 540 case EIO_READ:
608 { 541 {
609 SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); 542 SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0));
612 SvSETMAGIC (req->sv2); 545 SvSETMAGIC (req->sv2);
613 PUSHs (sv_result); 546 PUSHs (sv_result);
614 } 547 }
615 break; 548 break;
616 549
550 case EIO_CUSTOM:
551 if (req->feed == fiemap)
552 {
553#if HAVE_FIEMAP
554 if (!req->result)
555 {
556 struct fiemap *fiemap = (struct fiemap *)req->ptr1;
557
558 if (fiemap->fm_extent_count)
559 {
560 AV *av = newAV ();
561 int i;
562
563 while (fiemap->fm_mapped_extents)
564 {
565 struct fiemap_extent *extent = &fiemap->fm_extents [--fiemap->fm_mapped_extents];
566 AV *ext_av = newAV ();
567
568 av_store (ext_av, 3, newSVuv (extent->fe_flags));
569 av_store (ext_av, 2, newSVval64 (extent->fe_length));
570 av_store (ext_av, 1, newSVval64 (extent->fe_physical));
571 av_store (ext_av, 0, newSVval64 (extent->fe_logical));
572
573 av_store (av, fiemap->fm_mapped_extents, newRV_noinc ((SV *)ext_av));
574 }
575
576 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
577 }
578 else
579 {
580 SvIV_set (sv_result, fiemap->fm_mapped_extents);
581 PUSHs (sv_result);
582 }
583 }
584#endif
585 }
586 else
587 PUSHs (sv_result);
588 break;
589
617 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ 590 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */
618 if (req->result > 0) 591 if (req->result > 0)
619 SvIV_set (sv_result, 0); 592 SvIV_set (sv_result, 0);
620 /* FALLTHROUGH */ 593 /* FALLTHROUGH */
621 594
642 } 615 }
643 616
644 return !!SvTRUE (ERRSV); 617 return !!SvTRUE (ERRSV);
645} 618}
646 619
620static void
647static void req_destroy (aio_req req) 621req_destroy (aio_req req)
648{ 622{
649 if (req->self) 623 if (req->self)
650 { 624 {
651 sv_unmagic (req->self, PERL_MAGIC_ext); 625 sv_unmagic (req->self, PERL_MAGIC_ext);
652 SvREFCNT_dec (req->self); 626 SvREFCNT_dec (req->self);
653 } 627 }
654 628
655 SvREFCNT_dec (req->sv1); 629 SvREFCNT_dec (req->sv1);
656 SvREFCNT_dec (req->sv2); 630 SvREFCNT_dec (req->sv2);
631 SvREFCNT_dec (req->sv3);
632 SvREFCNT_dec (req->sv4);
657 SvREFCNT_dec (req->callback); 633 SvREFCNT_dec (req->callback);
658 634
659 Safefree (req); 635 free (req);
660} 636}
661 637
638static void
662static void req_cancel_subs (aio_req grp) 639req_cancel_subs (aio_req grp)
663{ 640{
664 if (grp->type != EIO_GROUP) 641 if (grp->type != EIO_GROUP)
665 return; 642 return;
666 643
667 SvREFCNT_dec (grp->sv2); 644 SvREFCNT_dec (grp->sv2);
668 grp->sv2 = 0; 645 grp->sv2 = 0;
669 646
670 eio_grp_cancel (grp); 647 eio_grp_cancel (grp);
671} 648}
672 649
650static void ecb_cold
673static void create_respipe (void) 651create_respipe (void)
674{ 652{
675 if (s_epipe_renew (&respipe)) 653 if (s_epipe_renew (&respipe))
676 croak ("IO::AIO: unable to initialize result pipe"); 654 croak ("IO::AIO: unable to initialize result pipe");
677} 655}
678 656
679static void poll_wait (void) 657static void
658poll_wait (void)
680{ 659{
681 while (eio_nreqs ()) 660 while (eio_nreqs ())
682 { 661 {
683 int size; 662 int size;
684 663
693 672
694 s_epipe_wait (&respipe); 673 s_epipe_wait (&respipe);
695 } 674 }
696} 675}
697 676
698static int poll_cb (void) 677static int
678poll_cb (void)
699{ 679{
700 for (;;) 680 for (;;)
701 { 681 {
702 int res = eio_poll (); 682 int res = eio_poll ();
703 683
721} 701}
722 702
723/*****************************************************************************/ 703/*****************************************************************************/
724 704
725#if !_POSIX_MAPPED_FILES 705#if !_POSIX_MAPPED_FILES
726# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 706# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS ()
727# define munmap(addr,length) (errno = ENOSYS, -1) 707# define munmap(addr,length) EIO_ENOSYS ()
728#endif 708#endif
729 709
730#if !_POSIX_MEMORY_PROTECTION 710#if !_POSIX_MEMORY_PROTECTION
731# define mprotect(addr,len,prot) (errno = ENOSYS, -1) 711# define mprotect(addr,len,prot) EIO_ENOSYS ()
732# define PROT_NONE 0 712# define PROT_NONE 0
733# define PROT_WRITE 0 713# define PROT_WRITE 0
734# define MAP_PRIVATE 0 714# define MAP_PRIVATE 0
735# define MAP_SHARED 0 715# define MAP_SHARED 0
736# define MAP_FIXED 0 716# define MAP_FIXED 0
737#endif 717#endif
738 718
739#define MMAP_MAGIC PERL_MAGIC_ext 719#define MMAP_MAGIC PERL_MAGIC_ext
740 720
721static int ecb_cold
741static int mmap_free (pTHX_ SV *sv, MAGIC *mg) 722mmap_free (pTHX_ SV *sv, MAGIC *mg)
742{ 723{
743 int old_errno = errno; 724 int old_errno = errno;
744 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 725 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
745 errno = old_errno; 726 errno = old_errno;
746 727
762 0, 0, 0, 0, mmap_free 743 0, 0, 0, 0, mmap_free
763}; 744};
764 745
765/*****************************************************************************/ 746/*****************************************************************************/
766 747
748static SV *
767static SV * get_cb (SV *cb_sv) 749get_cb (SV *cb_sv)
768{ 750{
769 SvGETMAGIC (cb_sv); 751 SvGETMAGIC (cb_sv);
770 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 752 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
771} 753}
772 754
755static aio_req ecb_noinline
756dreq (SV *callback)
757{
758 SV *cb_cv;
759 aio_req req;
760 int req_pri = next_pri;
761 next_pri = EIO_PRI_DEFAULT;
762
763 cb_cv = get_cb (callback);
764
765 req = calloc (sizeof (*req), 1);
766 if (!req)
767 croak ("out of memory during eio_req allocation");
768
769 req->callback = SvREFCNT_inc (cb_cv);
770 req->pri = req_pri;
771
772 return req;
773}
774
773#define dREQ \ 775#define dREQ \
774 SV *cb_cv; \ 776 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 777
788#define REQ_SEND \ 778#define REQ_SEND \
789 PUTBACK; \ 779 PUTBACK; \
790 req_submit (req); \ 780 req_submit (req); \
791 SPAGAIN; \ 781 SPAGAIN; \
792 \ 782 \
793 if (GIMME_V != G_VOID) \ 783 if (GIMME_V != G_VOID) \
794 XPUSHs (req_sv (req, aio_req_stash)); 784 XPUSHs (req_sv (req, aio_req_stash));
795 785
786ecb_inline void
787req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr)
788{
789 if (expect_false (SvROK (path)))
790 {
791 SV *rv = SvRV (path);
792 SV *wdob;
793
794 if (SvTYPE (rv) == SVt_PVAV && AvFILLp (rv) == 1)
795 {
796 path = AvARRAY (rv)[1];
797 wdob = AvARRAY (rv)[0];
798
799 if (SvOK (wdob))
800 {
801 *wd = SvAIO_WD (wdob);
802 *wdsv = SvREFCNT_inc_NN (SvRV (wdob));
803 }
804 else
805 *wd = EIO_INVALID_WD;
806 }
807 else if (SvTYPE (rv) == SVt_PVMG && SvSTASH (rv) == aio_wd_stash)
808 {
809 *wd = (aio_wd)(long)SvIVX (rv);
810 *wdsv = SvREFCNT_inc_NN (rv);
811 *ptr = ".";
812 return; /* path set to "." */
813 }
814 else
815 croak ("IO::AIO: pathname arguments must be specified as a string, an IO::AIO::WD object or a [IO::AIO::WD, path] pair");
816 }
817
818 *pathsv = newSVsv (path);
819 *ptr = SvPVbyte_nolen (*pathsv);
820}
821
822static void ecb_noinline
823req_set_path1 (aio_req req, SV *path)
824{
825 req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1);
826}
827
828static void ecb_noinline
829req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path)
830{
831 SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path;
832
833 switch (SvTYPE (rv))
834 {
835 case SVt_PVIO:
836 case SVt_PVLV:
837 case SVt_PVGV:
838 req->type = type_fh;
839 req->sv1 = newSVsv (fh_or_path);
840 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
841 break;
842
843 default:
844 req->type = type_path;
845 req_set_path1 (req, fh_or_path);
846 break;
847 }
848}
849
850XS(boot_IO__AIO) ecb_cold;
851
796MODULE = IO::AIO PACKAGE = IO::AIO 852MODULE = IO::AIO PACKAGE = IO::AIO
797 853
798PROTOTYPES: ENABLE 854PROTOTYPES: ENABLE
799 855
800BOOT: 856BOOT:
804 IV iv; 860 IV iv;
805 } *civ, const_iv[] = { 861 } *civ, const_iv[] = {
806# define const_niv(name, value) { # name, (IV) value }, 862# define const_niv(name, value) { # name, (IV) value },
807# define const_iv(name) { # name, (IV) name }, 863# define const_iv(name) { # name, (IV) name },
808# define const_eio(name) { # name, (IV) EIO_ ## name }, 864# define const_eio(name) { # name, (IV) EIO_ ## name },
865
866 /* you have to re-run ./gendef0 after adding/Removing any constants here */
867
868 const_iv (ENOSYS)
809 const_iv (EXDEV) 869 const_iv (EXDEV)
810 const_iv (ENOSYS) 870 const_iv (EBADR)
871
811 const_iv (O_RDONLY) 872 const_iv (O_RDONLY)
812 const_iv (O_WRONLY) 873 const_iv (O_WRONLY)
813 const_iv (O_RDWR) 874 const_iv (O_RDWR)
814 const_iv (O_CREAT) 875 const_iv (O_CREAT)
815 const_iv (O_TRUNC) 876 const_iv (O_TRUNC)
883 const_iv (MAP_LOCKED) 944 const_iv (MAP_LOCKED)
884 const_iv (MAP_NORESERVE) 945 const_iv (MAP_NORESERVE)
885 const_iv (MAP_POPULATE) 946 const_iv (MAP_POPULATE)
886 const_iv (MAP_NONBLOCK) 947 const_iv (MAP_NONBLOCK)
887 948
949 const_iv (FIEMAP_FLAG_SYNC)
950 const_iv (FIEMAP_FLAG_XATTR)
951 const_iv (FIEMAP_FLAGS_COMPAT)
952 const_iv (FIEMAP_EXTENT_LAST)
953 const_iv (FIEMAP_EXTENT_UNKNOWN)
954 const_iv (FIEMAP_EXTENT_DELALLOC)
955 const_iv (FIEMAP_EXTENT_ENCODED)
956 const_iv (FIEMAP_EXTENT_DATA_ENCRYPTED)
957 const_iv (FIEMAP_EXTENT_NOT_ALIGNED)
958 const_iv (FIEMAP_EXTENT_DATA_INLINE)
959 const_iv (FIEMAP_EXTENT_DATA_TAIL)
960 const_iv (FIEMAP_EXTENT_UNWRITTEN)
961 const_iv (FIEMAP_EXTENT_MERGED)
962 const_iv (FIEMAP_EXTENT_SHARED)
963
964 const_iv (SPLICE_F_MOVE)
965 const_iv (SPLICE_F_NONBLOCK)
966 const_iv (SPLICE_F_MORE)
967 const_iv (SPLICE_F_GIFT)
968
969 const_iv (SEEK_DATA)
970 const_iv (SEEK_HOLE)
971
972 /* libeio constants */
973 const_eio (SEEK_SET)
974 const_eio (SEEK_CUR)
975 const_eio (SEEK_END)
976
888 const_eio (MCL_FUTURE) 977 const_eio (MCL_FUTURE)
889 const_eio (MCL_CURRENT) 978 const_eio (MCL_CURRENT)
890 979
891 const_eio (MS_ASYNC) 980 const_eio (MS_ASYNC)
892 const_eio (MS_INVALIDATE) 981 const_eio (MS_INVALIDATE)
897 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) 986 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE)
898 const_eio (SYNC_FILE_RANGE_WRITE) 987 const_eio (SYNC_FILE_RANGE_WRITE)
899 const_eio (SYNC_FILE_RANGE_WAIT_AFTER) 988 const_eio (SYNC_FILE_RANGE_WAIT_AFTER)
900 989
901 const_eio (FALLOC_FL_KEEP_SIZE) 990 const_eio (FALLOC_FL_KEEP_SIZE)
991 const_eio (FALLOC_FL_PUNCH_HOLE)
902 992
903 const_eio (READDIR_DENTS) 993 const_eio (READDIR_DENTS)
904 const_eio (READDIR_DIRS_FIRST) 994 const_eio (READDIR_DIRS_FIRST)
905 const_eio (READDIR_STAT_ORDER) 995 const_eio (READDIR_STAT_ORDER)
906 const_eio (READDIR_FOUND_UNKNOWN) 996 const_eio (READDIR_FOUND_UNKNOWN)
917 }; 1007 };
918 1008
919 aio_stash = gv_stashpv ("IO::AIO" , 1); 1009 aio_stash = gv_stashpv ("IO::AIO" , 1);
920 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); 1010 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1);
921 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); 1011 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1);
1012 aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1);
922 1013
923 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 1014 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
924 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 1015 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
925 1016
926 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 1017 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
973 PROTOTYPE: $ 1064 PROTOTYPE: $
974 CODE: 1065 CODE:
975 max_outstanding = maxreqs; 1066 max_outstanding = maxreqs;
976 1067
977void 1068void
1069aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef)
1070 PPCODE:
1071{
1072 dREQ;
1073
1074 req->type = EIO_WD_OPEN;
1075 req_set_path1 (req, pathname);
1076
1077 REQ_SEND;
1078}
1079
1080void
978aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) 1081aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
979 PPCODE: 1082 PPCODE:
980{ 1083{
981 dREQ; 1084 dREQ;
982 1085
983 req->type = EIO_OPEN; 1086 req->type = EIO_OPEN;
984 req->sv1 = newSVsv (pathname); 1087 req_set_path1 (req, pathname);
985 req->ptr1 = SvPVbyte_nolen (req->sv1);
986 req->int1 = flags; 1088 req->int1 = flags;
987 req->int2 = mode; 1089 req->int2 = mode;
988 1090
989 REQ_SEND; 1091 REQ_SEND;
990} 1092}
1002 1104
1003 req->type = ix; 1105 req->type = ix;
1004 req->sv1 = newSVsv (fh); 1106 req->sv1 = newSVsv (fh);
1005 req->int1 = fd; 1107 req->int1 = fd;
1006 1108
1007 REQ_SEND (req); 1109 REQ_SEND;
1008} 1110}
1009 1111
1010void 1112void
1011aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 1113aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef)
1012 PPCODE: 1114 PPCODE:
1019 req->int1 = fd; 1121 req->int1 = fd;
1020 req->offs = offset; 1122 req->offs = offset;
1021 req->size = nbytes; 1123 req->size = nbytes;
1022 req->int2 = flags; 1124 req->int2 = flags;
1023 1125
1024 REQ_SEND (req); 1126 REQ_SEND;
1025} 1127}
1026 1128
1027void 1129void
1028aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) 1130aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef)
1029 PPCODE: 1131 PPCODE:
1036 req->int1 = fd; 1138 req->int1 = fd;
1037 req->int2 = mode; 1139 req->int2 = mode;
1038 req->offs = offset; 1140 req->offs = offset;
1039 req->size = len; 1141 req->size = len;
1040 1142
1041 REQ_SEND (req); 1143 REQ_SEND;
1042} 1144}
1043 1145
1044void 1146void
1045aio_close (SV *fh, SV *callback=&PL_sv_undef) 1147aio_close (SV *fh, SV *callback=&PL_sv_undef)
1046 PPCODE: 1148 PPCODE:
1070 req->type = EIO_DUP2; 1172 req->type = EIO_DUP2;
1071 req->int1 = close_fd; 1173 req->int1 = close_fd;
1072 req->sv2 = newSVsv (fh); 1174 req->sv2 = newSVsv (fh);
1073 req->int2 = fd; 1175 req->int2 = fd;
1074 1176
1075 REQ_SEND (req); 1177 REQ_SEND;
1178}
1179
1180void
1181aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef)
1182 PPCODE:
1183{
1184 int fd = s_fileno_croak (fh, 0);
1185 dREQ;
1186
1187 req->type = EIO_SEEK;
1188 req->sv1 = newSVsv (fh);
1189 req->int1 = fd;
1190 req->offs = SvVAL64 (offset);
1191 req->int2 = whence;
1192
1193 REQ_SEND;
1076} 1194}
1077 1195
1078void 1196void
1079aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 1197aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
1080 ALIAS: 1198 ALIAS:
1101 } 1219 }
1102 else 1220 else
1103 { 1221 {
1104 /* read: check type and grow scalar as necessary */ 1222 /* read: check type and grow scalar as necessary */
1105 SvUPGRADE (data, SVt_PV); 1223 SvUPGRADE (data, SVt_PV);
1224 if (SvLEN (data) >= SvCUR (data))
1106 svptr = SvGROW (data, len + dataoffset + 1); 1225 svptr = SvGROW (data, len + dataoffset + 1);
1226 else if (SvCUR (data) < len + dataoffset)
1227 croak ("length + dataoffset outside of scalar, and cannot grow");
1107 } 1228 }
1108 1229
1109 { 1230 {
1110 dREQ; 1231 dREQ;
1111 1232
1127 REQ_SEND; 1248 REQ_SEND;
1128 } 1249 }
1129} 1250}
1130 1251
1131void 1252void
1132aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1253aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1133 ALIAS: 1254 ALIAS:
1134 aio_readlink = EIO_READLINK 1255 aio_readlink = EIO_READLINK
1135 aio_realpath = EIO_REALPATH 1256 aio_realpath = EIO_REALPATH
1136 PPCODE: 1257 PPCODE:
1137{ 1258{
1138 dREQ; 1259 dREQ;
1139 1260
1140 req->type = ix; 1261 req->type = ix;
1141 req->sv1 = newSVsv (path); 1262 req_set_path1 (req, pathname);
1142 req->ptr1 = SvPVbyte_nolen (req->sv1);
1143 1263
1144 REQ_SEND; 1264 REQ_SEND;
1145} 1265}
1146 1266
1147void 1267void
1187 aio_statvfs = EIO_STATVFS 1307 aio_statvfs = EIO_STATVFS
1188 PPCODE: 1308 PPCODE:
1189{ 1309{
1190 dREQ; 1310 dREQ;
1191 1311
1192 req->sv1 = newSVsv (fh_or_path); 1312 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1193
1194 if (SvPOK (req->sv1))
1195 {
1196 req->type = ix;
1197 req->ptr1 = SvPVbyte_nolen (req->sv1);
1198 }
1199 else
1200 {
1201 req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT;
1202 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1203 }
1204 1313
1205 REQ_SEND; 1314 REQ_SEND;
1206} 1315}
1207 1316
1208UV 1317UV
1227{ 1336{
1228 dREQ; 1337 dREQ;
1229 1338
1230 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; 1339 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.;
1231 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; 1340 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.;
1232 req->sv1 = newSVsv (fh_or_path); 1341 req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path);
1233
1234 if (SvPOK (req->sv1))
1235 {
1236 req->type = EIO_UTIME;
1237 req->ptr1 = SvPVbyte_nolen (req->sv1);
1238 }
1239 else
1240 {
1241 req->type = EIO_FUTIME;
1242 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1243 }
1244 1342
1245 REQ_SEND; 1343 REQ_SEND;
1246} 1344}
1247 1345
1248void 1346void
1249aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) 1347aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef)
1250 PPCODE: 1348 PPCODE:
1251{ 1349{
1252 dREQ; 1350 dREQ;
1253 1351
1254 req->sv1 = newSVsv (fh_or_path);
1255 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; 1352 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
1256 1353 req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path);
1257 if (SvPOK (req->sv1))
1258 {
1259 req->type = EIO_TRUNCATE;
1260 req->ptr1 = SvPVbyte_nolen (req->sv1);
1261 }
1262 else
1263 {
1264 req->type = EIO_FTRUNCATE;
1265 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1266 }
1267 1354
1268 REQ_SEND; 1355 REQ_SEND;
1269} 1356}
1270 1357
1271void 1358void
1272aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) 1359aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef)
1273 ALIAS:
1274 aio_chmod = EIO_CHMOD
1275 aio_mkdir = EIO_MKDIR
1276 PPCODE: 1360 PPCODE:
1277{ 1361{
1278 dREQ; 1362 dREQ;
1279 1363
1280 req->int2 = mode; 1364 req->int2 = mode;
1281 req->sv1 = newSVsv (fh_or_path); 1365 req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path);
1282
1283 if (SvPOK (req->sv1))
1284 {
1285 req->type = ix;
1286 req->ptr1 = SvPVbyte_nolen (req->sv1);
1287 }
1288 else
1289 {
1290 req->type = EIO_FCHMOD;
1291 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1292 }
1293 1366
1294 REQ_SEND; 1367 REQ_SEND;
1295} 1368}
1296 1369
1297void 1370void
1300{ 1373{
1301 dREQ; 1374 dREQ;
1302 1375
1303 req->int2 = SvOK (uid) ? SvIV (uid) : -1; 1376 req->int2 = SvOK (uid) ? SvIV (uid) : -1;
1304 req->int3 = SvOK (gid) ? SvIV (gid) : -1; 1377 req->int3 = SvOK (gid) ? SvIV (gid) : -1;
1305 req->sv1 = newSVsv (fh_or_path); 1378 req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path);
1306
1307 if (SvPOK (req->sv1))
1308 {
1309 req->type = EIO_CHOWN;
1310 req->ptr1 = SvPVbyte_nolen (req->sv1);
1311 }
1312 else
1313 {
1314 req->type = EIO_FCHOWN;
1315 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1316 }
1317 1379
1318 REQ_SEND; 1380 REQ_SEND;
1319} 1381}
1320 1382
1321void 1383void
1323 PPCODE: 1385 PPCODE:
1324{ 1386{
1325 dREQ; 1387 dREQ;
1326 1388
1327 req->type = EIO_READDIR; 1389 req->type = EIO_READDIR;
1328 req->sv1 = newSVsv (pathname);
1329 req->ptr1 = SvPVbyte_nolen (req->sv1);
1330 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; 1390 req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1;
1331 1391
1332 if (flags & EIO_READDIR_DENTS) 1392 if (flags & EIO_READDIR_DENTS)
1333 req->int1 |= EIO_READDIR_CUSTOM2; 1393 req->int1 |= EIO_READDIR_CUSTOM2;
1334 1394
1395 req_set_path1 (req, pathname);
1396
1335 REQ_SEND; 1397 REQ_SEND;
1398}
1399
1400void
1401aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef)
1402 PPCODE:
1403{
1404 dREQ;
1405
1406 req->type = EIO_MKDIR;
1407 req->int2 = mode;
1408 req_set_path1 (req, pathname);
1409
1410 REQ_SEND;
1336} 1411}
1337 1412
1338void 1413void
1339aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) 1414aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef)
1340 ALIAS: 1415 ALIAS:
1344 PPCODE: 1419 PPCODE:
1345{ 1420{
1346 dREQ; 1421 dREQ;
1347 1422
1348 req->type = ix; 1423 req->type = ix;
1349 req->sv1 = newSVsv (pathname); 1424 req_set_path1 (req, pathname);
1350 req->ptr1 = SvPVbyte_nolen (req->sv1);
1351 1425
1352 REQ_SEND; 1426 REQ_SEND;
1353} 1427}
1354 1428
1355void 1429void
1358 aio_link = EIO_LINK 1432 aio_link = EIO_LINK
1359 aio_symlink = EIO_SYMLINK 1433 aio_symlink = EIO_SYMLINK
1360 aio_rename = EIO_RENAME 1434 aio_rename = EIO_RENAME
1361 PPCODE: 1435 PPCODE:
1362{ 1436{
1437 eio_wd wd2 = 0;
1363 dREQ; 1438 dREQ;
1364 1439
1365 req->type = ix; 1440 req->type = ix;
1366 req->sv1 = newSVsv (oldpath); 1441 req_set_path1 (req, oldpath);
1367 req->ptr1 = SvPVbyte_nolen (req->sv1); 1442 req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2);
1368 req->sv2 = newSVsv (newpath); 1443 req->int3 = (long)wd2;
1369 req->ptr2 = SvPVbyte_nolen (req->sv2);
1370 1444
1371 REQ_SEND; 1445 REQ_SEND;
1372} 1446}
1373 1447
1374void 1448void
1376 PPCODE: 1450 PPCODE:
1377{ 1451{
1378 dREQ; 1452 dREQ;
1379 1453
1380 req->type = EIO_MKNOD; 1454 req->type = EIO_MKNOD;
1381 req->sv1 = newSVsv (pathname);
1382 req->ptr1 = SvPVbyte_nolen (req->sv1);
1383 req->int2 = (mode_t)mode; 1455 req->int2 = (mode_t)mode;
1384 req->offs = dev; 1456 req->offs = dev;
1457 req_set_path1 (req, pathname);
1385 1458
1386 REQ_SEND; 1459 REQ_SEND;
1387} 1460}
1388 1461
1389void 1462void
1456 1529
1457 req->type = EIO_MLOCKALL; 1530 req->type = EIO_MLOCKALL;
1458 req->int1 = flags; 1531 req->int1 = flags;
1459 1532
1460 REQ_SEND; 1533 REQ_SEND;
1534}
1535
1536void
1537aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef)
1538 PPCODE:
1539{
1540 int fd = s_fileno_croak (fh, 0);
1541 dREQ;
1542
1543 req->type = EIO_CUSTOM;
1544 req->sv1 = newSVsv (fh);
1545 req->int1 = fd;
1546
1547 req->feed = fiemap;
1548#if HAVE_FIEMAP
1549 /* keep our fingers crossed that the next two types are 64 bit */
1550 req->offs = start;
1551 req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL;
1552 req->int2 = flags;
1553 req->int3 = SvOK (count) ? SvIV (count) : -1;
1554#endif
1555
1556 REQ_SEND;
1461} 1557}
1462 1558
1463void 1559void
1464aio_busy (double delay, SV *callback=&PL_sv_undef) 1560aio_busy (double delay, SV *callback=&PL_sv_undef)
1465 PPCODE: 1561 PPCODE:
1597 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1693 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1598 OUTPUT: 1694 OUTPUT:
1599 RETVAL 1695 RETVAL
1600 1696
1601void 1697void
1602mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) 1698mmap (SV *scalar, size_t length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0)
1603 PPCODE: 1699 PPCODE:
1604 sv_unmagic (scalar, MMAP_MAGIC); 1700 sv_unmagic (scalar, MMAP_MAGIC);
1605{ 1701{
1606 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; 1702 int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1;
1607 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1703 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1640 ALIAS: 1736 ALIAS:
1641 mprotect = 1 1737 mprotect = 1
1642 CODE: 1738 CODE:
1643{ 1739{
1644 STRLEN svlen; 1740 STRLEN svlen;
1645 void *addr = SvPVbyte (scalar, svlen); 1741 void *addr = SvPVbyte (scalar, svlen);
1646 size_t len = SvUV (length); 1742 size_t len = SvUV (length);
1647 1743
1648 if (offset < 0) 1744 if (offset < 0)
1649 offset += svlen; 1745 offset += svlen;
1650 1746
1686 addr = (void *)(((intptr_t)addr) + offset); 1782 addr = (void *)(((intptr_t)addr) + offset);
1687 eio_page_align (&addr, &len); 1783 eio_page_align (&addr, &len);
1688#if _POSIX_MEMLOCK_RANGE 1784#if _POSIX_MEMLOCK_RANGE
1689 RETVAL = munlock (addr, len); 1785 RETVAL = munlock (addr, len);
1690#else 1786#else
1691 RETVAL = ((errno = ENOSYS), -1); 1787 RETVAL = EIO_ENOSYS ();
1692#endif 1788#endif
1693} 1789}
1694 OUTPUT: 1790 OUTPUT:
1695 RETVAL 1791 RETVAL
1696 1792
1698munlockall () 1794munlockall ()
1699 CODE: 1795 CODE:
1700#if _POSIX_MEMLOCK 1796#if _POSIX_MEMLOCK
1701 munlockall (); 1797 munlockall ();
1702#else 1798#else
1703 RETVAL = -1; 1799 RETVAL = EIO_ENOSYS ();
1704 errno = ENOSYS;
1705#endif 1800#endif
1706 OUTPUT: 1801 OUTPUT:
1802 RETVAL
1803
1804int
1805splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags)
1806 CODE:
1807{
1808#if HAVE_LINUX_SPLICE
1809 loff_t off_in_, off_out_;
1810 RETVAL = splice (
1811 rfh, SvOK (off_in ) ? (off_in_ = SvVAL64 (off_in )), &off_in_ : 0,
1812 wfh, SvOK (off_out) ? (off_out_ = SvVAL64 (off_out)), &off_out_ : 0,
1813 length, flags
1814 );
1815#else
1816 RETVAL = EIO_ENOSYS ();
1817#endif
1818}
1819 OUTPUT:
1820 RETVAL
1821
1822int
1823tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags)
1824 CODE:
1825#if HAVE_LINUX_SPLICE
1826 RETVAL = tee (rfh, wfh, length, flags);
1827#else
1828 RETVAL = EIO_ENOSYS ();
1829#endif
1830 OUTPUT:
1707 RETVAL 1831 RETVAL
1708 1832
1709void _on_next_submit (SV *cb) 1833void _on_next_submit (SV *cb)
1710 CODE: 1834 CODE:
1711 SvREFCNT_dec (on_next_submit); 1835 SvREFCNT_dec (on_next_submit);
1712 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 1836 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1713 1837
1714PROTOTYPES: DISABLE 1838PROTOTYPES: DISABLE
1715 1839
1840MODULE = IO::AIO PACKAGE = IO::AIO::WD
1841
1842BOOT:
1843{
1844 newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD ));
1845 newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD));
1846}
1847
1848void
1849DESTROY (SV *self)
1850 CODE:
1851{
1852 aio_wd wd = SvAIO_WD (self);
1853#if HAVE_AT
1854 {
1855 SV *callback = &PL_sv_undef;
1856 dREQ; /* clobbers next_pri :/ */
1857 next_pri = req->pri; /* restore next_pri */
1858 req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */
1859 req->type = EIO_WD_CLOSE;
1860 req->wd = wd;
1861 REQ_SEND;
1862 }
1863#else
1864 eio_wd_close_sync (wd);
1865#endif
1866}
1867
1716MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1868MODULE = IO::AIO PACKAGE = IO::AIO::REQ
1717 1869
1718void 1870void
1719cancel (aio_req_ornot req) 1871cancel (aio_req_ornot req)
1720 CODE: 1872 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines