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.253 by root, Tue Feb 20 04:32:59 2018 UTC vs.
Revision 1.262 by root, Sun Aug 12 05:21:35 2018 UTC

4 4
5#include "EXTERN.h" 5#include "EXTERN.h"
6#include "perl.h" 6#include "perl.h"
7#include "XSUB.h" 7#include "XSUB.h"
8 8
9#include "schmorp.h" 9#if !defined mg_findext
10# define mg_findext(sv,type,vtbl) mg_find (sv, type)
11#endif
10 12
11#include <stddef.h> 13#include <stddef.h>
12#include <stdlib.h> 14#include <stdlib.h>
13#include <errno.h> 15#include <errno.h>
14#include <sys/types.h> 16#include <sys/types.h>
17#include <sys/socket.h>
15#include <sys/stat.h> 18#include <sys/stat.h>
16#include <limits.h> 19#include <limits.h>
17#include <fcntl.h> 20#include <fcntl.h>
18#include <sched.h> 21#include <sched.h>
19 22
104#define expect_false(expr) expect ((expr) != 0, 0) 107#define expect_false(expr) expect ((expr) != 0, 0)
105#define expect_true(expr) expect ((expr) != 0, 1) 108#define expect_true(expr) expect ((expr) != 0, 1)
106 109
107/*****************************************************************************/ 110/*****************************************************************************/
108 111
109#include "libeio/config.h" 112#include "config.h"
113
114#if HAVE_ST_XTIMENSEC
115# define ATIMENSEC PL_statcache.st_atimensec
116# define MTIMENSEC PL_statcache.st_mtimensec
117# define CTIMENSEC PL_statcache.st_ctimensec
118#elif HAVE_ST_XTIMESPEC
119# define ATIMENSEC PL_statcache.st_atim.tv_nsec
120# define MTIMENSEC PL_statcache.st_mtim.tv_nsec
121# define CTIMENSEC PL_statcache.st_ctim.tv_nsec
122#else
123# define ATIMENSEC 0
124# define MTIMENSEC 0
125# define CTIMENSEC 0
126#endif
127
128#include "schmorp.h"
110 129
111#if HAVE_EVENTFD 130#if HAVE_EVENTFD
112# include <sys/eventfd.h> 131# include <sys/eventfd.h>
132#endif
133
134#if HAVE_TIMERFD
135# include <sys/timerfd.h>
113#endif 136#endif
114 137
115#if HAVE_RLIMITS 138#if HAVE_RLIMITS
116 #include <sys/time.h> 139 #include <sys/time.h>
117 #include <sys/resource.h> 140 #include <sys/resource.h>
155# else 178# else
156# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 179# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
157# endif 180# endif
158#endif 181#endif
159 182
160/* defines all sorts of constants to 0 unless they are already defined */
161/* also provides const_iv_ and const_niv_ macros for them */
162#include "def0.h"
163
164#ifndef makedev 183#ifndef makedev
165# define makedev(maj,min) (((maj) << 8) | (min)) 184# define makedev(maj,min) (((maj) << 8) | (min))
166#endif 185#endif
167#ifndef major 186#ifndef major
168# define major(dev) ((dev) >> 8) 187# define major(dev) ((dev) >> 8)
176#endif 195#endif
177 196
178/*****************************************************************************/ 197/*****************************************************************************/
179 198
180#if !_POSIX_MAPPED_FILES 199#if !_POSIX_MAPPED_FILES
181# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 200# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
182# define munmap(addr,length) EIO_ENOSYS () 201# define munmap(addr,length) EIO_ENOSYS ()
183#endif 202#endif
184 203
185#if !_POSIX_MEMORY_PROTECTION 204#if !_POSIX_MEMORY_PROTECTION
186# define mprotect(addr,len,prot) EIO_ENOSYS () 205# define mprotect(addr,len,prot) EIO_ENOSYS ()
206#endif
207
208#if !MREMAP_MAYMOVE
209# define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1)
187#endif 210#endif
188 211
189#define FOREIGN_MAGIC PERL_MAGIC_ext 212#define FOREIGN_MAGIC PERL_MAGIC_ext
190 213
191static int ecb_cold 214static int ecb_cold
263{ 286{
264 /* todo: iterate over magic and only free ours, but of course */ 287 /* todo: iterate over magic and only free ours, but of course */
265 /* the perl5porters will call that (correct) behaviour buggy */ 288 /* the perl5porters will call that (correct) behaviour buggy */
266 sv_unmagic (sv, FOREIGN_MAGIC); 289 sv_unmagic (sv, FOREIGN_MAGIC);
267} 290}
291
292/*****************************************************************************/
293
294/* defines all sorts of constants to 0 unless they are already defined */
295/* also provides const_iv_ and const_niv_ macros for them */
296#include "def0.h"
268 297
269/*****************************************************************************/ 298/*****************************************************************************/
270 299
271static void 300static void
272fiemap (eio_req *req) 301fiemap (eio_req *req)
973 req_set_path1 (req, fh_or_path); 1002 req_set_path1 (req, fh_or_path);
974 break; 1003 break;
975 } 1004 }
976} 1005}
977 1006
1007/*****************************************************************************/
1008
1009static void
1010ts_set (struct timespec *ts, NV value)
1011{
1012 ts->tv_sec = value;
1013 ts->tv_nsec = (value - ts->tv_sec) * 1e9;
1014}
1015
1016static NV
1017ts_get (const struct timespec *ts)
1018{
1019 return ts->tv_sec + ts->tv_nsec * 1e-9;
1020}
1021
1022/*****************************************************************************/
1023
978XS(boot_IO__AIO) ecb_cold; 1024XS(boot_IO__AIO) ecb_cold;
979 1025
980MODULE = IO::AIO PACKAGE = IO::AIO 1026MODULE = IO::AIO PACKAGE = IO::AIO
981 1027
982PROTOTYPES: ENABLE 1028PROTOTYPES: ENABLE
1013 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1059 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1014 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1060 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1015 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1061 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1016 1062
1017 /* the second block will be 0 when missing */ 1063 /* the second block will be 0 when missing */
1064 const_iv (O_ACCMODE)
1065
1018 const_iv (O_RDONLY) 1066 const_iv (O_RDONLY)
1019 const_iv (O_WRONLY) 1067 const_iv (O_WRONLY)
1020 const_iv (O_RDWR) 1068 const_iv (O_RDWR)
1021 const_iv (O_CREAT) 1069 const_iv (O_CREAT)
1022 const_iv (O_TRUNC) 1070 const_iv (O_TRUNC)
1082 const_iv (MAP_GROWSDOWN) 1130 const_iv (MAP_GROWSDOWN)
1083 const_iv (MAP_32BIT) 1131 const_iv (MAP_32BIT)
1084 const_iv (MAP_HUGETLB) 1132 const_iv (MAP_HUGETLB)
1085 const_iv (MAP_STACK) 1133 const_iv (MAP_STACK)
1086 1134
1135 const_iv (MREMAP_MAYMOVE)
1136 const_iv (MREMAP_FIXED)
1137
1087 const_iv (F_DUPFD_CLOEXEC) 1138 const_iv (F_DUPFD_CLOEXEC)
1139
1140 const_iv (MSG_CMSG_CLOEXEC)
1141 const_iv (SOCK_CLOEXEC)
1088 1142
1089 const_iv (F_OFD_GETLK) 1143 const_iv (F_OFD_GETLK)
1090 const_iv (F_OFD_SETLK) 1144 const_iv (F_OFD_SETLK)
1091 const_iv (F_OFD_GETLKW) 1145 const_iv (F_OFD_GETLKW)
1092 1146
1169 1223
1170 const_iv (EFD_CLOEXEC) 1224 const_iv (EFD_CLOEXEC)
1171 const_iv (EFD_NONBLOCK) 1225 const_iv (EFD_NONBLOCK)
1172 const_iv (EFD_SEMAPHORE) 1226 const_iv (EFD_SEMAPHORE)
1173 1227
1228 const_iv (CLOCK_REALTIME)
1229 const_iv (CLOCK_MONOTONIC)
1230 const_iv (CLOCK_BOOTTIME)
1231 const_iv (CLOCK_REALTIME_ALARM)
1232 const_iv (CLOCK_BOOTTIME_ALARM)
1233
1234 const_iv (TFD_NONBLOCK)
1235 const_iv (TFD_CLOEXEC)
1236
1237 const_iv (TFD_TIMER_ABSTIME)
1238 const_iv (TFD_TIMER_CANCEL_ON_SET)
1239
1174 /* these are libeio constants, and are independent of gendef0 */ 1240 /* these are libeio constants, and are independent of gendef0 */
1175 const_eio (SEEK_SET) 1241 const_eio (SEEK_SET)
1176 const_eio (SEEK_CUR) 1242 const_eio (SEEK_CUR)
1177 const_eio (SEEK_END) 1243 const_eio (SEEK_END)
1178 1244
1561 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); 1627 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1562 1628
1563 REQ_SEND; 1629 REQ_SEND;
1564} 1630}
1565 1631
1632void
1633stat_xtime ()
1634 ALIAS:
1635 stat_atime = 1
1636 stat_mtime = 2
1637 stat_ctime = 4
1638 stat_xtime = 7
1639 PPCODE:
1640 EXTEND (SP, 3);
1641 if (ix & 1) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC));
1642 if (ix & 2) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC));
1643 if (ix & 4) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC));
1644
1645void
1646stat_xtimensec ()
1647 ALIAS:
1648 stat_atimensec = 1
1649 stat_mtimensec = 2
1650 stat_ctimensec = 4
1651 stat_xtimensec = 7
1652 PPCODE:
1653 EXTEND (SP, 3);
1654 if (ix & 1) PUSHs (newSViv (ATIMENSEC));
1655 if (ix & 2) PUSHs (newSViv (MTIMENSEC));
1656 if (ix & 4) PUSHs (newSViv (CTIMENSEC));
1657
1566UV 1658UV
1567major (UV dev) 1659major (UV dev)
1568 ALIAS: 1660 ALIAS:
1569 minor = 1 1661 minor = 1
1570 CODE: 1662 CODE:
2024void 2116void
2025munmap (SV *scalar) 2117munmap (SV *scalar)
2026 CODE: 2118 CODE:
2027 sv_clear_foreign (scalar); 2119 sv_clear_foreign (scalar);
2028 2120
2121SV *
2122mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0)
2123 CODE:
2124{
2125 MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl);
2126 void *new;
2127
2128 if (!mg || SvPVX (scalar) != mg->mg_ptr)
2129 croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified");
2130
2131 new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address);
2132
2133 RETVAL = &PL_sv_no;
2134
2135 if (new != (void *)-1)
2136 {
2137 RETVAL = new == (void *)mg->mg_ptr
2138 ? newSVpvn ("0 but true", 10)
2139 : &PL_sv_yes;
2140
2141 mg->mg_ptr = (char *)new;
2142 mg->mg_obj = (SV *)new_length;
2143
2144 SvPVX (scalar) = mg->mg_ptr;
2145 SvCUR_set (scalar, new_length);
2146 }
2147}
2148 OUTPUT:
2149 RETVAL
2150
2029int 2151int
2030madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) 2152madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
2031 ALIAS: 2153 ALIAS:
2032 mprotect = 1 2154 mprotect = 1
2033 CODE: 2155 CODE:
2176#else 2298#else
2177 fd = (errno = ENOSYS, -1); 2299 fd = (errno = ENOSYS, -1);
2178#endif 2300#endif
2179 2301
2180 XPUSHs (newmortalFH (fd, O_RDWR)); 2302 XPUSHs (newmortalFH (fd, O_RDWR));
2303}
2304
2305void
2306timerfd_create (int clockid, int flags = 0)
2307 PPCODE:
2308{
2309 int fd;
2310#if HAVE_TIMERFD
2311 fd = timerfd_create (clockid, flags);
2312#else
2313 fd = (errno = ENOSYS, -1);
2314#endif
2315
2316 XPUSHs (newmortalFH (fd, O_RDWR));
2317}
2318
2319void
2320timerfd_settime (SV *fh, int flags, NV interval, NV value)
2321 PPCODE:
2322{
2323 int fd = s_fileno_croak (fh, 0);
2324#if HAVE_TIMERFD
2325 int res;
2326 struct itimerspec its, ots;
2327
2328 ts_set (&its.it_interval, interval);
2329 ts_set (&its.it_value , value);
2330 res = timerfd_settime (fd, flags, &its, &ots);
2331
2332 if (!res)
2333 {
2334 EXTEND (SP, 2);
2335 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2336 PUSHs (newSVnv (ts_get (&ots.it_value)));
2337 }
2338#else
2339 errno = ENOSYS;
2340#endif
2341}
2342
2343void
2344timerfd_gettime (SV *fh)
2345 PPCODE:
2346{
2347 int fd = s_fileno_croak (fh, 0);
2348#if HAVE_TIMERFD
2349 int res;
2350 struct itimerspec ots;
2351 res = timerfd_gettime (fd, &ots);
2352
2353 if (!res)
2354 {
2355 EXTEND (SP, 2);
2356 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2357 PUSHs (newSVnv (ts_get (&ots.it_value)));
2358 }
2359#else
2360 errno = ENOSYS;
2361#endif
2181} 2362}
2182 2363
2183UV 2364UV
2184get_fdlimit () 2365get_fdlimit ()
2185 CODE: 2366 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines