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.252 by root, Sat Jan 6 02:11:10 2018 UTC vs.
Revision 1.263 by root, Sun Aug 12 06:03:20 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"
129
130#if HAVE_EVENTFD
131# include <sys/eventfd.h>
132#endif
133
134#if HAVE_TIMERFD
135# include <sys/timerfd.h>
136#endif
110 137
111#if HAVE_RLIMITS 138#if HAVE_RLIMITS
112 #include <sys/time.h> 139 #include <sys/time.h>
113 #include <sys/resource.h> 140 #include <sys/resource.h>
114#endif 141#endif
151# else 178# else
152# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 179# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
153# endif 180# endif
154#endif 181#endif
155 182
156/* defines all sorts of constants to 0 unless they are already defined */
157/* also provides const_iv_ and const_niv_ macros for them */
158#include "def0.h"
159
160#ifndef makedev 183#ifndef makedev
161# define makedev(maj,min) (((maj) << 8) | (min)) 184# define makedev(maj,min) (((maj) << 8) | (min))
162#endif 185#endif
163#ifndef major 186#ifndef major
164# define major(dev) ((dev) >> 8) 187# define major(dev) ((dev) >> 8)
172#endif 195#endif
173 196
174/*****************************************************************************/ 197/*****************************************************************************/
175 198
176#if !_POSIX_MAPPED_FILES 199#if !_POSIX_MAPPED_FILES
177# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 200# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
178# define munmap(addr,length) EIO_ENOSYS () 201# define munmap(addr,length) EIO_ENOSYS ()
179#endif 202#endif
180 203
181#if !_POSIX_MEMORY_PROTECTION 204#if !_POSIX_MEMORY_PROTECTION
182# 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)
183#endif 210#endif
184 211
185#define FOREIGN_MAGIC PERL_MAGIC_ext 212#define FOREIGN_MAGIC PERL_MAGIC_ext
186 213
187static int ecb_cold 214static int ecb_cold
259{ 286{
260 /* todo: iterate over magic and only free ours, but of course */ 287 /* todo: iterate over magic and only free ours, but of course */
261 /* the perl5porters will call that (correct) behaviour buggy */ 288 /* the perl5porters will call that (correct) behaviour buggy */
262 sv_unmagic (sv, FOREIGN_MAGIC); 289 sv_unmagic (sv, FOREIGN_MAGIC);
263} 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"
264 297
265/*****************************************************************************/ 298/*****************************************************************************/
266 299
267static void 300static void
268fiemap (eio_req *req) 301fiemap (eio_req *req)
969 req_set_path1 (req, fh_or_path); 1002 req_set_path1 (req, fh_or_path);
970 break; 1003 break;
971 } 1004 }
972} 1005}
973 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
974XS(boot_IO__AIO) ecb_cold; 1024XS(boot_IO__AIO) ecb_cold;
975 1025
976MODULE = IO::AIO PACKAGE = IO::AIO 1026MODULE = IO::AIO PACKAGE = IO::AIO
977 1027
978PROTOTYPES: ENABLE 1028PROTOTYPES: ENABLE
1009 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1059 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1010 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1060 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1011 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1061 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1012 1062
1013 /* the second block will be 0 when missing */ 1063 /* the second block will be 0 when missing */
1064 const_iv (O_ACCMODE)
1065
1014 const_iv (O_RDONLY) 1066 const_iv (O_RDONLY)
1015 const_iv (O_WRONLY) 1067 const_iv (O_WRONLY)
1016 const_iv (O_RDWR) 1068 const_iv (O_RDWR)
1017 const_iv (O_CREAT) 1069 const_iv (O_CREAT)
1018 const_iv (O_TRUNC) 1070 const_iv (O_TRUNC)
1078 const_iv (MAP_GROWSDOWN) 1130 const_iv (MAP_GROWSDOWN)
1079 const_iv (MAP_32BIT) 1131 const_iv (MAP_32BIT)
1080 const_iv (MAP_HUGETLB) 1132 const_iv (MAP_HUGETLB)
1081 const_iv (MAP_STACK) 1133 const_iv (MAP_STACK)
1082 1134
1135 const_iv (MREMAP_MAYMOVE)
1136 const_iv (MREMAP_FIXED)
1137
1083 const_iv (F_DUPFD_CLOEXEC) 1138 const_iv (F_DUPFD_CLOEXEC)
1139
1140 const_iv (MSG_CMSG_CLOEXEC)
1141 const_iv (SOCK_CLOEXEC)
1084 1142
1085 const_iv (F_OFD_GETLK) 1143 const_iv (F_OFD_GETLK)
1086 const_iv (F_OFD_SETLK) 1144 const_iv (F_OFD_SETLK)
1087 const_iv (F_OFD_GETLKW) 1145 const_iv (F_OFD_GETLKW)
1088 1146
1161 const_iv (SPLICE_F_MOVE) 1219 const_iv (SPLICE_F_MOVE)
1162 const_iv (SPLICE_F_NONBLOCK) 1220 const_iv (SPLICE_F_NONBLOCK)
1163 const_iv (SPLICE_F_MORE) 1221 const_iv (SPLICE_F_MORE)
1164 const_iv (SPLICE_F_GIFT) 1222 const_iv (SPLICE_F_GIFT)
1165 1223
1224 const_iv (EFD_CLOEXEC)
1225 const_iv (EFD_NONBLOCK)
1226 const_iv (EFD_SEMAPHORE)
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
1166 /* these are libeio constants, and are independent of gendef0 */ 1240 /* these are libeio constants, and are independent of gendef0 */
1167 const_eio (SEEK_SET) 1241 const_eio (SEEK_SET)
1168 const_eio (SEEK_CUR) 1242 const_eio (SEEK_CUR)
1169 const_eio (SEEK_END) 1243 const_eio (SEEK_END)
1170 1244
1553 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);
1554 1628
1555 REQ_SEND; 1629 REQ_SEND;
1556} 1630}
1557 1631
1632void
1633st_xtime ()
1634 ALIAS:
1635 st_atime = 1
1636 st_mtime = 2
1637 st_ctime = 4
1638 st_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
1646st_xtimensec ()
1647 ALIAS:
1648 st_atimensec = 1
1649 st_mtimensec = 2
1650 st_ctimensec = 4
1651 st_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
1558UV 1658UV
1559major (UV dev) 1659major (UV dev)
1560 ALIAS: 1660 ALIAS:
1561 minor = 1 1661 minor = 1
1562 CODE: 1662 CODE:
2016void 2116void
2017munmap (SV *scalar) 2117munmap (SV *scalar)
2018 CODE: 2118 CODE:
2019 sv_clear_foreign (scalar); 2119 sv_clear_foreign (scalar);
2020 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
2021int 2151int
2022madvise (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)
2023 ALIAS: 2153 ALIAS:
2024 mprotect = 1 2154 mprotect = 1
2025 CODE: 2155 CODE:
2154 { 2284 {
2155 EXTEND (SP, 2); 2285 EXTEND (SP, 2);
2156 PUSHs (newmortalFH (fd[0], O_RDONLY)); 2286 PUSHs (newmortalFH (fd[0], O_RDONLY));
2157 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2287 PUSHs (newmortalFH (fd[1], O_WRONLY));
2158 } 2288 }
2289}
2290
2291void
2292eventfd (unsigned int initval = 0, int flags = 0)
2293 PPCODE:
2294{
2295 int fd;
2296#if HAVE_EVENTFD
2297 fd = eventfd (initval, flags);
2298#else
2299 fd = (errno = ENOSYS, -1);
2300#endif
2301
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
2159} 2362}
2160 2363
2161UV 2364UV
2162get_fdlimit () 2365get_fdlimit ()
2163 CODE: 2366 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines