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.261 by root, Tue Jul 24 19:32: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
106 109
107/*****************************************************************************/ 110/*****************************************************************************/
108 111
109#include "libeio/config.h" 112#include "libeio/config.h"
110 113
114#include "schmorp.h"
115
111#if HAVE_EVENTFD 116#if HAVE_EVENTFD
112# include <sys/eventfd.h> 117# include <sys/eventfd.h>
118#endif
119
120#if HAVE_TIMERFD
121# include <sys/timerfd.h>
113#endif 122#endif
114 123
115#if HAVE_RLIMITS 124#if HAVE_RLIMITS
116 #include <sys/time.h> 125 #include <sys/time.h>
117 #include <sys/resource.h> 126 #include <sys/resource.h>
155# else 164# else
156# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 165# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
157# endif 166# endif
158#endif 167#endif
159 168
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 169#ifndef makedev
165# define makedev(maj,min) (((maj) << 8) | (min)) 170# define makedev(maj,min) (((maj) << 8) | (min))
166#endif 171#endif
167#ifndef major 172#ifndef major
168# define major(dev) ((dev) >> 8) 173# define major(dev) ((dev) >> 8)
176#endif 181#endif
177 182
178/*****************************************************************************/ 183/*****************************************************************************/
179 184
180#if !_POSIX_MAPPED_FILES 185#if !_POSIX_MAPPED_FILES
181# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 186# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
182# define munmap(addr,length) EIO_ENOSYS () 187# define munmap(addr,length) EIO_ENOSYS ()
183#endif 188#endif
184 189
185#if !_POSIX_MEMORY_PROTECTION 190#if !_POSIX_MEMORY_PROTECTION
186# define mprotect(addr,len,prot) EIO_ENOSYS () 191# define mprotect(addr,len,prot) EIO_ENOSYS ()
192#endif
193
194#if !MREMAP_MAYMOVE
195# define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1)
187#endif 196#endif
188 197
189#define FOREIGN_MAGIC PERL_MAGIC_ext 198#define FOREIGN_MAGIC PERL_MAGIC_ext
190 199
191static int ecb_cold 200static int ecb_cold
263{ 272{
264 /* todo: iterate over magic and only free ours, but of course */ 273 /* todo: iterate over magic and only free ours, but of course */
265 /* the perl5porters will call that (correct) behaviour buggy */ 274 /* the perl5porters will call that (correct) behaviour buggy */
266 sv_unmagic (sv, FOREIGN_MAGIC); 275 sv_unmagic (sv, FOREIGN_MAGIC);
267} 276}
277
278/*****************************************************************************/
279
280/* defines all sorts of constants to 0 unless they are already defined */
281/* also provides const_iv_ and const_niv_ macros for them */
282#include "def0.h"
268 283
269/*****************************************************************************/ 284/*****************************************************************************/
270 285
271static void 286static void
272fiemap (eio_req *req) 287fiemap (eio_req *req)
973 req_set_path1 (req, fh_or_path); 988 req_set_path1 (req, fh_or_path);
974 break; 989 break;
975 } 990 }
976} 991}
977 992
993/*****************************************************************************/
994
995static void
996ts_set (struct timespec *ts, NV value)
997{
998 ts->tv_sec = value;
999 ts->tv_nsec = (value - ts->tv_sec) * 1e9;
1000}
1001
1002static NV
1003ts_get (const struct timespec *ts)
1004{
1005 return ts->tv_sec + ts->tv_nsec * 1e-9;
1006}
1007
1008/*****************************************************************************/
1009
978XS(boot_IO__AIO) ecb_cold; 1010XS(boot_IO__AIO) ecb_cold;
979 1011
980MODULE = IO::AIO PACKAGE = IO::AIO 1012MODULE = IO::AIO PACKAGE = IO::AIO
981 1013
982PROTOTYPES: ENABLE 1014PROTOTYPES: ENABLE
1013 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1045 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1014 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1046 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1015 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1047 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1016 1048
1017 /* the second block will be 0 when missing */ 1049 /* the second block will be 0 when missing */
1050 const_iv (O_ACCMODE)
1051
1018 const_iv (O_RDONLY) 1052 const_iv (O_RDONLY)
1019 const_iv (O_WRONLY) 1053 const_iv (O_WRONLY)
1020 const_iv (O_RDWR) 1054 const_iv (O_RDWR)
1021 const_iv (O_CREAT) 1055 const_iv (O_CREAT)
1022 const_iv (O_TRUNC) 1056 const_iv (O_TRUNC)
1082 const_iv (MAP_GROWSDOWN) 1116 const_iv (MAP_GROWSDOWN)
1083 const_iv (MAP_32BIT) 1117 const_iv (MAP_32BIT)
1084 const_iv (MAP_HUGETLB) 1118 const_iv (MAP_HUGETLB)
1085 const_iv (MAP_STACK) 1119 const_iv (MAP_STACK)
1086 1120
1121 const_iv (MREMAP_MAYMOVE)
1122 const_iv (MREMAP_FIXED)
1123
1087 const_iv (F_DUPFD_CLOEXEC) 1124 const_iv (F_DUPFD_CLOEXEC)
1125
1126 const_iv (MSG_CMSG_CLOEXEC)
1127 const_iv (SOCK_CLOEXEC)
1088 1128
1089 const_iv (F_OFD_GETLK) 1129 const_iv (F_OFD_GETLK)
1090 const_iv (F_OFD_SETLK) 1130 const_iv (F_OFD_SETLK)
1091 const_iv (F_OFD_GETLKW) 1131 const_iv (F_OFD_GETLKW)
1092 1132
1169 1209
1170 const_iv (EFD_CLOEXEC) 1210 const_iv (EFD_CLOEXEC)
1171 const_iv (EFD_NONBLOCK) 1211 const_iv (EFD_NONBLOCK)
1172 const_iv (EFD_SEMAPHORE) 1212 const_iv (EFD_SEMAPHORE)
1173 1213
1214 const_iv (CLOCK_REALTIME)
1215 const_iv (CLOCK_MONOTONIC)
1216 const_iv (CLOCK_BOOTTIME)
1217 const_iv (CLOCK_REALTIME_ALARM)
1218 const_iv (CLOCK_BOOTTIME_ALARM)
1219
1220 const_iv (TFD_NONBLOCK)
1221 const_iv (TFD_CLOEXEC)
1222
1223 const_iv (TFD_TIMER_ABSTIME)
1224 const_iv (TFD_TIMER_CANCEL_ON_SET)
1225
1174 /* these are libeio constants, and are independent of gendef0 */ 1226 /* these are libeio constants, and are independent of gendef0 */
1175 const_eio (SEEK_SET) 1227 const_eio (SEEK_SET)
1176 const_eio (SEEK_CUR) 1228 const_eio (SEEK_CUR)
1177 const_eio (SEEK_END) 1229 const_eio (SEEK_END)
1178 1230
2024void 2076void
2025munmap (SV *scalar) 2077munmap (SV *scalar)
2026 CODE: 2078 CODE:
2027 sv_clear_foreign (scalar); 2079 sv_clear_foreign (scalar);
2028 2080
2081SV *
2082mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0)
2083 CODE:
2084{
2085 MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl);
2086 void *new;
2087
2088 if (!mg || SvPVX (scalar) != mg->mg_ptr)
2089 croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified");
2090
2091 new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address);
2092
2093 RETVAL = &PL_sv_no;
2094
2095 if (new != (void *)-1)
2096 {
2097 RETVAL = new == (void *)mg->mg_ptr
2098 ? newSVpvn ("0 but true", 10)
2099 : &PL_sv_yes;
2100
2101 mg->mg_ptr = (char *)new;
2102 mg->mg_obj = (SV *)new_length;
2103
2104 SvPVX (scalar) = mg->mg_ptr;
2105 SvCUR_set (scalar, new_length);
2106 }
2107}
2108 OUTPUT:
2109 RETVAL
2110
2029int 2111int
2030madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) 2112madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
2031 ALIAS: 2113 ALIAS:
2032 mprotect = 1 2114 mprotect = 1
2033 CODE: 2115 CODE:
2176#else 2258#else
2177 fd = (errno = ENOSYS, -1); 2259 fd = (errno = ENOSYS, -1);
2178#endif 2260#endif
2179 2261
2180 XPUSHs (newmortalFH (fd, O_RDWR)); 2262 XPUSHs (newmortalFH (fd, O_RDWR));
2263}
2264
2265void
2266timerfd_create (int clockid, int flags = 0)
2267 PPCODE:
2268{
2269 int fd;
2270#if HAVE_TIMERFD
2271 fd = timerfd_create (clockid, flags);
2272#else
2273 fd = (errno = ENOSYS, -1);
2274#endif
2275
2276 XPUSHs (newmortalFH (fd, O_RDWR));
2277}
2278
2279void
2280timerfd_settime (SV *fh, int flags, NV interval, NV value)
2281 PPCODE:
2282{
2283 int fd = s_fileno_croak (fh, 0);
2284#if HAVE_TIMERFD
2285 int res;
2286 struct itimerspec its, ots;
2287
2288 ts_set (&its.it_interval, interval);
2289 ts_set (&its.it_value , value);
2290 res = timerfd_settime (fd, flags, &its, &ots);
2291
2292 if (!res)
2293 {
2294 EXTEND (SP, 2);
2295 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2296 PUSHs (newSVnv (ts_get (&ots.it_value)));
2297 }
2298#else
2299 errno = ENOSYS;
2300#endif
2301}
2302
2303void
2304timerfd_gettime (SV *fh)
2305 PPCODE:
2306{
2307 int fd = s_fileno_croak (fh, 0);
2308#if HAVE_TIMERFD
2309 int res;
2310 struct itimerspec ots;
2311 res = timerfd_gettime (fd, &ots);
2312
2313 if (!res)
2314 {
2315 EXTEND (SP, 2);
2316 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2317 PUSHs (newSVnv (ts_get (&ots.it_value)));
2318 }
2319#else
2320 errno = ENOSYS;
2321#endif
2181} 2322}
2182 2323
2183UV 2324UV
2184get_fdlimit () 2325get_fdlimit ()
2185 CODE: 2326 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines