--- IO-AIO/AIO.xs 2018/02/20 04:32:59 1.253 +++ IO-AIO/AIO.xs 2018/07/18 00:57:55 1.258 @@ -6,7 +6,9 @@ #include "perl.h" #include "XSUB.h" -#include "schmorp.h" +#if !defined mg_findext +# define mg_findext(sv,type,vtbl) mg_find (sv, type) +#endif #include #include @@ -108,10 +110,16 @@ #include "libeio/config.h" +#include "schmorp.h" + #if HAVE_EVENTFD # include #endif +#if HAVE_TIMERFD +# include +#endif + #if HAVE_RLIMITS #include #include @@ -186,6 +194,10 @@ # define mprotect(addr,len,prot) EIO_ENOSYS () #endif +#if !MREMAP_MAYMOVE +# define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1) +#endif + #define FOREIGN_MAGIC PERL_MAGIC_ext static int ecb_cold @@ -975,6 +987,23 @@ } } +/*****************************************************************************/ + +static void +ts_set (struct timespec *ts, NV value) +{ + ts->tv_sec = value; + ts->tv_nsec = (value - ts->tv_sec) * 1e9; +} + +static NV +ts_get (const struct timespec *ts) +{ + return ts->tv_sec + ts->tv_nsec * 1e-9; +} + +/*****************************************************************************/ + XS(boot_IO__AIO) ecb_cold; MODULE = IO::AIO PACKAGE = IO::AIO @@ -1084,6 +1113,9 @@ const_iv (MAP_HUGETLB) const_iv (MAP_STACK) + const_iv (MREMAP_MAYMOVE) + const_iv (MREMAP_FIXED) + const_iv (F_DUPFD_CLOEXEC) const_iv (F_OFD_GETLK) @@ -1171,6 +1203,18 @@ const_iv (EFD_NONBLOCK) const_iv (EFD_SEMAPHORE) + const_iv (CLOCK_REALTIME) + const_iv (CLOCK_MONOTONIC) + const_iv (CLOCK_BOOTTIME) + const_iv (CLOCK_REALTIME_ALARM) + const_iv (CLOCK_BOOTTIME_ALARM) + + const_iv (TFD_NONBLOCK) + const_iv (TFD_CLOEXEC) + + const_iv (TFD_TIMER_ABSTIME) + const_iv (TFD_TIMER_CANCEL_ON_SET) + /* these are libeio constants, and are independent of gendef0 */ const_eio (SEEK_SET) const_eio (SEEK_CUR) @@ -2026,6 +2070,36 @@ CODE: sv_clear_foreign (scalar); +SV * +mremap (SV *scalar, STRLEN new_length, int flags = 0, IV new_address = 0) + CODE: +{ + MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); + void *new; + + if (!mg || SvPVX (scalar) != mg->mg_ptr) + croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified"); + + new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address); + + RETVAL = &PL_sv_no; + + if (new != (void *)-1) + { + RETVAL = new == (void *)mg->mg_ptr + ? newSVpvn ("0 but true", 10) + : &PL_sv_yes; + + mg->mg_ptr = (char *)new; + mg->mg_obj = (SV *)new_length; + + SvPVX (scalar) = mg->mg_ptr; + SvCUR_set (scalar, new_length); + } +} + OUTPUT: + RETVAL + int madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) ALIAS: @@ -2180,6 +2254,65 @@ XPUSHs (newmortalFH (fd, O_RDWR)); } +void +timerfd_create (int clockid, int flags = 0) + PPCODE: +{ + int fd; +#if HAVE_TIMERFD + fd = timerfd_create (clockid, flags); +#else + fd = (errno = ENOSYS, -1); +#endif + + XPUSHs (newmortalFH (fd, O_RDWR)); +} + +void +timerfd_settime (SV *fh, int flags, NV interval, NV value) + PPCODE: +{ + int fd = s_fileno_croak (fh, 0); +#if HAVE_TIMERFD + int res; + struct itimerspec its, ots; + + ts_set (&its.it_interval, interval); + ts_set (&its.it_value , value); + res = timerfd_settime (fd, flags, &its, &ots); + + if (!res) + { + EXTEND (SP, 2); + PUSHs (newSVnv (ts_get (&ots.it_interval))); + PUSHs (newSVnv (ts_get (&ots.it_value))); + } +#else + errno = ENOSYS; +#endif +} + +void +timerfd_gettime (SV *fh) + PPCODE: +{ + int fd = s_fileno_croak (fh, 0); +#if HAVE_TIMERFD + int res; + struct itimerspec ots; + res = timerfd_gettime (fd, &ots); + + if (!res) + { + EXTEND (SP, 2); + PUSHs (newSVnv (ts_get (&ots.it_interval))); + PUSHs (newSVnv (ts_get (&ots.it_value))); + } +#else + errno = ENOSYS; +#endif +} + UV get_fdlimit () CODE: