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.175 by root, Wed Dec 1 04:43:12 2010 UTC vs.
Revision 1.194 by root, Fri Jul 29 08:35:36 2011 UTC

11#include <stddef.h> 11#include <stddef.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <errno.h> 13#include <errno.h>
14#include <sys/types.h> 14#include <sys/types.h>
15#include <sys/stat.h> 15#include <sys/stat.h>
16#include <sys/statvfs.h>
17#include <limits.h> 16#include <limits.h>
18#include <fcntl.h> 17#include <fcntl.h>
19#include <sched.h> 18#include <sched.h>
20 19
21#if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES 20#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
22# include <sys/mman.h> 21# include <sys/mman.h>
23#endif 22#endif
24 23
25/* perl namespace pollution */ 24/* perl namespace pollution */
26#undef VERSION 25#undef VERSION
27
28#ifdef _WIN32
29
30# define EIO_STRUCT_DIRENT Direntry_t
31# undef malloc
32# undef free
33
34// perl overrides all those nice win32 functions
35# undef open
36# undef read
37# undef write
38# undef send
39# undef recv
40# undef stat
41# undef fstat
42# define lstat stat
43# undef truncate
44# undef ftruncate
45# undef open
46# undef close
47# undef unlink
48# undef rmdir
49# undef rename
50# undef lseek
51
52# define chown(a,b,c) (errno = ENOSYS, -1)
53# define fchown(a,b,c) (errno = ENOSYS, -1)
54# define fchmod(a,b) (errno = ENOSYS, -1)
55# define symlink(a,b) (errno = ENOSYS, -1)
56# define readlink(a,b,c) (errno = ENOSYS, -1)
57# define mknod(a,b,c) (errno = ENOSYS, -1)
58# define truncate(a,b) (errno = ENOSYS, -1)
59# define ftruncate(fd,o) chsize ((fd), (o))
60# define fsync(fd) _commit (fd)
61# define opendir(fd) (errno = ENOSYS, 0)
62# define readdir(fd) (errno = ENOSYS, -1)
63# define closedir(fd) (errno = ENOSYS, -1)
64# define mkdir(a,b) mkdir (a)
65
66#else
67
68# include <sys/time.h>
69# include <sys/select.h>
70# include <unistd.h>
71# include <utime.h>
72# include <signal.h>
73# define EIO_STRUCT_DIRENT struct dirent
74
75#endif
76 26
77/* perl stupidly overrides readdir and maybe others */ 27/* perl stupidly overrides readdir and maybe others */
78/* with thread-unsafe versions, imagine that :( */ 28/* with thread-unsafe versions, imagine that :( */
79#undef readdir 29#undef readdir
80#undef opendir 30#undef opendir
81#undef closedir 31#undef closedir
32
33#ifdef _WIN32
34
35 // perl overrides all those nice libc functions
36
37 #undef malloc
38 #undef free
39 #undef open
40 #undef read
41 #undef write
42 #undef send
43 #undef recv
44 #undef stat
45 #undef lstat
46 #undef fstat
47 #undef truncate
48 #undef ftruncate
49 #undef open
50 #undef link
51 #undef close
52 #undef unlink
53 #undef mkdir
54 #undef rmdir
55 #undef rename
56 #undef lseek
57 #undef opendir
58 #undef readdir
59 #undef closedir
60 #undef chmod
61 #undef fchmod
62 #undef dup
63 #undef dup2
64 #undef abort
65 #undef pipe
66
67#else
68
69 #include <sys/time.h>
70 #include <sys/select.h>
71 #include <unistd.h>
72 #include <utime.h>
73 #include <signal.h>
74
75#endif
82 76
83#define EIO_STRUCT_STAT Stat_t 77#define EIO_STRUCT_STAT Stat_t
84 78
85/* use NV for 32 bit perls as it allows larger offsets */ 79/* use NV for 32 bit perls as it allows larger offsets */
86#if IVSIZE >= 8 80#if IVSIZE >= 8
118 STRLEN stroffset; \ 112 STRLEN stroffset; \
119 SV *self; 113 SV *self;
120 114
121#define EIO_NO_WRAPPERS 1 115#define EIO_NO_WRAPPERS 1
122 116
117#include "libeio/config.h"
123#include "libeio/eio.h" 118#include "libeio/eio.h"
119
120static int req_invoke (eio_req *req);
121#define EIO_FINISH(req) req_invoke (req)
122static void req_destroy (eio_req *grp);
123#define EIO_DESTROY(req) req_destroy (req)
124
125#include "libeio/eio.c"
126
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
124 172
125#ifndef POSIX_FADV_NORMAL 173#ifndef POSIX_FADV_NORMAL
126# define POSIX_FADV_NORMAL 0 174# define POSIX_FADV_NORMAL 0
127#endif 175#endif
128#ifndef POSIX_FADV_SEQUENTIAL 176#ifndef POSIX_FADV_SEQUENTIAL
176#endif 224#endif
177#ifndef PROT_EXEC 225#ifndef PROT_EXEC
178# define PROT_EXEC 0 226# define PROT_EXEC 0
179#endif 227#endif
180 228
229#ifndef ST_RDONLY
230# define ST_RDONLY 0
231#endif
232#ifndef ST_NOSUID
233# define ST_NOSUID 0
234#endif
181#ifndef ST_NODEV 235#ifndef ST_NODEV
182# define ST_NODEV 0 236# define ST_NODEV 0
183#endif 237#endif
184#ifndef ST_NOEXEC 238#ifndef ST_NOEXEC
185# define ST_NOEXEC 0 239# define ST_NOEXEC 0
205#ifndef ST_NODIRATIME 259#ifndef ST_NODIRATIME
206# define ST_NODIRATIME 0 260# define ST_NODIRATIME 0
207#endif 261#endif
208#ifndef ST_RELATIME 262#ifndef ST_RELATIME
209# define ST_RELATIME 0 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
210#endif 289#endif
211 290
212#ifndef MAP_ANONYMOUS 291#ifndef MAP_ANONYMOUS
213# ifdef MAP_ANON 292# ifdef MAP_ANON
214# define MAP_ANONYMOUS MAP_ANON 293# define MAP_ANONYMOUS MAP_ANON
230#endif 309#endif
231#ifndef MAP_NONBLOCK 310#ifndef MAP_NONBLOCK
232# define MAP_NONBLOCK 0 311# define MAP_NONBLOCK 0
233#endif 312#endif
234 313
314#ifndef makedev
315# define makedev(maj,min) (((maj) << 8) | (min))
316#endif
317#ifndef major
318# define major(dev) ((dev) >> 8)
319#endif
320#ifndef minor
321# define minor(dev) ((dev) & 0xff)
322#endif
323
235#ifndef PAGESIZE 324#ifndef PAGESIZE
236# define PAGESIZE sysconf (_SC_PAGESIZE) 325# define PAGESIZE sysconf (_SC_PAGESIZE)
237#endif 326#endif
238
239static int req_invoke (eio_req *req);
240#define EIO_FINISH(req) req_invoke (req)
241static void req_destroy (eio_req *grp);
242#define EIO_DESTROY(req) req_destroy (req)
243 327
244enum { 328enum {
245 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 329 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
246}; 330};
247
248#include "libeio/eio.c"
249 331
250typedef eio_req *aio_req; 332typedef eio_req *aio_req;
251typedef eio_req *aio_req_ornot; 333typedef eio_req *aio_req_ornot;
252 334
253static SV *on_next_submit; 335static SV *on_next_submit;
352 /* do not recreate the result IV from scratch each time */ 434 /* do not recreate the result IV from scratch each time */
353 if (expect_true (sv_result_cache)) 435 if (expect_true (sv_result_cache))
354 { 436 {
355 sv_result = sv_result_cache; sv_result_cache = 0; 437 sv_result = sv_result_cache; sv_result_cache = 0;
356 SvIV_set (sv_result, req->result); 438 SvIV_set (sv_result, req->result);
439 SvIOK_only (sv_result);
357 } 440 }
358 else 441 else
359 { 442 {
360 sv_result = newSViv (req->result); 443 sv_result = newSViv (req->result);
361 SvREADONLY_on (sv_result); 444 SvREADONLY_on (sv_result);
458 case EIO_STATVFS: 541 case EIO_STATVFS:
459 case EIO_FSTATVFS: 542 case EIO_FSTATVFS:
460 { 543 {
461 SV *rv = &PL_sv_undef; 544 SV *rv = &PL_sv_undef;
462 545
546#ifndef _WIN32
463 if (req->result >= 0) 547 if (req->result >= 0)
464 { 548 {
465 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); 549 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req);
466 HV *hv = newHV (); 550 HV *hv = newHV ();
467 551
477 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); 561 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0);
478 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); 562 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0);
479 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); 563 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0);
480 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); 564 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0);
481 } 565 }
566#endif
482 567
483 PUSHs (rv); 568 PUSHs (rv);
484 } 569 }
485 570
486 break; 571 break;
502 case EIO_NOP: 587 case EIO_NOP:
503 case EIO_BUSY: 588 case EIO_BUSY:
504 break; 589 break;
505 590
506 case EIO_READLINK: 591 case EIO_READLINK:
592 case EIO_REALPATH:
507 if (req->result > 0) 593 if (req->result > 0)
508 PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); 594 PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result)));
509 break; 595 break;
510 596
511 case EIO_STAT: 597 case EIO_STAT:
512 case EIO_LSTAT: 598 case EIO_LSTAT:
513 case EIO_FSTAT: 599 case EIO_FSTAT:
514 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; 600 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
515 PL_laststatval = req->result; 601 PL_laststatval = req->result;
602 /* if compilation fails here then perl's Stat_t is not struct _stati64 */
516 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); 603 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
517 PUSHs (sv_result); 604 PUSHs (sv_result);
518 break; 605 break;
519 606
520 case EIO_READ: 607 case EIO_READ:
525 SvSETMAGIC (req->sv2); 612 SvSETMAGIC (req->sv2);
526 PUSHs (sv_result); 613 PUSHs (sv_result);
527 } 614 }
528 break; 615 break;
529 616
530 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ 617 case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */
531 if (req->result > 0) 618 if (req->result > 0)
532 SvIV_set (sv_result, 0); 619 SvIV_set (sv_result, 0);
533 /* FALLTHROUGH */ 620 /* FALLTHROUGH */
534 621
535 default: 622 default:
572 Safefree (req); 659 Safefree (req);
573} 660}
574 661
575static void req_cancel_subs (aio_req grp) 662static void req_cancel_subs (aio_req grp)
576{ 663{
577 aio_req sub;
578
579 if (grp->type != EIO_GROUP) 664 if (grp->type != EIO_GROUP)
580 return; 665 return;
581 666
582 SvREFCNT_dec (grp->sv2); 667 SvREFCNT_dec (grp->sv2);
583 grp->sv2 = 0; 668 grp->sv2 = 0;
584 669
585 eio_grp_cancel (grp); 670 eio_grp_cancel (grp);
586} 671}
587 672
588static void
589create_respipe (void) 673static void create_respipe (void)
590{ 674{
591 if (s_epipe_renew (&respipe)) 675 if (s_epipe_renew (&respipe))
592 croak ("IO::AIO: unable to initialize result pipe"); 676 croak ("IO::AIO: unable to initialize result pipe");
593} 677}
594 678
625 709
626 poll_wait (); 710 poll_wait ();
627 } 711 }
628} 712}
629 713
630static void atfork_child (void) 714static void ecb_cold
715reinit (void)
631{ 716{
632 create_respipe (); 717 create_respipe ();
718
719 if (eio_init (want_poll, done_poll) < 0)
720 croak ("IO::AIO: unable to initialise eio library");
633} 721}
634 722
635/*****************************************************************************/ 723/*****************************************************************************/
636 724
637#if !_POSIX_MAPPED_FILES 725#if !_POSIX_MAPPED_FILES
638# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) 726# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1)
639# define munmap(addr,length) (errno = ENOSYS, -1) 727# define munmap(addr,length) (errno = ENOSYS, -1)
728#endif
729
730#if !_POSIX_MEMORY_PROTECTION
640# define mprotect(addr,len,prot) (errno = ENOSYS, -1) 731# define mprotect(addr,len,prot) (errno = ENOSYS, -1)
641# define PROT_NONE 0 732# define PROT_NONE 0
642# define PROT_WRITE 0 733# define PROT_WRITE 0
643# define MAP_PRIVATE 0 734# define MAP_PRIVATE 0
644# define MAP_SHARED 0 735# define MAP_SHARED 0
645# define MAP_FIXED 0 736# define MAP_FIXED 0
646#endif 737#endif
647 738
648#define MMAP_MAGIC PERL_MAGIC_ext 739#define MMAP_MAGIC PERL_MAGIC_ext
649 740
650static int
651mmap_free (pTHX_ SV *sv, MAGIC *mg) 741static int mmap_free (pTHX_ SV *sv, MAGIC *mg)
652{ 742{
653 int old_errno = errno; 743 int old_errno = errno;
654 munmap (mg->mg_ptr, (size_t)mg->mg_obj); 744 munmap (mg->mg_ptr, (size_t)mg->mg_obj);
655 errno = old_errno; 745 errno = old_errno;
656 746
672 0, 0, 0, 0, mmap_free 762 0, 0, 0, 0, mmap_free
673}; 763};
674 764
675/*****************************************************************************/ 765/*****************************************************************************/
676 766
677static SV *
678get_cb (SV *cb_sv) 767static SV * get_cb (SV *cb_sv)
679{ 768{
680 SvGETMAGIC (cb_sv); 769 SvGETMAGIC (cb_sv);
681 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; 770 return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0;
682} 771}
683 772
724 const_iv (O_RDWR) 813 const_iv (O_RDWR)
725 const_iv (O_CREAT) 814 const_iv (O_CREAT)
726 const_iv (O_TRUNC) 815 const_iv (O_TRUNC)
727 const_iv (O_EXCL) 816 const_iv (O_EXCL)
728 const_iv (O_APPEND) 817 const_iv (O_APPEND)
729#ifndef _WIN32 818
819 const_iv (O_ASYNC)
820 const_iv (O_DIRECT)
821 const_iv (O_NOATIME)
822
823 const_iv (O_CLOEXEC)
824 const_iv (O_NOCTTY)
825 const_iv (O_NOFOLLOW)
826 const_iv (O_NONBLOCK)
827 const_iv (O_EXEC)
828 const_iv (O_SEARCH)
829 const_iv (O_DIRECTORY)
830 const_iv (O_DSYNC)
831 const_iv (O_RSYNC)
832 const_iv (O_SYNC)
833 const_iv (O_TTY_INIT)
834
730 const_iv (S_IFIFO) 835 const_iv (S_IFIFO)
731#endif 836 const_iv (S_IFCHR)
837 const_iv (S_IFBLK)
838 const_iv (S_IFLNK)
839 const_iv (S_IFREG)
840 const_iv (S_IFDIR)
841 const_iv (S_IFWHT)
842 const_iv (S_IFSOCK)
843 const_iv (S_IFMT)
844
732 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) 845 const_niv (FADV_NORMAL , POSIX_FADV_NORMAL)
733 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) 846 const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL)
734 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) 847 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
735 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) 848 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
736 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) 849 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
783 896
784 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) 897 const_eio (SYNC_FILE_RANGE_WAIT_BEFORE)
785 const_eio (SYNC_FILE_RANGE_WRITE) 898 const_eio (SYNC_FILE_RANGE_WRITE)
786 const_eio (SYNC_FILE_RANGE_WAIT_AFTER) 899 const_eio (SYNC_FILE_RANGE_WAIT_AFTER)
787 900
901 const_eio (FALLOC_FL_KEEP_SIZE)
902
788 const_eio (READDIR_DENTS) 903 const_eio (READDIR_DENTS)
789 const_eio (READDIR_DIRS_FIRST) 904 const_eio (READDIR_DIRS_FIRST)
790 const_eio (READDIR_STAT_ORDER) 905 const_eio (READDIR_STAT_ORDER)
791 const_eio (READDIR_FOUND_UNKNOWN) 906 const_eio (READDIR_FOUND_UNKNOWN)
792 907
803 918
804 aio_stash = gv_stashpv ("IO::AIO" , 1); 919 aio_stash = gv_stashpv ("IO::AIO" , 1);
805 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); 920 aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1);
806 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); 921 aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1);
807 922
808 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 923 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
809 newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); 924 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
810 925
811 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 926 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
812 927
813 create_respipe (); 928 reinit ();
814
815 if (eio_init (want_poll, done_poll) < 0)
816 croak ("IO::AIO: unable to initialise eio library");
817
818 /* atfork child called in fifo order, so before eio's handler */
819 X_THREAD_ATFORK (0, 0, atfork_child);
820} 929}
821 930
822void 931void
932reinit ()
933 PROTOTYPE:
934
935void
823max_poll_reqs (int nreqs) 936max_poll_reqs (unsigned int nreqs)
824 PROTOTYPE: $ 937 PROTOTYPE: $
825 CODE: 938 CODE:
826 eio_set_max_poll_reqs (nreqs); 939 eio_set_max_poll_reqs (nreqs);
827 940
828void 941void
830 PROTOTYPE: $ 943 PROTOTYPE: $
831 CODE: 944 CODE:
832 eio_set_max_poll_time (nseconds); 945 eio_set_max_poll_time (nseconds);
833 946
834void 947void
835min_parallel (int nthreads) 948min_parallel (unsigned int nthreads)
836 PROTOTYPE: $ 949 PROTOTYPE: $
837 CODE: 950 CODE:
838 eio_set_min_parallel (nthreads); 951 eio_set_min_parallel (nthreads);
839 952
840void 953void
841max_parallel (int nthreads) 954max_parallel (unsigned int nthreads)
842 PROTOTYPE: $ 955 PROTOTYPE: $
843 CODE: 956 CODE:
844 eio_set_max_parallel (nthreads); 957 eio_set_max_parallel (nthreads);
845 958
846void 959void
847max_idle (int nthreads) 960max_idle (unsigned int nthreads)
848 PROTOTYPE: $ 961 PROTOTYPE: $
849 CODE: 962 CODE:
850 eio_set_max_idle (nthreads); 963 eio_set_max_idle (nthreads);
851 964
852void 965void
966idle_timeout (unsigned int seconds)
967 PROTOTYPE: $
968 CODE:
969 eio_set_idle_timeout (seconds);
970
971void
853max_outstanding (int maxreqs) 972max_outstanding (unsigned int maxreqs)
854 PROTOTYPE: $ 973 PROTOTYPE: $
855 CODE: 974 CODE:
856 max_outstanding = maxreqs; 975 max_outstanding = maxreqs;
857 976
858void 977void
873void 992void
874aio_fsync (SV *fh, SV *callback=&PL_sv_undef) 993aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
875 ALIAS: 994 ALIAS:
876 aio_fsync = EIO_FSYNC 995 aio_fsync = EIO_FSYNC
877 aio_fdatasync = EIO_FDATASYNC 996 aio_fdatasync = EIO_FDATASYNC
997 aio_syncfs = EIO_SYNCFS
878 PPCODE: 998 PPCODE:
879{ 999{
880 int fd = s_fileno_croak (fh, 0); 1000 int fd = s_fileno_croak (fh, 0);
881 dREQ; 1001 dREQ;
882 1002
903 1023
904 REQ_SEND (req); 1024 REQ_SEND (req);
905} 1025}
906 1026
907void 1027void
1028aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef)
1029 PPCODE:
1030{
1031 int fd = s_fileno_croak (fh, 0);
1032 dREQ;
1033
1034 req->type = EIO_FALLOCATE;
1035 req->sv1 = newSVsv (fh);
1036 req->int1 = fd;
1037 req->int2 = mode;
1038 req->offs = offset;
1039 req->size = len;
1040
1041 REQ_SEND (req);
1042}
1043
1044void
908aio_close (SV *fh, SV *callback=&PL_sv_undef) 1045aio_close (SV *fh, SV *callback=&PL_sv_undef)
909 PPCODE: 1046 PPCODE:
910{ 1047{
911 static int close_pipe = -1; /* dummy fd to close fds via dup2 */ 1048 static int close_fd = -1; /* dummy fd to close fds via dup2 */
912 int fd = s_fileno_croak (fh, 0); 1049 int fd = s_fileno_croak (fh, 0);
913 dREQ; 1050 dREQ;
914 1051
915 if (close_pipe < 0) 1052 if (expect_false (close_fd < 0))
916 { 1053 {
917 int pipefd [2]; 1054 int pipefd [2];
918 1055
1056 if (
1057#ifdef _WIN32
1058 _pipe (pipefd, 1, _O_BINARY) < 0
1059#else
919 if (pipe (pipefd) < 0 1060 pipe (pipefd) < 0
920 || close (pipefd [1]) < 0
921 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) 1061 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0
1062#endif
1063 || close (pipefd [1]) < 0
1064 )
922 abort (); /*D*/ 1065 abort (); /*D*/
923 1066
924 close_pipe = pipefd [0]; 1067 close_fd = pipefd [0];
925 } 1068 }
926 1069
927 req->type = EIO_DUP2; 1070 req->type = EIO_DUP2;
928 req->int1 = close_pipe; 1071 req->int1 = close_fd;
929 req->sv2 = newSVsv (fh); 1072 req->sv2 = newSVsv (fh);
930 req->int2 = fd; 1073 req->int2 = fd;
931 1074
932 REQ_SEND (req); 1075 REQ_SEND (req);
933} 1076}
985 } 1128 }
986} 1129}
987 1130
988void 1131void
989aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) 1132aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
1133 ALIAS:
1134 aio_readlink = EIO_READLINK
1135 aio_realpath = EIO_REALPATH
990 PPCODE: 1136 PPCODE:
991{ 1137{
992 SV *data;
993 dREQ; 1138 dREQ;
994 1139
995 req->type = EIO_READLINK; 1140 req->type = ix;
996 req->sv1 = newSVsv (path); 1141 req->sv1 = newSVsv (path);
997 req->ptr1 = SvPVbyte_nolen (req->sv1); 1142 req->ptr1 = SvPVbyte_nolen (req->sv1);
998 1143
999 REQ_SEND; 1144 REQ_SEND;
1000} 1145}
1057 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); 1202 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1058 } 1203 }
1059 1204
1060 REQ_SEND; 1205 REQ_SEND;
1061} 1206}
1207
1208UV
1209major (UV dev)
1210 ALIAS:
1211 minor = 1
1212 CODE:
1213 RETVAL = ix ? major (dev) : minor (dev);
1214 OUTPUT:
1215 RETVAL
1216
1217UV
1218makedev (UV maj, UV min)
1219 CODE:
1220 RETVAL = makedev (maj, min);
1221 OUTPUT:
1222 RETVAL
1062 1223
1063void 1224void
1064aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) 1225aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef)
1065 PPCODE: 1226 PPCODE:
1066{ 1227{
1428 CODE: 1589 CODE:
1429 RETVAL = posix_fadvise (fh, offset, length, advice); 1590 RETVAL = posix_fadvise (fh, offset, length, advice);
1430 OUTPUT: 1591 OUTPUT:
1431 RETVAL 1592 RETVAL
1432 1593
1433ssize_t 1594IV
1434sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1595sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1435 CODE: 1596 CODE:
1436 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); 1597 RETVAL = eio_sendfile_sync (ofh, ifh, offset, count);
1437 OUTPUT: 1598 OUTPUT:
1438 RETVAL 1599 RETVAL
1522 if (!SvOK (length) || len + offset > svlen) 1683 if (!SvOK (length) || len + offset > svlen)
1523 len = svlen - offset; 1684 len = svlen - offset;
1524 1685
1525 addr = (void *)(((intptr_t)addr) + offset); 1686 addr = (void *)(((intptr_t)addr) + offset);
1526 eio_page_align (&addr, &len); 1687 eio_page_align (&addr, &len);
1527#if _POSIX_MEMLOCK 1688#if _POSIX_MEMLOCK_RANGE
1528 RETVAL = munlock (addr, len); 1689 RETVAL = munlock (addr, len);
1529#else 1690#else
1530 RETVAL = ((errno = ENOSYS), -1); 1691 RETVAL = ((errno = ENOSYS), -1);
1531#endif 1692#endif
1532} 1693}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines