ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.281 by root, Tue Feb 20 04:32:59 2018 UTC vs.
Revision 1.282 by root, Tue Feb 20 05:23:47 2018 UTC

2220Example: create a pipe race-free w.r.t. threads and fork: 2220Example: 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
2227This is a direct interface to the Linux L<eventfd(2)> system call. The 2227This 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
2230On success, the new eventfd filehandle is returned, otherwise returns 2230On success, the new eventfd filehandle is returned, otherwise returns
2232 2232
2233Please refer to L<eventfd(2)> for more info on this call. 2233Please refer to L<eventfd(2)> for more info on this call.
2234 2234
2235The following symbol flag values are available: C<IO::AIO::EFD_CLOEXEC>, 2235The following symbol flag values are available: C<IO::AIO::EFD_CLOEXEC>,
2236C<IO::AIO::EFD_NONBLOCK> and C<IO::AIO::EFD_SEMAPHORE> (Linux 2.6.30). 2236C<IO::AIO::EFD_NONBLOCK> and C<IO::AIO::EFD_SEMAPHORE> (Linux 2.6.30).
2237
2238Example: 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
2245This is a direct interface to the Linux L<timerfd_create(2)> system call. The
2246(unhelpful) default for C<$flags> is C<0>.
2247
2248On success, the new timerfd filehandle is returned, otherwise returns
2249C<undef>. If the eventfd syscall is missing, fails with C<ENOSYS>.
2250
2251Please refer to L<timerfd_create(2)> for more info on this call.
2252
2253The following C<$clockid> values are
2254available: C<IO::AIO::CLOCK_REALTIME>, C<IO::AIO::CLOCK_MONOTONIC>
2255C<IO::AIO::CLOCK_CLOCK_BOOTTIME> (Linux 3.15)
2256C<IO::AIO::CLOCK_CLOCK_REALTIME_ALARM> (Linux 3.11) and
2257C<IO::AIO::CLOCK_CLOCK_BOOTTIME_ALARM> (Linux 3.11).
2258
2259The following C<$flags> values are available (Linux
22602.6.27): C<IO::AIO::TFD_NONBLOCK> and C<IO::AIO::TFD_CLOEXEC>.
2261
2262Example: create a new timerfd and set it to one-second repeated alarms,
2263then 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
2281This is a direct interface to the Linux L<timerfd_settime(2)> system
2282call. Please refer to its manpage for more info on this call.
2283
2284The new itimerspec is specified using two (possibly fractional) second
2285values, C<$new_interval> and C<$new_value>).
2286
2287On success, the current interval and value are returned (as per
2288C<timerfd_gettime>). On failure, the empty list is returned.
2289
2290The following C<$flags> values are
2291available: C<IO::AIO::TFD_TIMER_ABSTIME> and
2292C<IO::AIO::TFD_TIMER_CANCEL_ON_SET>.
2293
2294See C<IO::AIO::timerfd_create> for a full example.
2295
2296=item ($cur_interval, $cur_value) = IO::AIO::timerfd_gettime $fh
2297
2298This is a direct interface to the Linux L<timerfd_gettime(2)> system
2299call. Please refer to its manpage for more info on this call.
2300
2301On success, returns the current values of interval and value for the given
2302timerfd (as potentially fractional second values). On failure, the empty
2303list is returned.
2237 2304
2238=back 2305=back
2239 2306
2240=cut 2307=cut
2241 2308
2307the process will result in undefined behaviour. Calling it at any time 2374the process will result in undefined behaviour. Calling it at any time
2308will also result in any undefined (by POSIX) behaviour. 2375will also result in any undefined (by POSIX) behaviour.
2309 2376
2310=back 2377=back
2311 2378
2379=head2 LINUX-SPECIFIC CALLS
2380
2381When a call is documented as "linux-specific" then this means it
2382originated on GNU/Linux. C<IO::AIO> will usually try to autodetect the
2383availability and compatibility of such calls regardless of the platform
2384it is compiled on, so platforms such as FreeBSD which often implement
2385these calls will work. When in doubt, call them and see if they fail wth
2386C<ENOSYS>.
2387
2312=head2 MEMORY USAGE 2388=head2 MEMORY USAGE
2313 2389
2314Per-request usage: 2390Per-request usage:
2315 2391
2316Each aio request uses - depending on your architecture - around 100-200 2392Each aio request uses - depending on your architecture - around 100-200

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines