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.251 by root, Sat Jan 6 01:04:42 2018 UTC vs.
Revision 1.259 by root, Sun Jul 22 20:39:19 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>
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
187static int ecb_cold 203static int ecb_cold
699 { 715 {
700 req->flags &= ~EIO_FLAG_PTR2_FREE; 716 req->flags &= ~EIO_FLAG_PTR2_FREE;
701 sv_set_foreign (req->sv2, &sysfree_vtbl, req->ptr2, req->result); 717 sv_set_foreign (req->sv2, &sysfree_vtbl, req->ptr2, req->result);
702 } 718 }
703 else 719 else
720 {
704 SvCUR_set (req->sv2, req->result); 721 SvCUR_set (req->sv2, req->result);
722 *SvEND (req->sv2) = 0;
723 SvPOK_only (req->sv2);
724 }
725
726 SvSETMAGIC (req->sv2);
705 } 727 }
706 728
707 PUSHs (sv_result); 729 PUSHs (sv_result);
708 } 730 }
709 break; 731 break;
963 req_set_path1 (req, fh_or_path); 985 req_set_path1 (req, fh_or_path);
964 break; 986 break;
965 } 987 }
966} 988}
967 989
990/*****************************************************************************/
991
992static void
993ts_set (struct timespec *ts, NV value)
994{
995 ts->tv_sec = value;
996 ts->tv_nsec = (value - ts->tv_sec) * 1e9;
997}
998
999static NV
1000ts_get (const struct timespec *ts)
1001{
1002 return ts->tv_sec + ts->tv_nsec * 1e-9;
1003}
1004
1005/*****************************************************************************/
1006
968XS(boot_IO__AIO) ecb_cold; 1007XS(boot_IO__AIO) ecb_cold;
969 1008
970MODULE = IO::AIO PACKAGE = IO::AIO 1009MODULE = IO::AIO PACKAGE = IO::AIO
971 1010
972PROTOTYPES: ENABLE 1011PROTOTYPES: ENABLE
1003 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1042 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1004 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1043 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1005 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1044 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1006 1045
1007 /* the second block will be 0 when missing */ 1046 /* the second block will be 0 when missing */
1047 const_iv (O_ACCMODE)
1048
1008 const_iv (O_RDONLY) 1049 const_iv (O_RDONLY)
1009 const_iv (O_WRONLY) 1050 const_iv (O_WRONLY)
1010 const_iv (O_RDWR) 1051 const_iv (O_RDWR)
1011 const_iv (O_CREAT) 1052 const_iv (O_CREAT)
1012 const_iv (O_TRUNC) 1053 const_iv (O_TRUNC)
1071 const_iv (MAP_NONBLOCK) 1112 const_iv (MAP_NONBLOCK)
1072 const_iv (MAP_GROWSDOWN) 1113 const_iv (MAP_GROWSDOWN)
1073 const_iv (MAP_32BIT) 1114 const_iv (MAP_32BIT)
1074 const_iv (MAP_HUGETLB) 1115 const_iv (MAP_HUGETLB)
1075 const_iv (MAP_STACK) 1116 const_iv (MAP_STACK)
1117
1118 const_iv (MREMAP_MAYMOVE)
1119 const_iv (MREMAP_FIXED)
1076 1120
1077 const_iv (F_DUPFD_CLOEXEC) 1121 const_iv (F_DUPFD_CLOEXEC)
1078 1122
1079 const_iv (F_OFD_GETLK) 1123 const_iv (F_OFD_GETLK)
1080 const_iv (F_OFD_SETLK) 1124 const_iv (F_OFD_SETLK)
1155 const_iv (SPLICE_F_MOVE) 1199 const_iv (SPLICE_F_MOVE)
1156 const_iv (SPLICE_F_NONBLOCK) 1200 const_iv (SPLICE_F_NONBLOCK)
1157 const_iv (SPLICE_F_MORE) 1201 const_iv (SPLICE_F_MORE)
1158 const_iv (SPLICE_F_GIFT) 1202 const_iv (SPLICE_F_GIFT)
1159 1203
1204 const_iv (EFD_CLOEXEC)
1205 const_iv (EFD_NONBLOCK)
1206 const_iv (EFD_SEMAPHORE)
1207
1208 const_iv (CLOCK_REALTIME)
1209 const_iv (CLOCK_MONOTONIC)
1210 const_iv (CLOCK_BOOTTIME)
1211 const_iv (CLOCK_REALTIME_ALARM)
1212 const_iv (CLOCK_BOOTTIME_ALARM)
1213
1214 const_iv (TFD_NONBLOCK)
1215 const_iv (TFD_CLOEXEC)
1216
1217 const_iv (TFD_TIMER_ABSTIME)
1218 const_iv (TFD_TIMER_CANCEL_ON_SET)
1219
1160 /* these are libeio constants, and are independent of gendef0 */ 1220 /* these are libeio constants, and are independent of gendef0 */
1161 const_eio (SEEK_SET) 1221 const_eio (SEEK_SET)
1162 const_eio (SEEK_CUR) 1222 const_eio (SEEK_CUR)
1163 const_eio (SEEK_END) 1223 const_eio (SEEK_END)
1164 1224
1415 } 1475 }
1416 else 1476 else
1417 { 1477 {
1418 /* read: check type and grow scalar as necessary */ 1478 /* read: check type and grow scalar as necessary */
1419 if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) 1479 if (!SvPOK (data) || SvLEN (data) >= SvCUR (data))
1420 svptr = sv_grow (data, len + dataoffset); 1480 svptr = sv_grow (data, len + dataoffset + 1);
1421 else if (SvCUR (data) < len + dataoffset) 1481 else if (SvCUR (data) < len + dataoffset)
1422 croak ("length + dataoffset outside of scalar, and cannot grow"); 1482 croak ("length + dataoffset outside of scalar, and cannot grow");
1423 } 1483 }
1424 1484
1425 { 1485 {
1819 sv_clear_foreign (data); 1879 sv_clear_foreign (data);
1820 1880
1821 if (length) /* known length, directly read into scalar */ 1881 if (length) /* known length, directly read into scalar */
1822 { 1882 {
1823 if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) 1883 if (!SvPOK (data) || SvLEN (data) >= SvCUR (data))
1824 svptr = sv_grow (data, length); 1884 svptr = sv_grow (data, length + 1);
1825 else if (SvCUR (data) < length) 1885 else if (SvCUR (data) < length)
1826 croak ("length outside of scalar, and cannot grow"); 1886 croak ("length outside of scalar, and cannot grow");
1827 else 1887 else
1828 svptr = SvPVbyte_nolen (data); 1888 svptr = SvPVbyte_nolen (data);
1829 } 1889 }
2010void 2070void
2011munmap (SV *scalar) 2071munmap (SV *scalar)
2012 CODE: 2072 CODE:
2013 sv_clear_foreign (scalar); 2073 sv_clear_foreign (scalar);
2014 2074
2075SV *
2076mremap (SV *scalar, STRLEN new_length, int flags = 0, IV new_address = 0)
2077 CODE:
2078{
2079 MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl);
2080 void *new;
2081
2082 if (!mg || SvPVX (scalar) != mg->mg_ptr)
2083 croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified");
2084
2085 new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address);
2086
2087 RETVAL = &PL_sv_no;
2088
2089 if (new != (void *)-1)
2090 {
2091 RETVAL = new == (void *)mg->mg_ptr
2092 ? newSVpvn ("0 but true", 10)
2093 : &PL_sv_yes;
2094
2095 mg->mg_ptr = (char *)new;
2096 mg->mg_obj = (SV *)new_length;
2097
2098 SvPVX (scalar) = mg->mg_ptr;
2099 SvCUR_set (scalar, new_length);
2100 }
2101}
2102 OUTPUT:
2103 RETVAL
2104
2015int 2105int
2016madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) 2106madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
2017 ALIAS: 2107 ALIAS:
2018 mprotect = 1 2108 mprotect = 1
2019 CODE: 2109 CODE:
2148 { 2238 {
2149 EXTEND (SP, 2); 2239 EXTEND (SP, 2);
2150 PUSHs (newmortalFH (fd[0], O_RDONLY)); 2240 PUSHs (newmortalFH (fd[0], O_RDONLY));
2151 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2241 PUSHs (newmortalFH (fd[1], O_WRONLY));
2152 } 2242 }
2243}
2244
2245void
2246eventfd (unsigned int initval = 0, int flags = 0)
2247 PPCODE:
2248{
2249 int fd;
2250#if HAVE_EVENTFD
2251 fd = eventfd (initval, flags);
2252#else
2253 fd = (errno = ENOSYS, -1);
2254#endif
2255
2256 XPUSHs (newmortalFH (fd, O_RDWR));
2257}
2258
2259void
2260timerfd_create (int clockid, int flags = 0)
2261 PPCODE:
2262{
2263 int fd;
2264#if HAVE_TIMERFD
2265 fd = timerfd_create (clockid, flags);
2266#else
2267 fd = (errno = ENOSYS, -1);
2268#endif
2269
2270 XPUSHs (newmortalFH (fd, O_RDWR));
2271}
2272
2273void
2274timerfd_settime (SV *fh, int flags, NV interval, NV value)
2275 PPCODE:
2276{
2277 int fd = s_fileno_croak (fh, 0);
2278#if HAVE_TIMERFD
2279 int res;
2280 struct itimerspec its, ots;
2281
2282 ts_set (&its.it_interval, interval);
2283 ts_set (&its.it_value , value);
2284 res = timerfd_settime (fd, flags, &its, &ots);
2285
2286 if (!res)
2287 {
2288 EXTEND (SP, 2);
2289 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2290 PUSHs (newSVnv (ts_get (&ots.it_value)));
2291 }
2292#else
2293 errno = ENOSYS;
2294#endif
2295}
2296
2297void
2298timerfd_gettime (SV *fh)
2299 PPCODE:
2300{
2301 int fd = s_fileno_croak (fh, 0);
2302#if HAVE_TIMERFD
2303 int res;
2304 struct itimerspec ots;
2305 res = timerfd_gettime (fd, &ots);
2306
2307 if (!res)
2308 {
2309 EXTEND (SP, 2);
2310 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2311 PUSHs (newSVnv (ts_get (&ots.it_value)));
2312 }
2313#else
2314 errno = ENOSYS;
2315#endif
2153} 2316}
2154 2317
2155UV 2318UV
2156get_fdlimit () 2319get_fdlimit ()
2157 CODE: 2320 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines