… | |
… | |
2220 | Example: create a pipe race-free w.r.t. threads and fork: |
2220 | Example: create a pipe race-free w.r.t. threads and fork: |
2221 | |
2221 | |
2222 | my ($rfh, $wfh) = IO::AIO::pipe2 IO::AIO::O_CLOEXEC |
2222 | my ($rfh, $wfh) = IO::AIO::pipe2 IO::AIO::O_CLOEXEC |
2223 | or die "pipe2: $!\n"; |
2223 | or die "pipe2: $!\n"; |
2224 | |
2224 | |
2225 | =item $fh = IO::AIO::eventfd ([$initval, [$flags]]) |
2225 | =item $fh = IO::AIO::eventfd [$initval, [$flags]] |
2226 | |
2226 | |
2227 | This is a direct interface to the Linux L<eventfd(2)> system call. The |
2227 | This is a direct interface to the Linux L<eventfd(2)> system call. The |
2228 | (unhelpful) defaults for C<$initval> and C<$flags> are C<0> for both. |
2228 | (unhelpful) defaults for C<$initval> and C<$flags> are C<0> for both. |
2229 | |
2229 | |
2230 | On success, the new eventfd filehandle is returned, otherwise returns |
2230 | On success, the new eventfd filehandle is returned, otherwise returns |
… | |
… | |
2232 | |
2232 | |
2233 | Please refer to L<eventfd(2)> for more info on this call. |
2233 | Please refer to L<eventfd(2)> for more info on this call. |
2234 | |
2234 | |
2235 | The following symbol flag values are available: C<IO::AIO::EFD_CLOEXEC>, |
2235 | The following symbol flag values are available: C<IO::AIO::EFD_CLOEXEC>, |
2236 | C<IO::AIO::EFD_NONBLOCK> and C<IO::AIO::EFD_SEMAPHORE> (Linux 2.6.30). |
2236 | C<IO::AIO::EFD_NONBLOCK> and C<IO::AIO::EFD_SEMAPHORE> (Linux 2.6.30). |
|
|
2237 | |
|
|
2238 | Example: create a new eventfd filehandle: |
|
|
2239 | |
|
|
2240 | $fh = IO::AIO::eventfd 0, IO::AIO::O_CLOEXEC |
|
|
2241 | or die "eventfd: $!\n"; |
|
|
2242 | |
|
|
2243 | =item $fh = IO::AIO::timerfd_create $clockid[, $flags] |
|
|
2244 | |
|
|
2245 | This is a direct interface to the Linux L<timerfd_create(2)> system call. The |
|
|
2246 | (unhelpful) default for C<$flags> is C<0>. |
|
|
2247 | |
|
|
2248 | On success, the new timerfd filehandle is returned, otherwise returns |
|
|
2249 | C<undef>. If the eventfd syscall is missing, fails with C<ENOSYS>. |
|
|
2250 | |
|
|
2251 | Please refer to L<timerfd_create(2)> for more info on this call. |
|
|
2252 | |
|
|
2253 | The following C<$clockid> values are |
|
|
2254 | available: C<IO::AIO::CLOCK_REALTIME>, C<IO::AIO::CLOCK_MONOTONIC> |
|
|
2255 | C<IO::AIO::CLOCK_CLOCK_BOOTTIME> (Linux 3.15) |
|
|
2256 | C<IO::AIO::CLOCK_CLOCK_REALTIME_ALARM> (Linux 3.11) and |
|
|
2257 | C<IO::AIO::CLOCK_CLOCK_BOOTTIME_ALARM> (Linux 3.11). |
|
|
2258 | |
|
|
2259 | The following C<$flags> values are available (Linux |
|
|
2260 | 2.6.27): C<IO::AIO::TFD_NONBLOCK> and C<IO::AIO::TFD_CLOEXEC>. |
|
|
2261 | |
|
|
2262 | Example: create a new timerfd and set it to one-second repeated alarms, |
|
|
2263 | then wait for two alarms: |
|
|
2264 | |
|
|
2265 | my $fh = IO::AIO::timerfd_create IO::AIO::CLOCK_BOOTTIME, IO::AIO::TFD_CLOEXEC |
|
|
2266 | or die "timerfd_create: $!\n"; |
|
|
2267 | |
|
|
2268 | defined IO::AIO::timerfd_settime $fh, 0, 1, 1 |
|
|
2269 | or die "timerfd_settime: $!\n"; |
|
|
2270 | |
|
|
2271 | for (1..2) { |
|
|
2272 | 8 == sysread $fh, my $buf, 8 |
|
|
2273 | or die "timerfd read failure\n"; |
|
|
2274 | |
|
|
2275 | printf "number of expirations (likely 1): %d\n", |
|
|
2276 | unpack "Q", $buf; |
|
|
2277 | } |
|
|
2278 | |
|
|
2279 | =item ($cur_interval, $cur_value) = IO::AIO::timerfd_settime $fh, $flags, $new_interval, $nbw_value |
|
|
2280 | |
|
|
2281 | This is a direct interface to the Linux L<timerfd_settime(2)> system |
|
|
2282 | call. Please refer to its manpage for more info on this call. |
|
|
2283 | |
|
|
2284 | The new itimerspec is specified using two (possibly fractional) second |
|
|
2285 | values, C<$new_interval> and C<$new_value>). |
|
|
2286 | |
|
|
2287 | On success, the current interval and value are returned (as per |
|
|
2288 | C<timerfd_gettime>). On failure, the empty list is returned. |
|
|
2289 | |
|
|
2290 | The following C<$flags> values are |
|
|
2291 | available: C<IO::AIO::TFD_TIMER_ABSTIME> and |
|
|
2292 | C<IO::AIO::TFD_TIMER_CANCEL_ON_SET>. |
|
|
2293 | |
|
|
2294 | See C<IO::AIO::timerfd_create> for a full example. |
|
|
2295 | |
|
|
2296 | =item ($cur_interval, $cur_value) = IO::AIO::timerfd_gettime $fh |
|
|
2297 | |
|
|
2298 | This is a direct interface to the Linux L<timerfd_gettime(2)> system |
|
|
2299 | call. Please refer to its manpage for more info on this call. |
|
|
2300 | |
|
|
2301 | On success, returns the current values of interval and value for the given |
|
|
2302 | timerfd (as potentially fractional second values). On failure, the empty |
|
|
2303 | list is returned. |
2237 | |
2304 | |
2238 | =back |
2305 | =back |
2239 | |
2306 | |
2240 | =cut |
2307 | =cut |
2241 | |
2308 | |
… | |
… | |
2307 | the process will result in undefined behaviour. Calling it at any time |
2374 | the process will result in undefined behaviour. Calling it at any time |
2308 | will also result in any undefined (by POSIX) behaviour. |
2375 | will also result in any undefined (by POSIX) behaviour. |
2309 | |
2376 | |
2310 | =back |
2377 | =back |
2311 | |
2378 | |
|
|
2379 | =head2 LINUX-SPECIFIC CALLS |
|
|
2380 | |
|
|
2381 | When a call is documented as "linux-specific" then this means it |
|
|
2382 | originated on GNU/Linux. C<IO::AIO> will usually try to autodetect the |
|
|
2383 | availability and compatibility of such calls regardless of the platform |
|
|
2384 | it is compiled on, so platforms such as FreeBSD which often implement |
|
|
2385 | these calls will work. When in doubt, call them and see if they fail wth |
|
|
2386 | C<ENOSYS>. |
|
|
2387 | |
2312 | =head2 MEMORY USAGE |
2388 | =head2 MEMORY USAGE |
2313 | |
2389 | |
2314 | Per-request usage: |
2390 | Per-request usage: |
2315 | |
2391 | |
2316 | Each aio request uses - depending on your architecture - around 100-200 |
2392 | Each aio request uses - depending on your architecture - around 100-200 |