… | |
… | |
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 | |
… | |
… | |
699 | { |
707 | { |
700 | req->flags &= ~EIO_FLAG_PTR2_FREE; |
708 | req->flags &= ~EIO_FLAG_PTR2_FREE; |
701 | sv_set_foreign (req->sv2, &sysfree_vtbl, req->ptr2, req->result); |
709 | sv_set_foreign (req->sv2, &sysfree_vtbl, req->ptr2, req->result); |
702 | } |
710 | } |
703 | else |
711 | else |
|
|
712 | { |
704 | SvCUR_set (req->sv2, req->result); |
713 | SvCUR_set (req->sv2, req->result); |
|
|
714 | *SvEND (req->sv2) = 0; |
|
|
715 | SvPOK_only (req->sv2); |
|
|
716 | } |
|
|
717 | |
|
|
718 | SvSETMAGIC (req->sv2); |
705 | } |
719 | } |
706 | |
720 | |
707 | PUSHs (sv_result); |
721 | PUSHs (sv_result); |
708 | } |
722 | } |
709 | break; |
723 | break; |
… | |
… | |
962 | req->type = type_path; |
976 | req->type = type_path; |
963 | req_set_path1 (req, fh_or_path); |
977 | req_set_path1 (req, fh_or_path); |
964 | break; |
978 | break; |
965 | } |
979 | } |
966 | } |
980 | } |
|
|
981 | |
|
|
982 | /*****************************************************************************/ |
|
|
983 | |
|
|
984 | static void |
|
|
985 | ts_set (struct timespec *ts, NV value) |
|
|
986 | { |
|
|
987 | ts->tv_sec = value; |
|
|
988 | ts->tv_nsec = (value - ts->tv_sec) * 1e9; |
|
|
989 | } |
|
|
990 | |
|
|
991 | static NV |
|
|
992 | ts_get (const struct timespec *ts) |
|
|
993 | { |
|
|
994 | return ts->tv_sec + ts->tv_nsec * 1e-9; |
|
|
995 | } |
|
|
996 | |
|
|
997 | /*****************************************************************************/ |
967 | |
998 | |
968 | XS(boot_IO__AIO) ecb_cold; |
999 | XS(boot_IO__AIO) ecb_cold; |
969 | |
1000 | |
970 | MODULE = IO::AIO PACKAGE = IO::AIO |
1001 | MODULE = IO::AIO PACKAGE = IO::AIO |
971 | |
1002 | |
… | |
… | |
1155 | const_iv (SPLICE_F_MOVE) |
1186 | const_iv (SPLICE_F_MOVE) |
1156 | const_iv (SPLICE_F_NONBLOCK) |
1187 | const_iv (SPLICE_F_NONBLOCK) |
1157 | const_iv (SPLICE_F_MORE) |
1188 | const_iv (SPLICE_F_MORE) |
1158 | const_iv (SPLICE_F_GIFT) |
1189 | const_iv (SPLICE_F_GIFT) |
1159 | |
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 | |
1160 | /* these are libeio constants, and are independent of gendef0 */ |
1207 | /* these are libeio constants, and are independent of gendef0 */ |
1161 | const_eio (SEEK_SET) |
1208 | const_eio (SEEK_SET) |
1162 | const_eio (SEEK_CUR) |
1209 | const_eio (SEEK_CUR) |
1163 | const_eio (SEEK_END) |
1210 | const_eio (SEEK_END) |
1164 | |
1211 | |
… | |
… | |
1415 | } |
1462 | } |
1416 | else |
1463 | else |
1417 | { |
1464 | { |
1418 | /* read: check type and grow scalar as necessary */ |
1465 | /* read: check type and grow scalar as necessary */ |
1419 | if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) |
1466 | if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) |
1420 | svptr = sv_grow (data, len + dataoffset); |
1467 | svptr = sv_grow (data, len + dataoffset + 1); |
1421 | else if (SvCUR (data) < len + dataoffset) |
1468 | else if (SvCUR (data) < len + dataoffset) |
1422 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
1469 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
1423 | } |
1470 | } |
1424 | |
1471 | |
1425 | { |
1472 | { |
… | |
… | |
1819 | sv_clear_foreign (data); |
1866 | sv_clear_foreign (data); |
1820 | |
1867 | |
1821 | if (length) /* known length, directly read into scalar */ |
1868 | if (length) /* known length, directly read into scalar */ |
1822 | { |
1869 | { |
1823 | if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) |
1870 | if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) |
1824 | svptr = sv_grow (data, length); |
1871 | svptr = sv_grow (data, length + 1); |
1825 | else if (SvCUR (data) < length) |
1872 | else if (SvCUR (data) < length) |
1826 | croak ("length outside of scalar, and cannot grow"); |
1873 | croak ("length outside of scalar, and cannot grow"); |
1827 | else |
1874 | else |
1828 | svptr = SvPVbyte_nolen (data); |
1875 | svptr = SvPVbyte_nolen (data); |
1829 | } |
1876 | } |
… | |
… | |
2147 | if (!res) |
2194 | if (!res) |
2148 | { |
2195 | { |
2149 | EXTEND (SP, 2); |
2196 | EXTEND (SP, 2); |
2150 | PUSHs (newmortalFH (fd[0], O_RDONLY)); |
2197 | PUSHs (newmortalFH (fd[0], O_RDONLY)); |
2151 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2198 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
|
|
2199 | } |
|
|
2200 | } |
|
|
2201 | |
|
|
2202 | void |
|
|
2203 | eventfd (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 | |
|
|
2216 | void |
|
|
2217 | timerfd_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 | |
|
|
2230 | void |
|
|
2231 | timerfd_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 | |
|
|
2254 | void |
|
|
2255 | timerfd_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))); |
2152 | } |
2272 | } |
2153 | } |
2273 | } |
2154 | |
2274 | |
2155 | UV |
2275 | UV |
2156 | get_fdlimit () |
2276 | get_fdlimit () |