--- IO-AIO/AIO.xs 2009/06/03 12:24:49 1.140 +++ IO-AIO/AIO.xs 2010/01/10 23:44:02 1.163 @@ -6,15 +6,22 @@ #include "perl.h" #include "XSUB.h" +#include "schmorp.h" + #include #include #include #include #include +#include #include #include #include +#if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES +# include +#endif + /* perl namespace pollution */ #undef VERSION @@ -77,9 +84,13 @@ /* use NV for 32 bit perls as it allows larger offsets */ #if IVSIZE >= 8 +# define VAL64 IV # define SvVAL64 SvIV +# define newSVval64 newSViv #else +# define VAL64 NV # define SvVAL64 SvNV +# define newSVval64 newSVnv #endif /*****************************************************************************/ @@ -95,11 +106,11 @@ /*****************************************************************************/ -static HV *stash; typedef SV SV8; /* byte-sv, used for argument-checking */ +typedef int aio_rfd; /* read file desriptor */ +typedef int aio_wfd; /* write file descriptor */ -#define AIO_REQ_KLASS "IO::AIO::REQ" -#define AIO_GRP_KLASS "IO::AIO::GRP" +static HV *aio_stash, *aio_req_stash, *aio_grp_stash; #define EIO_REQ_MEMBERS \ SV *callback; \ @@ -111,6 +122,91 @@ #include "libeio/eio.h" +#ifndef POSIX_FADV_NORMAL +# define POSIX_FADV_NORMAL 0 +# define NO_FADVISE 1 +#endif +#ifndef POSIX_FADV_SEQUENTIAL +# define POSIX_FADV_SEQUENTIAL 0 +#endif +#ifndef POSIX_FADV_RANDOM +# define POSIX_FADV_RANDOM 0 +#endif +#ifndef POSIX_FADV_NOREUSE +# define POSIX_FADV_NOREUSE 0 +#endif +#ifndef POSIX_FADV_WILLNEED +# define POSIX_FADV_WILLNEED 0 +#endif +#ifndef POSIX_FADV_DONTNEED +# define POSIX_FADV_DONTNEED 0 +#endif + +#ifndef ST_NODEV +# define ST_NODEV 0 +#endif +#ifndef ST_NOEXEC +# define ST_NOEXEC 0 +#endif +#ifndef ST_SYNCHRONOUS +# define ST_SYNCHRONOUS 0 +#endif +#ifndef ST_MANDLOCK +# define ST_MANDLOCK 0 +#endif +#ifndef ST_WRITE +# define ST_WRITE 0 +#endif +#ifndef ST_APPEND +# define ST_APPEND 0 +#endif +#ifndef ST_IMMUTABLE +# define ST_IMMUTABLE 0 +#endif +#ifndef ST_NOATIME +# define ST_NOATIME 0 +#endif +#ifndef ST_NODIRATIME +# define ST_NODIRATIME 0 +#endif +#ifndef ST_RELATIME +# define ST_RELATIME 0 +#endif + +#ifndef MCL_CURRENT +# define MCL_CURRENT 0 +#endif +#ifndef MCL_FUTURE +# define MCL_FUTURE 0 +#endif + +#ifndef MAP_ANONYMOUS +# ifdef MAP_ANON +# define MAP_ANONYMOUS MAP_ANON +# else +# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ +# endif +#endif +#ifndef MAP_HUGETLB +# define MAP_HUGETLB 0 +#endif +#ifndef MAP_LOCKED +# define MAP_LOCKED 0 +#endif +#ifndef MAP_NORESERVE +# define MAP_NORESERVE 0 +#endif +#ifndef MAP_POPULATE +# define MAP_POPULATE 0 +#endif +#ifndef MAP_NONBLOCK +# define MAP_NONBLOCK 0 +#endif + +#ifndef PAGESIZE +# define PAGESIZE sysconf (_SC_PAGESIZE) +#endif + static int req_invoke (eio_req *req); #define EIO_FINISH(req) req_invoke (req) static void req_destroy (eio_req *grp); @@ -129,7 +225,7 @@ static int next_pri = EIO_PRI_DEFAULT; static int max_outstanding; -static int respipe_osf [2], respipe [2] = { -1, -1 }; +static s_epipe respipe; static void req_destroy (aio_req req); static void req_cancel (aio_req req); @@ -137,19 +233,17 @@ static void want_poll (void) { /* write a dummy byte to the pipe so fh becomes ready */ - respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); + s_epipe_signal (&respipe); } static void done_poll (void) { /* read any signals sent by the worker threads */ - char buf [4]; - while (respipe_read (respipe [0], buf, 4) == 4) - ; + s_epipe_drain (&respipe); } /* must be called at most once */ -static SV *req_sv (aio_req req, const char *klass) +static SV *req_sv (aio_req req, HV *stash) { if (!req->self) { @@ -157,15 +251,18 @@ sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); } - return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); + return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); } static aio_req SvAIO_REQ (SV *sv) { MAGIC *mg; - if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) - croak ("object of class " AIO_REQ_KLASS " expected"); + if (!SvROK (sv) + || (SvSTASH (SvRV (sv)) != aio_grp_stash + && SvSTASH (SvRV (sv)) != aio_req_stash + && !sv_derived_from (sv, "IO::AIO::REQ"))) + croak ("object of class IO::AIO::REQ expected"); mg = mg_find (SvRV (sv), PERL_MAGIC_ext); @@ -181,7 +278,7 @@ ENTER; SAVETMPS; PUSHMARK (SP); - XPUSHs (req_sv (grp, AIO_GRP_KLASS)); + XPUSHs (req_sv (grp, aio_grp_stash)); PUTBACK; call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); SPAGAIN; @@ -230,23 +327,57 @@ if (req->result >= 0) { int i; - char *buf = req->ptr2; + char *names = (char *)req->ptr2; + eio_dirent *ent = (eio_dirent *)req->ptr1; /* might be 0 */ AV *av = newAV (); av_extend (av, req->result - 1); for (i = 0; i < req->result; ++i) { - SV *sv = newSVpv (buf, 0); - - av_store (av, i, sv); - buf += SvCUR (sv) + 1; + if (req->int1 & EIO_READDIR_DENTS) + { + SV *namesv = newSVpvn (names + ent->nameofs, ent->namelen); + + if (req->int1 & EIO_READDIR_CUSTOM2) + { + static SV *sv_type [EIO_DT_MAX + 1]; /* type sv cache */ + AV *avent = newAV (); + + av_extend (avent, 2); + + if (!sv_type [ent->type]) + { + sv_type [ent->type] = newSViv (ent->type); + SvREADONLY_on (sv_type [ent->type]); + } + + av_store (avent, 0, namesv); + av_store (avent, 1, SvREFCNT_inc (sv_type [ent->type])); + av_store (avent, 2, IVSIZE >= 8 ? newSVuv (ent->inode) : newSVnv (ent->inode)); + + av_store (av, i, newRV_noinc ((SV *)avent)); + } + else + av_store (av, i, namesv); + + ++ent; + } + else + { + SV *name = newSVpv (names, 0); + av_store (av, i, name); + names += SvCUR (name) + 1; + } } rv = sv_2mortal (newRV_noinc ((SV *)av)); } PUSHs (rv); + + if (req->int1 & EIO_READDIR_CUSTOM1) + XPUSHs (sv_2mortal (newSViv (req->int1 & ~(EIO_READDIR_CUSTOM1 | EIO_READDIR_CUSTOM2)))); } break; @@ -262,15 +393,15 @@ char sym [64]; int symlen; - symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result); - gv_init (gv, stash, sym, symlen, 0); + 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 ? ">" : "+<", - req->result + (int)req->result ); if (do_open (gv, sym, symlen, 0, 0, 0, 0)) @@ -281,6 +412,36 @@ } break; + case EIO_STATVFS: + case EIO_FSTATVFS: + { + SV *rv = &PL_sv_undef; + + if (req->result >= 0) + { + EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); + HV *hv = newHV (); + + rv = sv_2mortal (newRV_noinc ((SV *)hv)); + + hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); + hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); + hv_store (hv, "blocks" , sizeof ("blocks" ) - 1, newSVval64 (f->f_blocks ), 0); + hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); + hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); + 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, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); + hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); + } + + PUSHs (rv); + } + + break; + case EIO_GROUP: req->int1 = 2; /* mark group as finished */ @@ -376,54 +537,15 @@ eio_grp_cancel (grp); } -#ifdef USE_SOCKETS_AS_HANDLES -# define TO_SOCKET(x) (win32_get_osfhandle (x)) -#else -# define TO_SOCKET(x) (x) -#endif - static void create_respipe (void) { - int old_readfd = respipe [0]; - - if (respipe [1] >= 0) - respipe_close (TO_SOCKET (respipe [1])); - -#ifdef _WIN32 - if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) -#else - if (pipe (respipe)) -#endif - croak ("unable to initialize result pipe"); - - if (old_readfd >= 0) - { - if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) - croak ("unable to initialize result pipe(2)"); - - respipe_close (respipe [0]); - respipe [0] = old_readfd; - } - -#ifdef _WIN32 - int arg = 1; - if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) - || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) -#else - if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) - || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) -#endif - croak ("unable to initialize result pipe(3)"); - - respipe_osf [0] = TO_SOCKET (respipe [0]); - respipe_osf [1] = TO_SOCKET (respipe [1]); + if (s_epipe_renew (&respipe)) + croak ("IO::AIO: unable to initialize result pipe"); } static void poll_wait (void) { - fd_set rfd; - while (eio_nreqs ()) { int size; @@ -437,10 +559,7 @@ etp_maybe_start_thread (); - FD_ZERO (&rfd); - FD_SET (respipe [0], &rfd); - - PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); + s_epipe_wait (&respipe); } } @@ -465,22 +584,44 @@ create_respipe (); } -static SV * -get_cb (SV *cb_sv) +/*****************************************************************************/ + +#if !_POSIX_MAPPED_FILES +# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) +# define munmap(addr,length) (errno = ENOSYS, -1) +#endif + +#define MMAP_MAGIC PERL_MAGIC_ext + +static int +mmap_free (pTHX_ SV *sv, MAGIC *mg) { - HV *st; - GV *gvp; - CV *cv; + int old_errno = errno; + munmap (mg->mg_ptr, (size_t)mg->mg_obj); + errno = old_errno; + + mg->mg_obj = 0; /* just in case */ + + SvREADONLY_off (sv); + SvCUR_set (sv, 0); + SvLEN_set (sv, 0); + SvPVX (sv) = 0; + SvOK_off (sv); - if (!SvOK (cb_sv)) - return 0; + return 0; +} - cv = sv_2cv (cb_sv, &st, &gvp, 0); +static MGVTBL mmap_vtbl = { + 0, 0, 0, 0, mmap_free +}; - if (!cv) - croak ("IO::AIO callback must be undef or a CODE reference"); +/*****************************************************************************/ - return (SV *)cv; +static SV * +get_cb (SV *cb_sv) +{ + SvGETMAGIC (cb_sv); + return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; } #define dREQ \ @@ -504,18 +645,7 @@ SPAGAIN; \ \ if (GIMME_V != G_VOID) \ - XPUSHs (req_sv (req, AIO_REQ_KLASS)); - -static int -extract_fd (SV *fh, int wr) -{ - int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); - - if (fd < 0) - croak ("illegal fh argument, either not an OS file or read/write mode mismatch"); - - return fd; -} + XPUSHs (req_sv (req, aio_req_stash)); MODULE = IO::AIO PACKAGE = IO::AIO @@ -523,29 +653,104 @@ BOOT: { - stash = gv_stashpv ("IO::AIO", 1); - - newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); - newCONSTSUB (stash, "ENOSYS", newSViv (ENOSYS)); - newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); - newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); - newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); - newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); + static const struct { + const char *name; + IV iv; + } *civ, const_iv[] = { +# define const_niv(name, value) { # name, (IV) value }, +# define const_iv(name) { # name, (IV) name }, +# define const_eio(name) { # name, (IV) EIO_ ## name }, + const_iv (EXDEV) + const_iv (ENOSYS) + const_iv (O_RDONLY) + const_iv (O_WRONLY) + const_iv (O_CREAT) + const_iv (O_TRUNC) #ifndef _WIN32 - newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); + const_iv (S_IFIFO) #endif - newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); - newCONSTSUB (stash, "SYNC_FILE_RANGE_WAIT_BEFORE", newSViv (EIO_SYNC_FILE_RANGE_WAIT_BEFORE)); - newCONSTSUB (stash, "SYNC_FILE_RANGE_WRITE" , newSViv (EIO_SYNC_FILE_RANGE_WRITE)); - newCONSTSUB (stash, "SYNC_FILE_RANGE_WAIT_AFTER" , newSViv (EIO_SYNC_FILE_RANGE_WAIT_AFTER)); + 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_iv (ST_RDONLY) + const_iv (ST_NOSUID) + const_iv (ST_NODEV) + const_iv (ST_NOEXEC) + const_iv (ST_SYNCHRONOUS) + const_iv (ST_MANDLOCK) + const_iv (ST_WRITE) + const_iv (ST_APPEND) + const_iv (ST_IMMUTABLE) + const_iv (ST_NOATIME) + const_iv (ST_NODIRATIME) + const_iv (ST_RELATIME) + + const_iv (PROT_EXEC) + const_iv (PROT_NONE) + const_iv (PROT_READ) + const_iv (PROT_WRITE) + + /*const_iv (MAP_FIXED)*/ + const_iv (MAP_PRIVATE) + const_iv (MAP_SHARED) + 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 (MCL_FUTURE) + const_iv (MCL_CURRENT) + + const_eio (MS_ASYNC) + const_eio (MS_INVALIDATE) + const_eio (MS_SYNC) + + const_eio (MT_MODIFY) + + const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) + const_eio (SYNC_FILE_RANGE_WRITE) + const_eio (SYNC_FILE_RANGE_WAIT_AFTER) + + const_eio (READDIR_DENTS) + const_eio (READDIR_DIRS_FIRST) + const_eio (READDIR_STAT_ORDER) + const_eio (READDIR_FOUND_UNKNOWN) + + const_eio (DT_UNKNOWN) + const_eio (DT_FIFO) + const_eio (DT_CHR) + const_eio (DT_DIR) + const_eio (DT_BLK) + const_eio (DT_REG) + const_eio (DT_LNK) + const_eio (DT_SOCK) + const_eio (DT_WHT) + }; + + aio_stash = gv_stashpv ("IO::AIO" , 1); + aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); + aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); + + for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) + newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); - create_respipe (); + newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); + + create_respipe (); - if (eio_init (want_poll, done_poll) < 0) - croak ("IO::AIO: unable to initialise eio library"); + if (eio_init (want_poll, done_poll) < 0) + croak ("IO::AIO: unable to initialise eio library"); - /* atfork child called in fifo order, so before eio's handler */ - X_THREAD_ATFORK (0, 0, atfork_child); + /* atfork child called in fifo order, so before eio's handler */ + X_THREAD_ATFORK (0, 0, atfork_child); } void @@ -608,7 +813,7 @@ aio_fdatasync = EIO_FDATASYNC PPCODE: { - int fd = extract_fd (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; req->type = ix; @@ -619,18 +824,18 @@ } void -aio_sync_file_range (SV *fh, SV *offset, SV *nbytes, IV 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) PROTOTYPE: $$$$;$ PPCODE: { - int fd = extract_fd (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; req->type = EIO_SYNC_FILE_RANGE; req->sv1 = newSVsv (fh); req->int1 = fd; - req->offs = SvVAL64 (offset); - req->size = SvVAL64 (nbytes); + req->offs = offset; + req->size = nbytes; req->int2 = flags; REQ_SEND (req); @@ -642,7 +847,7 @@ PPCODE: { static int close_pipe = -1; /* dummy fd to close fds via dup2 */ - int fd = extract_fd (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; if (close_pipe < 0) @@ -674,7 +879,7 @@ PPCODE: { STRLEN svlen; - int fd = extract_fd (fh, ix == EIO_WRITE); + int fd = s_fileno_croak (fh, ix == EIO_WRITE); char *svptr = SvPVbyte (data, svlen); UV len = SvUV (length); @@ -735,12 +940,12 @@ } void -aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV 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) PROTOTYPE: $$$$;$ PPCODE: { - int ifd = extract_fd (in_fh , 0); - int ofd = extract_fd (out_fh, 0); + int ifd = s_fileno_croak (in_fh , 0); + int ofd = s_fileno_croak (out_fh, 1); dREQ; req->type = EIO_SENDFILE; @@ -748,24 +953,24 @@ req->int1 = ofd; req->sv2 = newSVsv (in_fh); req->int2 = ifd; - req->offs = SvVAL64 (in_offset); + req->offs = in_offset; req->size = length; REQ_SEND; } void -aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef) +aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) PROTOTYPE: $$$;$ PPCODE: { - int fd = extract_fd (fh, 0); + int fd = s_fileno_croak (fh, 0); dREQ; req->type = EIO_READAHEAD; req->sv1 = newSVsv (fh); req->int1 = fd; - req->offs = SvVAL64 (offset); + req->offs = offset; req->size = length; REQ_SEND; @@ -774,8 +979,9 @@ void aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) ALIAS: - aio_stat = EIO_STAT - aio_lstat = EIO_LSTAT + aio_stat = EIO_STAT + aio_lstat = EIO_LSTAT + aio_statvfs = EIO_STATVFS PPCODE: { dREQ; @@ -789,7 +995,7 @@ } else { - req->type = EIO_FSTAT; + req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); } @@ -894,6 +1100,23 @@ } void +aio_readdirx (SV8 *pathname, IV flags, SV *callback=&PL_sv_undef) + PPCODE: +{ + dREQ; + + req->type = EIO_READDIR; + req->sv1 = newSVsv (pathname); + req->ptr1 = SvPVbyte_nolen (req->sv1); + req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; + + if (flags & EIO_READDIR_DENTS) + req->int1 |= EIO_READDIR_CUSTOM2; + + REQ_SEND; +} + +void aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) ALIAS: aio_unlink = EIO_UNLINK @@ -945,6 +1168,40 @@ } void +aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) + ALIAS: + aio_mtouch = EIO_MTOUCH + aio_msync = EIO_MSYNC + PROTOTYPE: $$$$;$ + PPCODE: +{ + STRLEN svlen; + UV len = SvUV (length); + char *svptr = SvPVbyte (data, svlen); + + if (offset < 0) + offset += svlen; + + if (offset < 0 || offset > svlen) + croak ("offset outside of scalar"); + + if (!SvOK (length) || len + offset > svlen) + len = svlen - offset; + + { + dREQ; + + req->type = ix; + req->size = len; + req->sv2 = SvREFCNT_inc (data); + req->ptr2 = (char *)svptr + offset; + req->int1 = flags; + + REQ_SEND; + } +} + +void aio_busy (double delay, SV *callback=&PL_sv_undef) PPCODE: { @@ -966,7 +1223,7 @@ req->type = EIO_GROUP; req_submit (req); - XPUSHs (req_sv (req, AIO_GRP_KLASS)); + XPUSHs (req_sv (req, aio_grp_stash)); } void @@ -1028,7 +1285,7 @@ poll_fileno() PROTOTYPE: CODE: - RETVAL = respipe [0]; + RETVAL = s_epipe_fd (&respipe); OUTPUT: RETVAL @@ -1078,6 +1335,89 @@ OUTPUT: RETVAL +int +fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) + PROTOTYPE: $$$$ + CODE: +#if _XOPEN_SOURCE >= 600 && !NO_FADVISE + RETVAL = posix_fadvise (fh, offset, length, advice); +#else + RETVAL = errno = ENOSYS; /* yes, this is actually correct */ +#endif + OUTPUT: + RETVAL + +ssize_t +sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) + PROTOTYPE: $$$$ + CODE: + RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); + OUTPUT: + RETVAL + +void +mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) + PROTOTYPE: $$$$$;$ + PPCODE: + sv_unmagic (scalar, MMAP_MAGIC); +{ + int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; + void *addr = (void *)mmap (0, length, prot, flags, fd, offset); + if (addr == (void *)-1) + XSRETURN_NO; + + /* we store the length in mg_obj, as namlen is I32 :/ */ + sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) + ->mg_obj = (SV *)length; + + SvUPGRADE (scalar, SVt_PV); /* nop... */ + if (!(prot & PROT_WRITE)) + SvREADONLY_on (scalar); + + SvPVX (scalar) = (char *)addr; + SvCUR_set (scalar, length); + SvLEN_set (scalar, 0); + SvPOK_only (scalar); + + XSRETURN_YES; +} + +void +munmap (SV *scalar) + PROTOTYPE: $ + CODE: + sv_unmagic (scalar, MMAP_MAGIC); + +int +mlockall (int flags) + PROTOTYPE: $ + CODE: +#if _POSIX_MEMLOCK +#if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 + extern int mallopt (int, int); + mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ +#endif + mlockall (flags); +#else + RETVAL = -1; + errno = ENOSYS; +#endif + OUTPUT: + RETVAL + +int +munlockall () + PROTOTYPE: + CODE: +#if _POSIX_MEMLOCK + munlockall (); +#else + RETVAL = -1; + errno = ENOSYS; +#endif + OUTPUT: + RETVAL + void _on_next_submit (SV *cb) CODE: SvREFCNT_dec (on_next_submit); @@ -1101,7 +1441,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); @@ -1148,6 +1488,7 @@ grp->errorno = errno; av = newAV (); + av_extend (av, items - 1); for (i = 1; i < items; ++i ) av_push (av, newSVsv (ST (i)));