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.254 by root, Tue Feb 20 05:23:47 2018 UTC

106 106
107/*****************************************************************************/ 107/*****************************************************************************/
108 108
109#include "libeio/config.h" 109#include "libeio/config.h"
110 110
111#if HAVE_EVENTFD
112# include <sys/eventfd.h>
113#endif
114
115#if HAVE_TIMERFD
116# include <sys/timerfd.h>
117#endif
118
111#if HAVE_RLIMITS 119#if HAVE_RLIMITS
112 #include <sys/time.h> 120 #include <sys/time.h>
113 #include <sys/resource.h> 121 #include <sys/resource.h>
114#endif 122#endif
115 123
968 req->type = type_path; 976 req->type = type_path;
969 req_set_path1 (req, fh_or_path); 977 req_set_path1 (req, fh_or_path);
970 break; 978 break;
971 } 979 }
972} 980}
981
982/*****************************************************************************/
983
984static void
985ts_set (struct timespec *ts, NV value)
986{
987 ts->tv_sec = value;
988 ts->tv_nsec = (value - ts->tv_sec) * 1e9;
989}
990
991static NV
992ts_get (const struct timespec *ts)
993{
994 return ts->tv_sec + ts->tv_nsec * 1e-9;
995}
996
997/*****************************************************************************/
973 998
974XS(boot_IO__AIO) ecb_cold; 999XS(boot_IO__AIO) ecb_cold;
975 1000
976MODULE = IO::AIO PACKAGE = IO::AIO 1001MODULE = IO::AIO PACKAGE = IO::AIO
977 1002
1161 const_iv (SPLICE_F_MOVE) 1186 const_iv (SPLICE_F_MOVE)
1162 const_iv (SPLICE_F_NONBLOCK) 1187 const_iv (SPLICE_F_NONBLOCK)
1163 const_iv (SPLICE_F_MORE) 1188 const_iv (SPLICE_F_MORE)
1164 const_iv (SPLICE_F_GIFT) 1189 const_iv (SPLICE_F_GIFT)
1165 1190
1191 const_iv (EFD_CLOEXEC)
1192 const_iv (EFD_NONBLOCK)
1193 const_iv (EFD_SEMAPHORE)
1194
1195 const_iv (CLOCK_REALTIME)
1196 const_iv (CLOCK_MONOTONIC)
1197 const_iv (CLOCK_BOOTTIME)
1198 const_iv (CLOCK_REALTIME_ALARM)
1199 const_iv (CLOCK_BOOTTIME_ALARM)
1200
1201 const_iv (TFD_NONBLOCK)
1202 const_iv (TFD_CLOEXEC)
1203
1204 const_iv (TFD_TIMER_ABSTIME)
1205 const_iv (TFD_TIMER_CANCEL_ON_SET)
1206
1166 /* these are libeio constants, and are independent of gendef0 */ 1207 /* these are libeio constants, and are independent of gendef0 */
1167 const_eio (SEEK_SET) 1208 const_eio (SEEK_SET)
1168 const_eio (SEEK_CUR) 1209 const_eio (SEEK_CUR)
1169 const_eio (SEEK_END) 1210 const_eio (SEEK_END)
1170 1211
2156 PUSHs (newmortalFH (fd[0], O_RDONLY)); 2197 PUSHs (newmortalFH (fd[0], O_RDONLY));
2157 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2198 PUSHs (newmortalFH (fd[1], O_WRONLY));
2158 } 2199 }
2159} 2200}
2160 2201
2202void
2203eventfd (unsigned int initval = 0, int flags = 0)
2204 PPCODE:
2205{
2206 int fd;
2207#if HAVE_EVENTFD
2208 fd = eventfd (initval, flags);
2209#else
2210 fd = (errno = ENOSYS, -1);
2211#endif
2212
2213 XPUSHs (newmortalFH (fd, O_RDWR));
2214}
2215
2216void
2217timerfd_create (int clockid, int flags = 0)
2218 PPCODE:
2219{
2220 int fd;
2221#if HAVE_TIMERFD
2222 fd = timerfd_create (clockid, flags);
2223#else
2224 fd = (errno = ENOSYS, -1);
2225#endif
2226
2227 XPUSHs (newmortalFH (fd, O_RDWR));
2228}
2229
2230void
2231timerfd_settime (SV *fh, int flags, NV interval, NV value)
2232 PPCODE:
2233{
2234 int fd = s_fileno_croak (fh, 0);
2235 int res;
2236 struct itimerspec its, ots;
2237
2238 ts_set (&its.it_interval, interval);
2239 ts_set (&its.it_value , value);
2240#if HAVE_TIMERFD
2241 res = timerfd_settime (fd, flags, &its, &ots);
2242#else
2243 res = (errno = ENOSYS, -1);
2244#endif
2245
2246 if (!res)
2247 {
2248 EXTEND (SP, 2);
2249 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2250 PUSHs (newSVnv (ts_get (&ots.it_value)));
2251 }
2252}
2253
2254void
2255timerfd_gettime (SV *fh)
2256 PPCODE:
2257{
2258 int fd = s_fileno_croak (fh, 0);
2259 int res;
2260 struct itimerspec ots;
2261#if HAVE_TIMERFD
2262 res = timerfd_gettime (fd, &ots);
2263#else
2264 res = (errno = ENOSYS, -1);
2265#endif
2266
2267 if (!res)
2268 {
2269 EXTEND (SP, 2);
2270 PUSHs (newSVnv (ts_get (&ots.it_interval)));
2271 PUSHs (newSVnv (ts_get (&ots.it_value)));
2272 }
2273}
2274
2161UV 2275UV
2162get_fdlimit () 2276get_fdlimit ()
2163 CODE: 2277 CODE:
2164#if HAVE_RLIMITS 2278#if HAVE_RLIMITS
2165 struct rlimit rl; 2279 struct rlimit rl;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines