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.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
116#if HAVE_EVENTFD
117# include <sys/eventfd.h>
118#endif
119
120#if HAVE_TIMERFD
121# include <sys/timerfd.h>
122#endif
123
111#if HAVE_RLIMITS 124#if HAVE_RLIMITS
112 #include <sys/time.h> 125 #include <sys/time.h>
113 #include <sys/resource.h> 126 #include <sys/resource.h>
114#endif 127#endif
115 128
151# else 164# else
152# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 165# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
153# endif 166# endif
154#endif 167#endif
155 168
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 169#ifndef makedev
161# define makedev(maj,min) (((maj) << 8) | (min)) 170# define makedev(maj,min) (((maj) << 8) | (min))
162#endif 171#endif
163#ifndef major 172#ifndef major
164# define major(dev) ((dev) >> 8) 173# define major(dev) ((dev) >> 8)
172#endif 181#endif
173 182
174/*****************************************************************************/ 183/*****************************************************************************/
175 184
176#if !_POSIX_MAPPED_FILES 185#if !_POSIX_MAPPED_FILES
177# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 186# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
178# define munmap(addr,length) EIO_ENOSYS () 187# define munmap(addr,length) EIO_ENOSYS ()
179#endif 188#endif
180 189
181#if !_POSIX_MEMORY_PROTECTION 190#if !_POSIX_MEMORY_PROTECTION
182# 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)
183#endif 196#endif
184 197
185#define FOREIGN_MAGIC PERL_MAGIC_ext 198#define FOREIGN_MAGIC PERL_MAGIC_ext
186 199
187static int ecb_cold 200static int ecb_cold
259{ 272{
260 /* todo: iterate over magic and only free ours, but of course */ 273 /* todo: iterate over magic and only free ours, but of course */
261 /* the perl5porters will call that (correct) behaviour buggy */ 274 /* the perl5porters will call that (correct) behaviour buggy */
262 sv_unmagic (sv, FOREIGN_MAGIC); 275 sv_unmagic (sv, FOREIGN_MAGIC);
263} 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"
264 283
265/*****************************************************************************/ 284/*****************************************************************************/
266 285
267static void 286static void
268fiemap (eio_req *req) 287fiemap (eio_req *req)
969 req_set_path1 (req, fh_or_path); 988 req_set_path1 (req, fh_or_path);
970 break; 989 break;
971 } 990 }
972} 991}
973 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
974XS(boot_IO__AIO) ecb_cold; 1010XS(boot_IO__AIO) ecb_cold;
975 1011
976MODULE = IO::AIO PACKAGE = IO::AIO 1012MODULE = IO::AIO PACKAGE = IO::AIO
977 1013
978PROTOTYPES: ENABLE 1014PROTOTYPES: ENABLE
1009 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1045 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1010 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1046 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1011 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1047 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1012 1048
1013 /* the second block will be 0 when missing */ 1049 /* the second block will be 0 when missing */
1050 const_iv (O_ACCMODE)
1051
1014 const_iv (O_RDONLY) 1052 const_iv (O_RDONLY)
1015 const_iv (O_WRONLY) 1053 const_iv (O_WRONLY)
1016 const_iv (O_RDWR) 1054 const_iv (O_RDWR)
1017 const_iv (O_CREAT) 1055 const_iv (O_CREAT)
1018 const_iv (O_TRUNC) 1056 const_iv (O_TRUNC)
1078 const_iv (MAP_GROWSDOWN) 1116 const_iv (MAP_GROWSDOWN)
1079 const_iv (MAP_32BIT) 1117 const_iv (MAP_32BIT)
1080 const_iv (MAP_HUGETLB) 1118 const_iv (MAP_HUGETLB)
1081 const_iv (MAP_STACK) 1119 const_iv (MAP_STACK)
1082 1120
1121 const_iv (MREMAP_MAYMOVE)
1122 const_iv (MREMAP_FIXED)
1123
1083 const_iv (F_DUPFD_CLOEXEC) 1124 const_iv (F_DUPFD_CLOEXEC)
1125
1126 const_iv (MSG_CMSG_CLOEXEC)
1127 const_iv (SOCK_CLOEXEC)
1084 1128
1085 const_iv (F_OFD_GETLK) 1129 const_iv (F_OFD_GETLK)
1086 const_iv (F_OFD_SETLK) 1130 const_iv (F_OFD_SETLK)
1087 const_iv (F_OFD_GETLKW) 1131 const_iv (F_OFD_GETLKW)
1088 1132
1161 const_iv (SPLICE_F_MOVE) 1205 const_iv (SPLICE_F_MOVE)
1162 const_iv (SPLICE_F_NONBLOCK) 1206 const_iv (SPLICE_F_NONBLOCK)
1163 const_iv (SPLICE_F_MORE) 1207 const_iv (SPLICE_F_MORE)
1164 const_iv (SPLICE_F_GIFT) 1208 const_iv (SPLICE_F_GIFT)
1165 1209
1210 const_iv (EFD_CLOEXEC)
1211 const_iv (EFD_NONBLOCK)
1212 const_iv (EFD_SEMAPHORE)
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
1166 /* these are libeio constants, and are independent of gendef0 */ 1226 /* these are libeio constants, and are independent of gendef0 */
1167 const_eio (SEEK_SET) 1227 const_eio (SEEK_SET)
1168 const_eio (SEEK_CUR) 1228 const_eio (SEEK_CUR)
1169 const_eio (SEEK_END) 1229 const_eio (SEEK_END)
1170 1230
2016void 2076void
2017munmap (SV *scalar) 2077munmap (SV *scalar)
2018 CODE: 2078 CODE:
2019 sv_clear_foreign (scalar); 2079 sv_clear_foreign (scalar);
2020 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
2021int 2111int
2022madvise (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)
2023 ALIAS: 2113 ALIAS:
2024 mprotect = 1 2114 mprotect = 1
2025 CODE: 2115 CODE:
2154 { 2244 {
2155 EXTEND (SP, 2); 2245 EXTEND (SP, 2);
2156 PUSHs (newmortalFH (fd[0], O_RDONLY)); 2246 PUSHs (newmortalFH (fd[0], O_RDONLY));
2157 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2247 PUSHs (newmortalFH (fd[1], O_WRONLY));
2158 } 2248 }
2249}
2250
2251void
2252eventfd (unsigned int initval = 0, int flags = 0)
2253 PPCODE:
2254{
2255 int fd;
2256#if HAVE_EVENTFD
2257 fd = eventfd (initval, flags);
2258#else
2259 fd = (errno = ENOSYS, -1);
2260#endif
2261
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
2159} 2322}
2160 2323
2161UV 2324UV
2162get_fdlimit () 2325get_fdlimit ()
2163 CODE: 2326 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines