--- IO-AIO/AIO.xs 2012/07/30 16:44:12 1.220 +++ IO-AIO/AIO.xs 2017/06/23 23:50:25 1.249 @@ -21,7 +21,12 @@ # include #endif -#if __linux__ +/* the incompetent fool that created musl keeps __linux__, refuses + * to implement any linux standard apis, and also has no way to test + * for his broken iplementation. don't complain to me if this fails + * for you. + */ +#if __linux__ && (defined __GLIBC__ || defined __UCLIBC__) # include # ifdef FS_IOC_FIEMAP # include @@ -143,6 +148,7 @@ #endif /* defines all sorts of constants to 0 unless they are already defined */ +/* also provides const_iv_ and const_niv_ macros for them */ #include "def0.h" #ifndef makedev @@ -155,7 +161,7 @@ # define minor(dev) ((dev) & 0xff) #endif -#ifndef PAGESIZE +#if PAGESIZE <= 0 # define PAGESIZE sysconf (_SC_PAGESIZE) #endif @@ -191,7 +197,7 @@ fiemap->fm_flags = req->int2; fiemap->fm_extent_count = count; - if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) + if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap) < 0) return; if (req->int3 >= 0 /* not autosizing */ @@ -200,7 +206,7 @@ goto done; /* else we have to loop - - * it would be tempting (atcually I tried that first) to just query the + * it would be tempting (actually I tried that first) to just query the * number of extents needed, but linux often feels like not returning all * extents, without telling us it left any out. this complicates * this quite a bit. @@ -220,9 +226,12 @@ incmap->fm_flags = fiemap->fm_flags; incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent); - if (ioctl (req->int1, FS_IOC_FIEMAP, incmap)) + if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0) return; + if (!incmap->fm_mapped_extents) + goto done; + count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents; fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); errno = ENOMEM; @@ -303,7 +312,7 @@ static SV * newSVaio_wd (aio_wd wd) { - return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); + return sv_bless (newRV_noinc (newSViv ((intptr_t)wd)), aio_wd_stash); } static aio_req @@ -334,6 +343,31 @@ return (aio_wd)(long)SvIVX (SvRV (sv)); } +static SV * +newmortalFH (int fd, int flags) +{ + if (fd < 0) + return &PL_sv_undef; + + GV *gv = (GV *)sv_newmortal (); + char sym[64]; + int symlen; + + symlen = snprintf (sym, sizeof (sym), "fd#%d", fd); + gv_init (gv, aio_stash, sym, symlen, 0); + + symlen = snprintf ( + sym, + sizeof (sym), + "%s&=%d", + flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", + fd + ); + + return do_open (gv, sym, symlen, 0, 0, 0, 0) + ? (SV *)gv : &PL_sv_undef; +} + static void aio_grp_feed (aio_req grp) { @@ -469,34 +503,7 @@ break; case EIO_OPEN: - { - /* convert fd to fh */ - SV *fh = &PL_sv_undef; - - if (req->result >= 0) - { - GV *gv = (GV *)sv_newmortal (); - int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); - char sym [64]; - int symlen; - - symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); - gv_init (gv, aio_stash, sym, symlen, 0); - - symlen = snprintf ( - sym, - sizeof (sym), - "%s&=%d", - flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", - (int)req->result - ); - - if (do_open (gv, sym, symlen, 0, 0, 0, 0)) - fh = (SV *)gv; - } - - PUSHs (fh); - } + PUSHs (newmortalFH (req->result, req->int1 & (O_RDONLY | O_WRONLY | O_RDWR))); break; case EIO_STATVFS: @@ -509,6 +516,11 @@ { EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); HV *hv = newHV (); + /* POSIX requires fsid to be unsigned long, but AIX in its infinite wisdom + * chooses to make it a struct. + */ + unsigned long fsid = 0; + memcpy (&fsid, &f->f_fsid, sizeof (unsigned long) < sizeof (f->f_fsid) ? sizeof (unsigned long) : sizeof (f->f_fsid)); rv = sv_2mortal (newRV_noinc ((SV *)hv)); @@ -520,7 +532,7 @@ hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); - hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); + hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (fsid ), 0); hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); } @@ -695,14 +707,14 @@ { int size; - X_LOCK (reslock); - size = res_queue.size; - X_UNLOCK (reslock); + X_LOCK (EIO_POOL->reslock); + size = EIO_POOL->res_queue.size; + X_UNLOCK (EIO_POOL->reslock); if (size) return; - etp_maybe_start_thread (); + etp_maybe_start_thread (EIO_POOL); s_epipe_wait (&respipe); } @@ -743,11 +755,6 @@ #if !_POSIX_MEMORY_PROTECTION # define mprotect(addr,len,prot) EIO_ENOSYS () -# define PROT_NONE 0 -# define PROT_WRITE 0 -# define MAP_PRIVATE 0 -# define MAP_SHARED 0 -# define MAP_FIXED 0 #endif #define MMAP_MAGIC PERL_MAGIC_ext @@ -897,12 +904,30 @@ # define const_iv(name) { # name, (IV) name }, # define const_eio(name) { # name, (IV) EIO_ ## name }, - /* you have to re-run ./gendef0 after adding/Removing any constants here */ - + /* you have to re-run ./gendef0 after adding/removing any constants here */ + /* the first block can be undef if missing */ const_iv (ENOSYS) const_iv (EXDEV) const_iv (EBADR) + /* for lseek */ + const_iv (SEEK_DATA) + const_iv (SEEK_HOLE) + + const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) + const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) + const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) + const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) + const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) + const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) + + const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) + const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) + const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) + const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) + const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) + + /* the second block will be 0 when missing */ const_iv (O_RDONLY) const_iv (O_WRONLY) const_iv (O_RDWR) @@ -925,6 +950,8 @@ const_iv (O_DSYNC) const_iv (O_RSYNC) const_iv (O_SYNC) + const_iv (O_PATH) + const_iv (O_TMPFILE) const_iv (O_TTY_INIT) const_iv (S_IFIFO) @@ -937,19 +964,6 @@ const_iv (S_IFSOCK) const_iv (S_IFMT) - const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) - const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) - const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) - const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) - const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) - const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) - - const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) - const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) - const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) - const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) - const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) - const_iv (ST_RDONLY) const_iv (ST_NOSUID) const_iv (ST_NODEV) @@ -968,17 +982,83 @@ const_iv (PROT_READ) const_iv (PROT_WRITE) - /*const_iv (MAP_FIXED)*/ const_iv (MAP_PRIVATE) const_iv (MAP_SHARED) + const_iv (MAP_FIXED) const_iv (MAP_ANONYMOUS) /* linuxish */ - const_iv (MAP_HUGETLB) const_iv (MAP_LOCKED) const_iv (MAP_NORESERVE) const_iv (MAP_POPULATE) const_iv (MAP_NONBLOCK) + const_iv (MAP_GROWSDOWN) + const_iv (MAP_32BIT) + const_iv (MAP_HUGETLB) + const_iv (MAP_STACK) + + const_iv (F_DUPFD_CLOEXEC) + + const_iv (F_OFD_GETLK) + const_iv (F_OFD_SETLK) + const_iv (F_OFD_GETLKW) + + const_iv (FIFREEZE) + const_iv (FITHAW) + const_iv (FITRIM) + const_iv (FICLONE) + const_iv (FICLONERANGE) + const_iv (FIDEDUPERANGE) + + const_iv (FS_IOC_GETFLAGS) + const_iv (FS_IOC_SETFLAGS) + const_iv (FS_IOC_GETVERSION) + const_iv (FS_IOC_SETVERSION) + const_iv (FS_IOC_FIEMAP) + const_iv (FS_IOC_FSGETXATTR) + const_iv (FS_IOC_FSSETXATTR) + const_iv (FS_IOC_SET_ENCRYPTION_POLICY) + const_iv (FS_IOC_GET_ENCRYPTION_PWSALT) + const_iv (FS_IOC_GET_ENCRYPTION_POLICY) + + const_iv (FS_KEY_DESCRIPTOR_SIZE) + + const_iv (FS_SECRM_FL) + const_iv (FS_UNRM_FL) + const_iv (FS_COMPR_FL) + const_iv (FS_SYNC_FL) + const_iv (FS_IMMUTABLE_FL) + const_iv (FS_APPEND_FL) + const_iv (FS_NODUMP_FL) + const_iv (FS_NOATIME_FL) + const_iv (FS_DIRTY_FL) + const_iv (FS_COMPRBLK_FL) + const_iv (FS_NOCOMP_FL) + const_iv (FS_ENCRYPT_FL) + const_iv (FS_BTREE_FL) + const_iv (FS_INDEX_FL) + const_iv (FS_JOURNAL_DATA_FL) + const_iv (FS_NOTAIL_FL) + const_iv (FS_DIRSYNC_FL) + const_iv (FS_TOPDIR_FL) + const_iv (FS_FL_USER_MODIFIABLE) + + const_iv (FS_XFLAG_REALTIME) + const_iv (FS_XFLAG_PREALLOC) + const_iv (FS_XFLAG_IMMUTABLE) + const_iv (FS_XFLAG_APPEND) + const_iv (FS_XFLAG_SYNC) + const_iv (FS_XFLAG_NOATIME) + const_iv (FS_XFLAG_NODUMP) + const_iv (FS_XFLAG_RTINHERIT) + const_iv (FS_XFLAG_PROJINHERIT) + const_iv (FS_XFLAG_NOSYMLINKS) + const_iv (FS_XFLAG_EXTSIZE) + const_iv (FS_XFLAG_EXTSZINHERIT) + const_iv (FS_XFLAG_NODEFRAG) + const_iv (FS_XFLAG_FILESTREAM) + const_iv (FS_XFLAG_DAX) + const_iv (FS_XFLAG_HASATTR) const_iv (FIEMAP_FLAG_SYNC) const_iv (FIEMAP_FLAG_XATTR) @@ -1000,10 +1080,7 @@ const_iv (SPLICE_F_MORE) const_iv (SPLICE_F_GIFT) - const_iv (SEEK_DATA) - const_iv (SEEK_HOLE) - - /* libeio constants */ + /* these are libeio constants, and are independent of gendef0 */ const_eio (SEEK_SET) const_eio (SEEK_CUR) const_eio (SEEK_END) @@ -1023,6 +1100,14 @@ const_eio (FALLOC_FL_KEEP_SIZE) const_eio (FALLOC_FL_PUNCH_HOLE) + const_eio (FALLOC_FL_COLLAPSE_RANGE) + const_eio (FALLOC_FL_ZERO_RANGE) + const_eio (FALLOC_FL_INSERT_RANGE) + const_eio (FALLOC_FL_UNSHARE_RANGE) + + const_eio (RENAME_NOREPLACE) + const_eio (RENAME_EXCHANGE) + const_eio (RENAME_WHITEOUT) const_eio (READDIR_DENTS) const_eio (READDIR_DIRS_FIRST) @@ -1100,7 +1185,7 @@ max_outstanding = maxreqs; void -aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef) +aio_wd (SV8 *pathname, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1112,7 +1197,7 @@ } void -aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) +aio_open (SV8 *pathname, int flags, int mode, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1126,14 +1211,14 @@ } void -aio_fsync (SV *fh, SV *callback=&PL_sv_undef) +aio_fsync (SV *fh, SV *callback = &PL_sv_undef) ALIAS: aio_fsync = EIO_FSYNC aio_fdatasync = EIO_FDATASYNC aio_syncfs = EIO_SYNCFS PPCODE: { - int fd = s_fileno_croak (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; req->type = ix; @@ -1144,10 +1229,10 @@ } void -aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) +aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback = &PL_sv_undef) PPCODE: { - int fd = s_fileno_croak (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; req->type = EIO_SYNC_FILE_RANGE; @@ -1161,10 +1246,10 @@ } void -aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) +aio_allocate (SV *fh, int mode, off_t offset, size_t len, SV *callback = &PL_sv_undef) PPCODE: { - int fd = s_fileno_croak (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; req->type = EIO_FALLOCATE; @@ -1178,11 +1263,11 @@ } void -aio_close (SV *fh, SV *callback=&PL_sv_undef) +aio_close (SV *fh, SV *callback = &PL_sv_undef) PPCODE: { static int close_fd = -1; /* dummy fd to close fds via dup2 */ - int fd = s_fileno_croak (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; if (expect_false (close_fd < 0)) @@ -1212,7 +1297,7 @@ } void -aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) +aio_seek (SV *fh, SV *offset, int whence, SV *callback = &PL_sv_undef) PPCODE: { int fd = s_fileno_croak (fh, 0); @@ -1228,7 +1313,7 @@ } void -aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) +aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback = &PL_sv_undef) ALIAS: aio_read = EIO_READ aio_write = EIO_WRITE @@ -1254,9 +1339,8 @@ else { /* read: check type and grow scalar as necessary */ - SvUPGRADE (data, SVt_PV); - if (SvLEN (data) >= SvCUR (data)) - svptr = SvGROW (data, len + dataoffset + 1); + if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) + svptr = sv_grow (data, len + dataoffset + 1); else if (SvCUR (data) < len + dataoffset) croak ("length + dataoffset outside of scalar, and cannot grow"); } @@ -1284,7 +1368,47 @@ } void -aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef) +aio_ioctl (SV *fh, unsigned long request, SV8 *arg, SV *callback = &PL_sv_undef) + ALIAS: + aio_ioctl = EIO_IOCTL + aio_fcntl = EIO_FCNTL + PPCODE: +{ + int fd = s_fileno_croak (fh, 0); + char *svptr; + + if (SvPOK (arg) || !SvNIOK (arg)) + { + STRLEN svlen; + /* perl uses IOCPARM_LEN for fcntl, so we do, too */ +#ifdef IOCPARM_LEN + STRLEN need = IOCPARM_LEN (request); +#else + STRLEN need = 256; +#endif + + if (svlen < need) + svptr = SvGROW (arg, need); + } + else + svptr = (char *)SvIV (arg); + + { + dREQ; + + req->type = ix; + req->sv1 = newSVsv (fh); + req->int1 = fd; + req->int2 = (long)request; + req->sv2 = SvREFCNT_inc (arg); + req->ptr2 = svptr; + + REQ_SEND; + } +} + +void +aio_readlink (SV8 *pathname, SV *callback = &PL_sv_undef) ALIAS: aio_readlink = EIO_READLINK aio_realpath = EIO_REALPATH @@ -1299,11 +1423,11 @@ } void -aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) +aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback = &PL_sv_undef) PPCODE: { - int ifd = s_fileno_croak (in_fh , 0); - int ofd = s_fileno_croak (out_fh, 1); + int ifd = s_fileno_croak (in_fh , 0); + int ofd = s_fileno_croak (out_fh, 1); dREQ; req->type = EIO_SENDFILE; @@ -1318,10 +1442,10 @@ } void -aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) +aio_readahead (SV *fh, off_t offset, size_t length, SV *callback = &PL_sv_undef) PPCODE: { - int fd = s_fileno_croak (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; req->type = EIO_READAHEAD; @@ -1334,7 +1458,7 @@ } void -aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) +aio_stat (SV8 *fh_or_path, SV *callback = &PL_sv_undef) ALIAS: aio_stat = EIO_STAT aio_lstat = EIO_LSTAT @@ -1353,7 +1477,7 @@ ALIAS: minor = 1 CODE: - RETVAL = ix ? major (dev) : minor (dev); + RETVAL = ix ? minor (dev) : major (dev); OUTPUT: RETVAL @@ -1365,7 +1489,7 @@ RETVAL void -aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) +aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1378,7 +1502,7 @@ } void -aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) +aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1390,7 +1514,7 @@ } void -aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) +aio_chmod (SV8 *fh_or_path, int mode, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1402,7 +1526,7 @@ } void -aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback=&PL_sv_undef) +aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1415,7 +1539,7 @@ } void -aio_readdirx (SV8 *pathname, IV flags, SV *callback=&PL_sv_undef) +aio_readdirx (SV8 *pathname, IV flags, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1432,7 +1556,7 @@ } void -aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef) +aio_mkdir (SV8 *pathname, int mode, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1445,7 +1569,7 @@ } void -aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) +aio_unlink (SV8 *pathname, SV *callback = &PL_sv_undef) ALIAS: aio_unlink = EIO_UNLINK aio_rmdir = EIO_RMDIR @@ -1461,7 +1585,7 @@ } void -aio_link (SV8 *oldpath, SV8 *newpath, SV *callback=&PL_sv_undef) +aio_link (SV8 *oldpath, SV8 *newpath, SV *callback = &PL_sv_undef) ALIAS: aio_link = EIO_LINK aio_symlink = EIO_SYMLINK @@ -1480,7 +1604,23 @@ } void -aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback=&PL_sv_undef) +aio_rename2 (SV8 *oldpath, SV8 *newpath, int flags = 0, SV *callback = &PL_sv_undef) + PPCODE: +{ + eio_wd wd2 = 0; + dREQ; + + req->type = EIO_RENAME; + req_set_path1 (req, oldpath); + req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2); + req->int2 = flags; + req->int3 = (long)wd2; + + REQ_SEND; +} + +void +aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1494,7 +1634,7 @@ } void -aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) +aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = -1, SV *callback = &PL_sv_undef) ALIAS: aio_mtouch = EIO_MTOUCH aio_msync = EIO_MSYNC @@ -1504,6 +1644,9 @@ char *svptr = SvPVbyte (data, svlen); UV len = SvUV (length); + if (flags < 0) + flags = ix == EIO_MSYNC ? EIO_MS_SYNC : 0; + if (offset < 0) offset += svlen; @@ -1527,7 +1670,7 @@ } void -aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) +aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback = &PL_sv_undef) PPCODE: { STRLEN svlen; @@ -1556,7 +1699,7 @@ } void -aio_mlockall (IV flags, SV *callback=&PL_sv_undef) +aio_mlockall (IV flags, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1568,7 +1711,7 @@ } void -aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) +aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback = &PL_sv_undef) PPCODE: { int fd = s_fileno_croak (fh, 0); @@ -1591,7 +1734,7 @@ } void -aio_busy (double delay, SV *callback=&PL_sv_undef) +aio_busy (double delay, SV *callback = &PL_sv_undef) PPCODE: { dREQ; @@ -1603,19 +1746,22 @@ } void -aio_group (SV *callback=&PL_sv_undef) +aio_group (SV *callback = &PL_sv_undef) PPCODE: { dREQ; req->type = EIO_GROUP; + PUTBACK; req_submit (req); + SPAGAIN; + XPUSHs (req_sv (req, aio_grp_stash)); } void -aio_nop (SV *callback=&PL_sv_undef) +aio_nop (SV *callback = &PL_sv_undef) ALIAS: aio_nop = EIO_NOP aio_sync = EIO_SYNC @@ -1629,7 +1775,7 @@ } int -aioreq_pri (int pri = 0) +aioreq_pri (int pri = NO_INIT) CODE: RETVAL = next_pri; if (items > 0) @@ -1729,7 +1875,7 @@ RETVAL void -mmap (SV *scalar, size_t length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) +mmap (SV *scalar, STRLEN length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) PPCODE: sv_unmagic (scalar, MMAP_MAGIC); { @@ -1766,14 +1912,14 @@ sv_unmagic (scalar, MMAP_MAGIC); int -madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) +madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) ALIAS: mprotect = 1 CODE: { STRLEN svlen; void *addr = SvPVbyte (scalar, svlen); - size_t len = SvUV (length); + STRLEN len = SvUV (length); if (offset < 0) offset += svlen; @@ -1797,11 +1943,11 @@ RETVAL int -munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) +munlock (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef) CODE: { STRLEN svlen; - void *addr = SvPVbyte (scalar, svlen); + void *addr = SvPVbyte (scalar, svlen); size_t len = SvUV (length); if (offset < 0) @@ -1864,6 +2010,47 @@ OUTPUT: RETVAL +int +pipesize (aio_rfd rfh, int new_size = -1) + PROTOTYPE: $;$ + CODE: +#if defined(F_SETPIPE_SZ) && defined(F_GETPIPE_SZ) + if (new_size >= 0) + RETVAL = fcntl (rfh, F_SETPIPE_SZ, new_size); + else + RETVAL = fcntl (rfh, F_GETPIPE_SZ); +#else + errno = ENOSYS; + RETVAL = -1; +#endif + OUTPUT: + RETVAL + +void +pipe2 (int flags = 0) + PROTOTYPE: ;$ + PPCODE: +{ + int fd[2]; + int res; + + if (flags) +#if HAVE_PIPE2 + res = pipe2 (fd, flags); +#else + res = (errno = ENOSYS, -1); +#endif + else + res = pipe (fd); + + if (!res) + { + EXTEND (SP, 2); + PUSHs (newmortalFH (fd[0], O_RDONLY)); + PUSHs (newmortalFH (fd[1], O_WRONLY)); + } +} + void _on_next_submit (SV *cb) CODE: SvREFCNT_dec (on_next_submit); @@ -1907,7 +2094,7 @@ eio_cancel (req); void -cb (aio_req_ornot req, SV *callback=&PL_sv_undef) +cb (aio_req_ornot req, SV *callback = NO_INIT) PPCODE: { if (GIMME_V != G_VOID) @@ -1915,7 +2102,7 @@ if (items > 1) { - SV *cb_cv =get_cb (callback); + SV *cb_cv = get_cb (callback); SvREFCNT_dec (req->callback); req->callback = SvREFCNT_inc (cb_cv); @@ -1982,7 +2169,7 @@ eio_grp_limit (grp, limit); void -feed (aio_req grp, SV *callback=&PL_sv_undef) +feed (aio_req grp, SV *callback = &PL_sv_undef) CODE: { SvREFCNT_dec (grp->sv2);