--- IO-AIO/AIO.xs 2015/06/13 00:06:13 1.232 +++ IO-AIO/AIO.xs 2016/02/23 19:42:43 1.239 @@ -147,6 +147,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 @@ -341,6 +342,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) { @@ -476,34 +502,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: @@ -707,14 +706,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); } @@ -755,11 +754,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 @@ -909,12 +903,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) @@ -937,6 +949,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) @@ -949,19 +963,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) @@ -980,17 +981,20 @@ 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 (FIEMAP_FLAG_SYNC) const_iv (FIEMAP_FLAG_XATTR) @@ -1012,10 +1016,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) @@ -1297,6 +1298,46 @@ } void +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 + 1); + } + 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 @@ -1896,6 +1937,31 @@ 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);