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.265 by root, Tue Aug 14 11:50:43 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>
22
23#if HAVE_SYS_MKDEV_H
24# include <sys/mkdev.h>
25#elif HAVE_SYS_SYSMACROS_H
26# include <sys/sysmacros.h>
27#endif
19 28
20#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES 29#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
21# include <sys/mman.h> 30# include <sys/mman.h>
22#endif 31#endif
23 32
104#define expect_false(expr) expect ((expr) != 0, 0) 113#define expect_false(expr) expect ((expr) != 0, 0)
105#define expect_true(expr) expect ((expr) != 0, 1) 114#define expect_true(expr) expect ((expr) != 0, 1)
106 115
107/*****************************************************************************/ 116/*****************************************************************************/
108 117
109#include "libeio/config.h" 118#include "config.h"
119
120#if HAVE_ST_XTIMENSEC
121# define ATIMENSEC PL_statcache.st_atimensec
122# define MTIMENSEC PL_statcache.st_mtimensec
123# define CTIMENSEC PL_statcache.st_ctimensec
124#elif HAVE_ST_XTIMESPEC
125# define ATIMENSEC PL_statcache.st_atim.tv_nsec
126# define MTIMENSEC PL_statcache.st_mtim.tv_nsec
127# define CTIMENSEC PL_statcache.st_ctim.tv_nsec
128#else
129# define ATIMENSEC 0
130# define MTIMENSEC 0
131# define CTIMENSEC 0
132#endif
133
134#include "schmorp.h"
135
136#if HAVE_EVENTFD
137# include <sys/eventfd.h>
138#endif
139
140#if HAVE_TIMERFD
141# include <sys/timerfd.h>
142#endif
110 143
111#if HAVE_RLIMITS 144#if HAVE_RLIMITS
112 #include <sys/time.h> 145 #include <sys/time.h>
113 #include <sys/resource.h> 146 #include <sys/resource.h>
114#endif 147#endif
151# else 184# else
152# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 185# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
153# endif 186# endif
154#endif 187#endif
155 188
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 189#ifndef makedev
161# define makedev(maj,min) (((maj) << 8) | (min)) 190# define makedev(maj,min) (((maj) << 8) | (min))
162#endif 191#endif
163#ifndef major 192#ifndef major
164# define major(dev) ((dev) >> 8) 193# define major(dev) ((dev) >> 8)
172#endif 201#endif
173 202
174/*****************************************************************************/ 203/*****************************************************************************/
175 204
176#if !_POSIX_MAPPED_FILES 205#if !_POSIX_MAPPED_FILES
177# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 206# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
178# define munmap(addr,length) EIO_ENOSYS () 207# define munmap(addr,length) EIO_ENOSYS ()
179#endif 208#endif
180 209
181#if !_POSIX_MEMORY_PROTECTION 210#if !_POSIX_MEMORY_PROTECTION
182# define mprotect(addr,len,prot) EIO_ENOSYS () 211# define mprotect(addr,len,prot) EIO_ENOSYS ()
212#endif
213
214#if !MREMAP_MAYMOVE
215# define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1)
183#endif 216#endif
184 217
185#define FOREIGN_MAGIC PERL_MAGIC_ext 218#define FOREIGN_MAGIC PERL_MAGIC_ext
186 219
187static int ecb_cold 220static int ecb_cold
259{ 292{
260 /* todo: iterate over magic and only free ours, but of course */ 293 /* todo: iterate over magic and only free ours, but of course */
261 /* the perl5porters will call that (correct) behaviour buggy */ 294 /* the perl5porters will call that (correct) behaviour buggy */
262 sv_unmagic (sv, FOREIGN_MAGIC); 295 sv_unmagic (sv, FOREIGN_MAGIC);
263} 296}
297
298/*****************************************************************************/
299
300/* defines all sorts of constants to 0 unless they are already defined */
301/* also provides const_iv_ and const_niv_ macros for them */
302#include "def0.h"
264 303
265/*****************************************************************************/ 304/*****************************************************************************/
266 305
267static void 306static void
268fiemap (eio_req *req) 307fiemap (eio_req *req)
969 req_set_path1 (req, fh_or_path); 1008 req_set_path1 (req, fh_or_path);
970 break; 1009 break;
971 } 1010 }
972} 1011}
973 1012
1013/*****************************************************************************/
1014
1015static void
1016ts_set (struct timespec *ts, NV value)
1017{
1018 ts->tv_sec = value;
1019 ts->tv_nsec = (value - ts->tv_sec) * 1e9;
1020}
1021
1022static NV
1023ts_get (const struct timespec *ts)
1024{
1025 return ts->tv_sec + ts->tv_nsec * 1e-9;
1026}
1027
1028/*****************************************************************************/
1029
974XS(boot_IO__AIO) ecb_cold; 1030XS(boot_IO__AIO) ecb_cold;
975 1031
976MODULE = IO::AIO PACKAGE = IO::AIO 1032MODULE = IO::AIO PACKAGE = IO::AIO
977 1033
978PROTOTYPES: ENABLE 1034PROTOTYPES: ENABLE
1009 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1065 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1010 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1066 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1011 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1067 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1012 1068
1013 /* the second block will be 0 when missing */ 1069 /* the second block will be 0 when missing */
1070 const_iv (O_ACCMODE)
1071
1014 const_iv (O_RDONLY) 1072 const_iv (O_RDONLY)
1015 const_iv (O_WRONLY) 1073 const_iv (O_WRONLY)
1016 const_iv (O_RDWR) 1074 const_iv (O_RDWR)
1017 const_iv (O_CREAT) 1075 const_iv (O_CREAT)
1018 const_iv (O_TRUNC) 1076 const_iv (O_TRUNC)
1078 const_iv (MAP_GROWSDOWN) 1136 const_iv (MAP_GROWSDOWN)
1079 const_iv (MAP_32BIT) 1137 const_iv (MAP_32BIT)
1080 const_iv (MAP_HUGETLB) 1138 const_iv (MAP_HUGETLB)
1081 const_iv (MAP_STACK) 1139 const_iv (MAP_STACK)
1082 1140
1141 const_iv (MREMAP_MAYMOVE)
1142 const_iv (MREMAP_FIXED)
1143
1083 const_iv (F_DUPFD_CLOEXEC) 1144 const_iv (F_DUPFD_CLOEXEC)
1145
1146 const_iv (MSG_CMSG_CLOEXEC)
1147 const_iv (SOCK_CLOEXEC)
1084 1148
1085 const_iv (F_OFD_GETLK) 1149 const_iv (F_OFD_GETLK)
1086 const_iv (F_OFD_SETLK) 1150 const_iv (F_OFD_SETLK)
1087 const_iv (F_OFD_GETLKW) 1151 const_iv (F_OFD_GETLKW)
1088 1152
1161 const_iv (SPLICE_F_MOVE) 1225 const_iv (SPLICE_F_MOVE)
1162 const_iv (SPLICE_F_NONBLOCK) 1226 const_iv (SPLICE_F_NONBLOCK)
1163 const_iv (SPLICE_F_MORE) 1227 const_iv (SPLICE_F_MORE)
1164 const_iv (SPLICE_F_GIFT) 1228 const_iv (SPLICE_F_GIFT)
1165 1229
1230 const_iv (EFD_CLOEXEC)
1231 const_iv (EFD_NONBLOCK)
1232 const_iv (EFD_SEMAPHORE)
1233
1234 const_iv (CLOCK_REALTIME)
1235 const_iv (CLOCK_MONOTONIC)
1236 const_iv (CLOCK_BOOTTIME)
1237 const_iv (CLOCK_REALTIME_ALARM)
1238 const_iv (CLOCK_BOOTTIME_ALARM)
1239
1240 const_iv (TFD_NONBLOCK)
1241 const_iv (TFD_CLOEXEC)
1242
1243 const_iv (TFD_TIMER_ABSTIME)
1244 const_iv (TFD_TIMER_CANCEL_ON_SET)
1245
1166 /* these are libeio constants, and are independent of gendef0 */ 1246 /* these are libeio constants, and are independent of gendef0 */
1167 const_eio (SEEK_SET) 1247 const_eio (SEEK_SET)
1168 const_eio (SEEK_CUR) 1248 const_eio (SEEK_CUR)
1169 const_eio (SEEK_END) 1249 const_eio (SEEK_END)
1170 1250
1553 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); 1633 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1554 1634
1555 REQ_SEND; 1635 REQ_SEND;
1556} 1636}
1557 1637
1638void
1639st_xtime ()
1640 ALIAS:
1641 st_atime = 1
1642 st_mtime = 2
1643 st_ctime = 4
1644 st_xtime = 7
1645 PPCODE:
1646 EXTEND (SP, 3);
1647 if (ix & 1) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC));
1648 if (ix & 2) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC));
1649 if (ix & 4) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC));
1650
1651void
1652st_xtimensec ()
1653 ALIAS:
1654 st_atimensec = 1
1655 st_mtimensec = 2
1656 st_ctimensec = 4
1657 st_xtimensec = 7
1658 PPCODE:
1659 EXTEND (SP, 3);
1660 if (ix & 1) PUSHs (newSViv (ATIMENSEC));
1661 if (ix & 2) PUSHs (newSViv (MTIMENSEC));
1662 if (ix & 4) PUSHs (newSViv (CTIMENSEC));
1663
1558UV 1664UV
1559major (UV dev) 1665major (UV dev)
1560 ALIAS: 1666 ALIAS:
1561 minor = 1 1667 minor = 1
1562 CODE: 1668 CODE:
2016void 2122void
2017munmap (SV *scalar) 2123munmap (SV *scalar)
2018 CODE: 2124 CODE:
2019 sv_clear_foreign (scalar); 2125 sv_clear_foreign (scalar);
2020 2126
2127SV *
2128mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0)
2129 CODE:
2130{
2131 MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl);
2132 void *new;
2133
2134 if (!mg || SvPVX (scalar) != mg->mg_ptr)
2135 croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified");
2136
2137 new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address);
2138
2139 RETVAL = &PL_sv_no;
2140
2141 if (new != (void *)-1)
2142 {
2143 RETVAL = new == (void *)mg->mg_ptr
2144 ? newSVpvn ("0 but true", 10)
2145 : &PL_sv_yes;
2146
2147 mg->mg_ptr = (char *)new;
2148 mg->mg_obj = (SV *)new_length;
2149
2150 SvPVX (scalar) = mg->mg_ptr;
2151 SvCUR_set (scalar, new_length);
2152 }
2153}
2154 OUTPUT:
2155 RETVAL
2156
2021int 2157int
2022madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) 2158madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
2023 ALIAS: 2159 ALIAS:
2024 mprotect = 1 2160 mprotect = 1
2025 CODE: 2161 CODE:
2154 { 2290 {
2155 EXTEND (SP, 2); 2291 EXTEND (SP, 2);
2156 PUSHs (newmortalFH (fd[0], O_RDONLY)); 2292 PUSHs (newmortalFH (fd[0], O_RDONLY));
2157 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2293 PUSHs (newmortalFH (fd[1], O_WRONLY));
2158 } 2294 }
2295}
2296
2297void
2298eventfd (unsigned int initval = 0, int flags = 0)
2299 PPCODE:
2300{
2301 int fd;
2302#if HAVE_EVENTFD
2303 fd = eventfd (initval, flags);
2304#else
2305 fd = (errno = ENOSYS, -1);
2306#endif
2307
2308 XPUSHs (newmortalFH (fd, O_RDWR));
2309}
2310
2311void
2312timerfd_create (int clockid, int flags = 0)
2313 PPCODE:
2314{
2315 int fd;
2316#if HAVE_TIMERFD
2317 fd = timerfd_create (clockid, flags);
2318#else
2319 fd = (errno = ENOSYS, -1);
2320#endif
2321
2322 XPUSHs (newmortalFH (fd, O_RDWR));
2323}
2324
2325void
2326timerfd_settime (SV *fh, int flags, NV interval, NV value)
2327 PPCODE:
2328{
2329 int fd = s_fileno_croak (fh, 0);
2330#if HAVE_TIMERFD
2331 int res;
2332 struct itimerspec its, ots;
2333
2334 ts_set (&its.it_interval, interval);
2335 ts_set (&its.it_value , value);
2336 res = timerfd_settime (fd, flags, &its, &ots);
2337
2338 if (!res)
2339 {
2340 EXTEND (SP, 2);
2341 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2342 PUSHs (newSVnv (ts_get (&ots.it_value)));
2343 }
2344#else
2345 errno = ENOSYS;
2346#endif
2347}
2348
2349void
2350timerfd_gettime (SV *fh)
2351 PPCODE:
2352{
2353 int fd = s_fileno_croak (fh, 0);
2354#if HAVE_TIMERFD
2355 int res;
2356 struct itimerspec ots;
2357 res = timerfd_gettime (fd, &ots);
2358
2359 if (!res)
2360 {
2361 EXTEND (SP, 2);
2362 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2363 PUSHs (newSVnv (ts_get (&ots.it_value)));
2364 }
2365#else
2366 errno = ENOSYS;
2367#endif
2159} 2368}
2160 2369
2161UV 2370UV
2162get_fdlimit () 2371get_fdlimit ()
2163 CODE: 2372 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines