Future-Uring
view release on metacpan or search on metacpan
lib/Future/Uring/Handle.pm view on Meta::CPAN
my $s_flags = %args ? to_sflags(\%args) : 0;
my $ring = ring;
$ring->submit if $args{timeout} && $ring->sq_space_left < 2;
my $id = $ring->tee($self->{fh}, $fh, $nbytes, 0, $s_flags, sub($res, $flags) {
if ($res < 0) {
$future->fail(Future::Uring::Exception->new('tee', $res, $sourcename, $line));
} else {
$future->done;
}
});
$future->on_cancel(sub { $ring->cancel($id, 0, 0) }) if $args{mutable};
add_timeout($ring, \%args) if $args{timeout};
return $future;
}
sub truncate($self, $length, %args) {
my $future = Future::Uring::_Future->new;
my (undef, $sourcename, $line) = caller;
my $s_flags = %args ? to_sflags(\%args) : 0;
my $ring = ring;
$ring->submit if $args{timeout} && $ring->sq_space_left < 2;
my $id = $ring->ftruncate($self->{fh}, $length, $s_flags, sub($res, $flags) {
if ($res < 0) {
$future->fail(Future::Uring::Exception->new('truncate', $res, $sourcename, $line));
} else {
$future->done;
}
});
$future->on_cancel(sub { $ring->cancel($id, 0, 0) }) if $args{mutable};
add_timeout($ring, \%args) if $args{timeout};
return $future;
}
sub write($self, $buffer, %args) {
my $future = Future::Uring::_Future->new;
my (undef, $sourcename, $line) = caller;
my $offset = $args{offset} // -1;
my $s_flags = %args ? to_sflags(\%args) : 0;
my $ring = ring;
$ring->submit if $args{timeout} && $ring->sq_space_left < 2;
my $id = $ring->write($self->{fh}, $buffer, $offset, $s_flags, sub($res, $flags) {
if ($res >= 0) {
$future->done($res);
} else {
$future->fail(Future::Uring::Exception->new('write', $res, $sourcename, $line));
}
});
$future->on_cancel(sub { $ring->cancel($id, 0, 0) }) if $args{mutable};
add_timeout($ring, \%args) if $args{timeout};
return $future;
}
package
Future::Uring::_PollFuture;
use parent -norequire, 'Future::Uring::_Future';
use IO::Uring qw/IORING_POLL_UPDATE_EVENTS/;
use IO::Poll qw/POLLIN POLLOUT/;
sub update($original, %args) {
my $future = Future::Uring::_Future->new;
my (undef, $sourcename, $line) = caller;
my $old_id = $original->udata('uring_id');
my $s_flags = %args ? to_sflags(\%args) : 0;
my $mask = $args{mask} // 0;
$mask |= POLLIN if $args{read};
$mask |= POLLOUT if $args{write};
my $ring = Future::Uring::ring();
$ring->submit if $args{timeout} && $ring->sq_space_left < 2;
my $id = $ring->poll_update($old_id, undef, $mask, IORING_POLL_UPDATE_EVENTS, $s_flags, sub($res, $flags) {
if ($res < 0) {
$future->fail(Future::Uring::Exception->new('poll_update', $res, $sourcename, $line));
} else {
$future->done;
}
});
$future->on_cancel(sub { $ring->cancel($id, 0, 0) }) if $args{mutable};
add_timeout($ring, \%args) if $args{timeout};
return $future;
}
1;
# ABSTRACT: A Uring filehandle
__END__
=pod
=encoding UTF-8
=head1 NAME
Future::Uring::Handle - A Uring filehandle
=head1 VERSION
version 0.004
=head1 SYNOPSIS
while (1) {
my $buffer = await $input->recv(512, timeout => 60);
my $result = await $output->send($buffer, timeout => 10);
}
=head1 DESCRIPTION
This is a Future::Uring handle. It offers fully asynchronous IO on a filehandle. Generally speaking its methods are the same as their well known symmetric counterparts (e.g. C<send>, C<listen>), though some have subtly different semantics (e.g. C<pol...
=head1 METHODS
=head2 new
my $handle = Future::Uring::Handle->new($fh)
This will create a new Uring handle based on a Perl handle C<$fh>.
=head2 inner
( run in 2.703 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )