… | |
… | |
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> |
… | |
… | |
106 | |
108 | |
107 | /*****************************************************************************/ |
109 | /*****************************************************************************/ |
108 | |
110 | |
109 | #include "libeio/config.h" |
111 | #include "libeio/config.h" |
110 | |
112 | |
|
|
113 | #include "schmorp.h" |
|
|
114 | |
|
|
115 | #if HAVE_EVENTFD |
|
|
116 | # include <sys/eventfd.h> |
|
|
117 | #endif |
|
|
118 | |
|
|
119 | #if HAVE_TIMERFD |
|
|
120 | # include <sys/timerfd.h> |
|
|
121 | #endif |
|
|
122 | |
111 | #if HAVE_RLIMITS |
123 | #if HAVE_RLIMITS |
112 | #include <sys/time.h> |
124 | #include <sys/time.h> |
113 | #include <sys/resource.h> |
125 | #include <sys/resource.h> |
114 | #endif |
126 | #endif |
115 | |
127 | |
… | |
… | |
178 | # define munmap(addr,length) EIO_ENOSYS () |
190 | # define munmap(addr,length) EIO_ENOSYS () |
179 | #endif |
191 | #endif |
180 | |
192 | |
181 | #if !_POSIX_MEMORY_PROTECTION |
193 | #if !_POSIX_MEMORY_PROTECTION |
182 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
194 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
|
|
195 | #endif |
|
|
196 | |
|
|
197 | #if !MREMAP_MAYMOVE |
|
|
198 | # define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1) |
183 | #endif |
199 | #endif |
184 | |
200 | |
185 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
201 | #define FOREIGN_MAGIC PERL_MAGIC_ext |
186 | |
202 | |
187 | static int ecb_cold |
203 | static int ecb_cold |
… | |
… | |
969 | req_set_path1 (req, fh_or_path); |
985 | req_set_path1 (req, fh_or_path); |
970 | break; |
986 | break; |
971 | } |
987 | } |
972 | } |
988 | } |
973 | |
989 | |
|
|
990 | /*****************************************************************************/ |
|
|
991 | |
|
|
992 | static void |
|
|
993 | ts_set (struct timespec *ts, NV value) |
|
|
994 | { |
|
|
995 | ts->tv_sec = value; |
|
|
996 | ts->tv_nsec = (value - ts->tv_sec) * 1e9; |
|
|
997 | } |
|
|
998 | |
|
|
999 | static NV |
|
|
1000 | ts_get (const struct timespec *ts) |
|
|
1001 | { |
|
|
1002 | return ts->tv_sec + ts->tv_nsec * 1e-9; |
|
|
1003 | } |
|
|
1004 | |
|
|
1005 | /*****************************************************************************/ |
|
|
1006 | |
974 | XS(boot_IO__AIO) ecb_cold; |
1007 | XS(boot_IO__AIO) ecb_cold; |
975 | |
1008 | |
976 | MODULE = IO::AIO PACKAGE = IO::AIO |
1009 | MODULE = IO::AIO PACKAGE = IO::AIO |
977 | |
1010 | |
978 | PROTOTYPES: ENABLE |
1011 | PROTOTYPES: ENABLE |
… | |
… | |
1077 | const_iv (MAP_NONBLOCK) |
1110 | const_iv (MAP_NONBLOCK) |
1078 | const_iv (MAP_GROWSDOWN) |
1111 | const_iv (MAP_GROWSDOWN) |
1079 | const_iv (MAP_32BIT) |
1112 | const_iv (MAP_32BIT) |
1080 | const_iv (MAP_HUGETLB) |
1113 | const_iv (MAP_HUGETLB) |
1081 | const_iv (MAP_STACK) |
1114 | const_iv (MAP_STACK) |
|
|
1115 | |
|
|
1116 | const_iv (MREMAP_MAYMOVE) |
|
|
1117 | const_iv (MREMAP_FIXED) |
1082 | |
1118 | |
1083 | const_iv (F_DUPFD_CLOEXEC) |
1119 | const_iv (F_DUPFD_CLOEXEC) |
1084 | |
1120 | |
1085 | const_iv (F_OFD_GETLK) |
1121 | const_iv (F_OFD_GETLK) |
1086 | const_iv (F_OFD_SETLK) |
1122 | const_iv (F_OFD_SETLK) |
… | |
… | |
1161 | const_iv (SPLICE_F_MOVE) |
1197 | const_iv (SPLICE_F_MOVE) |
1162 | const_iv (SPLICE_F_NONBLOCK) |
1198 | const_iv (SPLICE_F_NONBLOCK) |
1163 | const_iv (SPLICE_F_MORE) |
1199 | const_iv (SPLICE_F_MORE) |
1164 | const_iv (SPLICE_F_GIFT) |
1200 | const_iv (SPLICE_F_GIFT) |
1165 | |
1201 | |
|
|
1202 | const_iv (EFD_CLOEXEC) |
|
|
1203 | const_iv (EFD_NONBLOCK) |
|
|
1204 | const_iv (EFD_SEMAPHORE) |
|
|
1205 | |
|
|
1206 | const_iv (CLOCK_REALTIME) |
|
|
1207 | const_iv (CLOCK_MONOTONIC) |
|
|
1208 | const_iv (CLOCK_BOOTTIME) |
|
|
1209 | const_iv (CLOCK_REALTIME_ALARM) |
|
|
1210 | const_iv (CLOCK_BOOTTIME_ALARM) |
|
|
1211 | |
|
|
1212 | const_iv (TFD_NONBLOCK) |
|
|
1213 | const_iv (TFD_CLOEXEC) |
|
|
1214 | |
|
|
1215 | const_iv (TFD_TIMER_ABSTIME) |
|
|
1216 | const_iv (TFD_TIMER_CANCEL_ON_SET) |
|
|
1217 | |
1166 | /* these are libeio constants, and are independent of gendef0 */ |
1218 | /* these are libeio constants, and are independent of gendef0 */ |
1167 | const_eio (SEEK_SET) |
1219 | const_eio (SEEK_SET) |
1168 | const_eio (SEEK_CUR) |
1220 | const_eio (SEEK_CUR) |
1169 | const_eio (SEEK_END) |
1221 | const_eio (SEEK_END) |
1170 | |
1222 | |
… | |
… | |
2016 | void |
2068 | void |
2017 | munmap (SV *scalar) |
2069 | munmap (SV *scalar) |
2018 | CODE: |
2070 | CODE: |
2019 | sv_clear_foreign (scalar); |
2071 | sv_clear_foreign (scalar); |
2020 | |
2072 | |
|
|
2073 | SV * |
|
|
2074 | mremap (SV *scalar, STRLEN new_length, int flags = 0, IV new_address = 0) |
|
|
2075 | CODE: |
|
|
2076 | { |
|
|
2077 | MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); |
|
|
2078 | void *new; |
|
|
2079 | |
|
|
2080 | if (!mg || SvPVX (scalar) != mg->mg_ptr) |
|
|
2081 | croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified"); |
|
|
2082 | |
|
|
2083 | new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address); |
|
|
2084 | |
|
|
2085 | RETVAL = &PL_sv_no; |
|
|
2086 | |
|
|
2087 | if (new != (void *)-1) |
|
|
2088 | { |
|
|
2089 | RETVAL = new == (void *)mg->mg_ptr |
|
|
2090 | ? newSVpvn ("0 but true", 10) |
|
|
2091 | : &PL_sv_yes; |
|
|
2092 | |
|
|
2093 | mg->mg_ptr = (char *)new; |
|
|
2094 | mg->mg_obj = (SV *)new_length; |
|
|
2095 | |
|
|
2096 | SvPVX (scalar) = mg->mg_ptr; |
|
|
2097 | SvCUR_set (scalar, new_length); |
|
|
2098 | } |
|
|
2099 | } |
|
|
2100 | OUTPUT: |
|
|
2101 | RETVAL |
|
|
2102 | |
2021 | int |
2103 | int |
2022 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2104 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
2023 | ALIAS: |
2105 | ALIAS: |
2024 | mprotect = 1 |
2106 | mprotect = 1 |
2025 | CODE: |
2107 | CODE: |
… | |
… | |
2154 | { |
2236 | { |
2155 | EXTEND (SP, 2); |
2237 | EXTEND (SP, 2); |
2156 | PUSHs (newmortalFH (fd[0], O_RDONLY)); |
2238 | PUSHs (newmortalFH (fd[0], O_RDONLY)); |
2157 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2239 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2158 | } |
2240 | } |
|
|
2241 | } |
|
|
2242 | |
|
|
2243 | void |
|
|
2244 | eventfd (unsigned int initval = 0, int flags = 0) |
|
|
2245 | PPCODE: |
|
|
2246 | { |
|
|
2247 | int fd; |
|
|
2248 | #if HAVE_EVENTFD |
|
|
2249 | fd = eventfd (initval, flags); |
|
|
2250 | #else |
|
|
2251 | fd = (errno = ENOSYS, -1); |
|
|
2252 | #endif |
|
|
2253 | |
|
|
2254 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2255 | } |
|
|
2256 | |
|
|
2257 | void |
|
|
2258 | timerfd_create (int clockid, int flags = 0) |
|
|
2259 | PPCODE: |
|
|
2260 | { |
|
|
2261 | int fd; |
|
|
2262 | #if HAVE_TIMERFD |
|
|
2263 | fd = timerfd_create (clockid, flags); |
|
|
2264 | #else |
|
|
2265 | fd = (errno = ENOSYS, -1); |
|
|
2266 | #endif |
|
|
2267 | |
|
|
2268 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2269 | } |
|
|
2270 | |
|
|
2271 | void |
|
|
2272 | timerfd_settime (SV *fh, int flags, NV interval, NV value) |
|
|
2273 | PPCODE: |
|
|
2274 | { |
|
|
2275 | int fd = s_fileno_croak (fh, 0); |
|
|
2276 | #if HAVE_TIMERFD |
|
|
2277 | int res; |
|
|
2278 | struct itimerspec its, ots; |
|
|
2279 | |
|
|
2280 | ts_set (&its.it_interval, interval); |
|
|
2281 | ts_set (&its.it_value , value); |
|
|
2282 | res = timerfd_settime (fd, flags, &its, &ots); |
|
|
2283 | |
|
|
2284 | if (!res) |
|
|
2285 | { |
|
|
2286 | EXTEND (SP, 2); |
|
|
2287 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
|
|
2288 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
|
|
2289 | } |
|
|
2290 | #else |
|
|
2291 | errno = ENOSYS; |
|
|
2292 | #endif |
|
|
2293 | } |
|
|
2294 | |
|
|
2295 | void |
|
|
2296 | timerfd_gettime (SV *fh) |
|
|
2297 | PPCODE: |
|
|
2298 | { |
|
|
2299 | int fd = s_fileno_croak (fh, 0); |
|
|
2300 | #if HAVE_TIMERFD |
|
|
2301 | int res; |
|
|
2302 | struct itimerspec ots; |
|
|
2303 | res = timerfd_gettime (fd, &ots); |
|
|
2304 | |
|
|
2305 | if (!res) |
|
|
2306 | { |
|
|
2307 | EXTEND (SP, 2); |
|
|
2308 | PUSHs (newSVnv (ts_get (&ots.it_interval))); |
|
|
2309 | PUSHs (newSVnv (ts_get (&ots.it_value))); |
|
|
2310 | } |
|
|
2311 | #else |
|
|
2312 | errno = ENOSYS; |
|
|
2313 | #endif |
2159 | } |
2314 | } |
2160 | |
2315 | |
2161 | UV |
2316 | UV |
2162 | get_fdlimit () |
2317 | get_fdlimit () |
2163 | CODE: |
2318 | CODE: |