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.255 by root, Tue Feb 20 06:05:19 2018 UTC vs.
Revision 1.261 by root, Tue Jul 24 19:32:20 2018 UTC

3#include <errno.h> 3#include <errno.h>
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
9#if !defined mg_findext
10# define mg_findext(sv,type,vtbl) mg_find (sv, type)
11#endif
8 12
9#include <stddef.h> 13#include <stddef.h>
10#include <stdlib.h> 14#include <stdlib.h>
11#include <errno.h> 15#include <errno.h>
12#include <sys/types.h> 16#include <sys/types.h>
17#include <sys/socket.h>
13#include <sys/stat.h> 18#include <sys/stat.h>
14#include <limits.h> 19#include <limits.h>
15#include <fcntl.h> 20#include <fcntl.h>
16#include <sched.h> 21#include <sched.h>
17 22
159# else 164# else
160# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 165# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
161# endif 166# endif
162#endif 167#endif
163 168
164/* defines all sorts of constants to 0 unless they are already defined */
165/* also provides const_iv_ and const_niv_ macros for them */
166#include "def0.h"
167
168#ifndef makedev 169#ifndef makedev
169# define makedev(maj,min) (((maj) << 8) | (min)) 170# define makedev(maj,min) (((maj) << 8) | (min))
170#endif 171#endif
171#ifndef major 172#ifndef major
172# define major(dev) ((dev) >> 8) 173# define major(dev) ((dev) >> 8)
180#endif 181#endif
181 182
182/*****************************************************************************/ 183/*****************************************************************************/
183 184
184#if !_POSIX_MAPPED_FILES 185#if !_POSIX_MAPPED_FILES
185# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 186# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
186# define munmap(addr,length) EIO_ENOSYS () 187# define munmap(addr,length) EIO_ENOSYS ()
187#endif 188#endif
188 189
189#if !_POSIX_MEMORY_PROTECTION 190#if !_POSIX_MEMORY_PROTECTION
190# 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)
191#endif 196#endif
192 197
193#define FOREIGN_MAGIC PERL_MAGIC_ext 198#define FOREIGN_MAGIC PERL_MAGIC_ext
194 199
195static int ecb_cold 200static int ecb_cold
267{ 272{
268 /* todo: iterate over magic and only free ours, but of course */ 273 /* todo: iterate over magic and only free ours, but of course */
269 /* the perl5porters will call that (correct) behaviour buggy */ 274 /* the perl5porters will call that (correct) behaviour buggy */
270 sv_unmagic (sv, FOREIGN_MAGIC); 275 sv_unmagic (sv, FOREIGN_MAGIC);
271} 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"
272 283
273/*****************************************************************************/ 284/*****************************************************************************/
274 285
275static void 286static void
276fiemap (eio_req *req) 287fiemap (eio_req *req)
1034 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1045 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1035 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1046 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1036 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1047 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1037 1048
1038 /* the second block will be 0 when missing */ 1049 /* the second block will be 0 when missing */
1050 const_iv (O_ACCMODE)
1051
1039 const_iv (O_RDONLY) 1052 const_iv (O_RDONLY)
1040 const_iv (O_WRONLY) 1053 const_iv (O_WRONLY)
1041 const_iv (O_RDWR) 1054 const_iv (O_RDWR)
1042 const_iv (O_CREAT) 1055 const_iv (O_CREAT)
1043 const_iv (O_TRUNC) 1056 const_iv (O_TRUNC)
1103 const_iv (MAP_GROWSDOWN) 1116 const_iv (MAP_GROWSDOWN)
1104 const_iv (MAP_32BIT) 1117 const_iv (MAP_32BIT)
1105 const_iv (MAP_HUGETLB) 1118 const_iv (MAP_HUGETLB)
1106 const_iv (MAP_STACK) 1119 const_iv (MAP_STACK)
1107 1120
1121 const_iv (MREMAP_MAYMOVE)
1122 const_iv (MREMAP_FIXED)
1123
1108 const_iv (F_DUPFD_CLOEXEC) 1124 const_iv (F_DUPFD_CLOEXEC)
1125
1126 const_iv (MSG_CMSG_CLOEXEC)
1127 const_iv (SOCK_CLOEXEC)
1109 1128
1110 const_iv (F_OFD_GETLK) 1129 const_iv (F_OFD_GETLK)
1111 const_iv (F_OFD_SETLK) 1130 const_iv (F_OFD_SETLK)
1112 const_iv (F_OFD_GETLKW) 1131 const_iv (F_OFD_GETLKW)
1113 1132
2057void 2076void
2058munmap (SV *scalar) 2077munmap (SV *scalar)
2059 CODE: 2078 CODE:
2060 sv_clear_foreign (scalar); 2079 sv_clear_foreign (scalar);
2061 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
2062int 2111int
2063madvise (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)
2064 ALIAS: 2113 ALIAS:
2065 mprotect = 1 2114 mprotect = 1
2066 CODE: 2115 CODE:
2230void 2279void
2231timerfd_settime (SV *fh, int flags, NV interval, NV value) 2280timerfd_settime (SV *fh, int flags, NV interval, NV value)
2232 PPCODE: 2281 PPCODE:
2233{ 2282{
2234 int fd = s_fileno_croak (fh, 0); 2283 int fd = s_fileno_croak (fh, 0);
2284#if HAVE_TIMERFD
2235 int res; 2285 int res;
2236 struct itimerspec its, ots; 2286 struct itimerspec its, ots;
2237 2287
2238 ts_set (&its.it_interval, interval); 2288 ts_set (&its.it_interval, interval);
2239 ts_set (&its.it_value , value); 2289 ts_set (&its.it_value , value);
2240#if HAVE_TIMERFD
2241 res = timerfd_settime (fd, flags, &its, &ots); 2290 res = timerfd_settime (fd, flags, &its, &ots);
2242#else
2243 res = (errno = ENOSYS, -1);
2244#endif
2245 2291
2246 if (!res) 2292 if (!res)
2247 { 2293 {
2248 EXTEND (SP, 2); 2294 EXTEND (SP, 2);
2249 PUSHs (newSVnv (ts_get (&ots.it_interval))); 2295 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2250 PUSHs (newSVnv (ts_get (&ots.it_value))); 2296 PUSHs (newSVnv (ts_get (&ots.it_value)));
2251 } 2297 }
2298#else
2299 errno = ENOSYS;
2300#endif
2252} 2301}
2253 2302
2254void 2303void
2255timerfd_gettime (SV *fh) 2304timerfd_gettime (SV *fh)
2256 PPCODE: 2305 PPCODE:
2257{ 2306{
2258 int fd = s_fileno_croak (fh, 0); 2307 int fd = s_fileno_croak (fh, 0);
2308#if HAVE_TIMERFD
2259 int res; 2309 int res;
2260 struct itimerspec ots; 2310 struct itimerspec ots;
2261#if HAVE_TIMERFD
2262 res = timerfd_gettime (fd, &ots); 2311 res = timerfd_gettime (fd, &ots);
2263#else
2264 res = (errno = ENOSYS, -1);
2265#endif
2266 2312
2267 if (!res) 2313 if (!res)
2268 { 2314 {
2269 EXTEND (SP, 2); 2315 EXTEND (SP, 2);
2270 PUSHs (newSVnv (ts_get (&ots.it_interval))); 2316 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2271 PUSHs (newSVnv (ts_get (&ots.it_value))); 2317 PUSHs (newSVnv (ts_get (&ots.it_value)));
2272 } 2318 }
2319#else
2320 errno = ENOSYS;
2321#endif
2273} 2322}
2274 2323
2275UV 2324UV
2276get_fdlimit () 2325get_fdlimit ()
2277 CODE: 2326 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines