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.263 by root, Sun Aug 12 06:03: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
102#define expect_false(expr) expect ((expr) != 0, 0) 107#define expect_false(expr) expect ((expr) != 0, 0)
103#define expect_true(expr) expect ((expr) != 0, 1) 108#define expect_true(expr) expect ((expr) != 0, 1)
104 109
105/*****************************************************************************/ 110/*****************************************************************************/
106 111
107#include "libeio/config.h" 112#include "config.h"
113
114#if HAVE_ST_XTIMENSEC
115# define ATIMENSEC PL_statcache.st_atimensec
116# define MTIMENSEC PL_statcache.st_mtimensec
117# define CTIMENSEC PL_statcache.st_ctimensec
118#elif HAVE_ST_XTIMESPEC
119# define ATIMENSEC PL_statcache.st_atim.tv_nsec
120# define MTIMENSEC PL_statcache.st_mtim.tv_nsec
121# define CTIMENSEC PL_statcache.st_ctim.tv_nsec
122#else
123# define ATIMENSEC 0
124# define MTIMENSEC 0
125# define CTIMENSEC 0
126#endif
108 127
109#include "schmorp.h" 128#include "schmorp.h"
110 129
111#if HAVE_EVENTFD 130#if HAVE_EVENTFD
112# include <sys/eventfd.h> 131# include <sys/eventfd.h>
159# else 178# else
160# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 179# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
161# endif 180# endif
162#endif 181#endif
163 182
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 183#ifndef makedev
169# define makedev(maj,min) (((maj) << 8) | (min)) 184# define makedev(maj,min) (((maj) << 8) | (min))
170#endif 185#endif
171#ifndef major 186#ifndef major
172# define major(dev) ((dev) >> 8) 187# define major(dev) ((dev) >> 8)
180#endif 195#endif
181 196
182/*****************************************************************************/ 197/*****************************************************************************/
183 198
184#if !_POSIX_MAPPED_FILES 199#if !_POSIX_MAPPED_FILES
185# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 200# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
186# define munmap(addr,length) EIO_ENOSYS () 201# define munmap(addr,length) EIO_ENOSYS ()
187#endif 202#endif
188 203
189#if !_POSIX_MEMORY_PROTECTION 204#if !_POSIX_MEMORY_PROTECTION
190# define mprotect(addr,len,prot) EIO_ENOSYS () 205# define mprotect(addr,len,prot) EIO_ENOSYS ()
206#endif
207
208#if !MREMAP_MAYMOVE
209# define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1)
191#endif 210#endif
192 211
193#define FOREIGN_MAGIC PERL_MAGIC_ext 212#define FOREIGN_MAGIC PERL_MAGIC_ext
194 213
195static int ecb_cold 214static int ecb_cold
267{ 286{
268 /* todo: iterate over magic and only free ours, but of course */ 287 /* todo: iterate over magic and only free ours, but of course */
269 /* the perl5porters will call that (correct) behaviour buggy */ 288 /* the perl5porters will call that (correct) behaviour buggy */
270 sv_unmagic (sv, FOREIGN_MAGIC); 289 sv_unmagic (sv, FOREIGN_MAGIC);
271} 290}
291
292/*****************************************************************************/
293
294/* defines all sorts of constants to 0 unless they are already defined */
295/* also provides const_iv_ and const_niv_ macros for them */
296#include "def0.h"
272 297
273/*****************************************************************************/ 298/*****************************************************************************/
274 299
275static void 300static void
276fiemap (eio_req *req) 301fiemap (eio_req *req)
1034 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1059 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1035 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1060 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1036 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1061 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1037 1062
1038 /* the second block will be 0 when missing */ 1063 /* the second block will be 0 when missing */
1064 const_iv (O_ACCMODE)
1065
1039 const_iv (O_RDONLY) 1066 const_iv (O_RDONLY)
1040 const_iv (O_WRONLY) 1067 const_iv (O_WRONLY)
1041 const_iv (O_RDWR) 1068 const_iv (O_RDWR)
1042 const_iv (O_CREAT) 1069 const_iv (O_CREAT)
1043 const_iv (O_TRUNC) 1070 const_iv (O_TRUNC)
1103 const_iv (MAP_GROWSDOWN) 1130 const_iv (MAP_GROWSDOWN)
1104 const_iv (MAP_32BIT) 1131 const_iv (MAP_32BIT)
1105 const_iv (MAP_HUGETLB) 1132 const_iv (MAP_HUGETLB)
1106 const_iv (MAP_STACK) 1133 const_iv (MAP_STACK)
1107 1134
1135 const_iv (MREMAP_MAYMOVE)
1136 const_iv (MREMAP_FIXED)
1137
1108 const_iv (F_DUPFD_CLOEXEC) 1138 const_iv (F_DUPFD_CLOEXEC)
1139
1140 const_iv (MSG_CMSG_CLOEXEC)
1141 const_iv (SOCK_CLOEXEC)
1109 1142
1110 const_iv (F_OFD_GETLK) 1143 const_iv (F_OFD_GETLK)
1111 const_iv (F_OFD_SETLK) 1144 const_iv (F_OFD_SETLK)
1112 const_iv (F_OFD_GETLKW) 1145 const_iv (F_OFD_GETLKW)
1113 1146
1594 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); 1627 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1595 1628
1596 REQ_SEND; 1629 REQ_SEND;
1597} 1630}
1598 1631
1632void
1633st_xtime ()
1634 ALIAS:
1635 st_atime = 1
1636 st_mtime = 2
1637 st_ctime = 4
1638 st_xtime = 7
1639 PPCODE:
1640 EXTEND (SP, 3);
1641 if (ix & 1) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC));
1642 if (ix & 2) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC));
1643 if (ix & 4) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC));
1644
1645void
1646st_xtimensec ()
1647 ALIAS:
1648 st_atimensec = 1
1649 st_mtimensec = 2
1650 st_ctimensec = 4
1651 st_xtimensec = 7
1652 PPCODE:
1653 EXTEND (SP, 3);
1654 if (ix & 1) PUSHs (newSViv (ATIMENSEC));
1655 if (ix & 2) PUSHs (newSViv (MTIMENSEC));
1656 if (ix & 4) PUSHs (newSViv (CTIMENSEC));
1657
1599UV 1658UV
1600major (UV dev) 1659major (UV dev)
1601 ALIAS: 1660 ALIAS:
1602 minor = 1 1661 minor = 1
1603 CODE: 1662 CODE:
2057void 2116void
2058munmap (SV *scalar) 2117munmap (SV *scalar)
2059 CODE: 2118 CODE:
2060 sv_clear_foreign (scalar); 2119 sv_clear_foreign (scalar);
2061 2120
2121SV *
2122mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0)
2123 CODE:
2124{
2125 MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl);
2126 void *new;
2127
2128 if (!mg || SvPVX (scalar) != mg->mg_ptr)
2129 croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified");
2130
2131 new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address);
2132
2133 RETVAL = &PL_sv_no;
2134
2135 if (new != (void *)-1)
2136 {
2137 RETVAL = new == (void *)mg->mg_ptr
2138 ? newSVpvn ("0 but true", 10)
2139 : &PL_sv_yes;
2140
2141 mg->mg_ptr = (char *)new;
2142 mg->mg_obj = (SV *)new_length;
2143
2144 SvPVX (scalar) = mg->mg_ptr;
2145 SvCUR_set (scalar, new_length);
2146 }
2147}
2148 OUTPUT:
2149 RETVAL
2150
2062int 2151int
2063madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) 2152madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
2064 ALIAS: 2153 ALIAS:
2065 mprotect = 1 2154 mprotect = 1
2066 CODE: 2155 CODE:
2230void 2319void
2231timerfd_settime (SV *fh, int flags, NV interval, NV value) 2320timerfd_settime (SV *fh, int flags, NV interval, NV value)
2232 PPCODE: 2321 PPCODE:
2233{ 2322{
2234 int fd = s_fileno_croak (fh, 0); 2323 int fd = s_fileno_croak (fh, 0);
2324#if HAVE_TIMERFD
2235 int res; 2325 int res;
2236 struct itimerspec its, ots; 2326 struct itimerspec its, ots;
2237 2327
2238 ts_set (&its.it_interval, interval); 2328 ts_set (&its.it_interval, interval);
2239 ts_set (&its.it_value , value); 2329 ts_set (&its.it_value , value);
2240#if HAVE_TIMERFD
2241 res = timerfd_settime (fd, flags, &its, &ots); 2330 res = timerfd_settime (fd, flags, &its, &ots);
2242#else
2243 res = (errno = ENOSYS, -1);
2244#endif
2245 2331
2246 if (!res) 2332 if (!res)
2247 { 2333 {
2248 EXTEND (SP, 2); 2334 EXTEND (SP, 2);
2249 PUSHs (newSVnv (ts_get (&ots.it_interval))); 2335 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2250 PUSHs (newSVnv (ts_get (&ots.it_value))); 2336 PUSHs (newSVnv (ts_get (&ots.it_value)));
2251 } 2337 }
2338#else
2339 errno = ENOSYS;
2340#endif
2252} 2341}
2253 2342
2254void 2343void
2255timerfd_gettime (SV *fh) 2344timerfd_gettime (SV *fh)
2256 PPCODE: 2345 PPCODE:
2257{ 2346{
2258 int fd = s_fileno_croak (fh, 0); 2347 int fd = s_fileno_croak (fh, 0);
2348#if HAVE_TIMERFD
2259 int res; 2349 int res;
2260 struct itimerspec ots; 2350 struct itimerspec ots;
2261#if HAVE_TIMERFD
2262 res = timerfd_gettime (fd, &ots); 2351 res = timerfd_gettime (fd, &ots);
2263#else
2264 res = (errno = ENOSYS, -1);
2265#endif
2266 2352
2267 if (!res) 2353 if (!res)
2268 { 2354 {
2269 EXTEND (SP, 2); 2355 EXTEND (SP, 2);
2270 PUSHs (newSVnv (ts_get (&ots.it_interval))); 2356 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2271 PUSHs (newSVnv (ts_get (&ots.it_value))); 2357 PUSHs (newSVnv (ts_get (&ots.it_value)));
2272 } 2358 }
2359#else
2360 errno = ENOSYS;
2361#endif
2273} 2362}
2274 2363
2275UV 2364UV
2276get_fdlimit () 2365get_fdlimit ()
2277 CODE: 2366 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines