AnyEvent-Net-Curl-Queued

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.046 2013-10-17T12:32:49
 - saner YADA defaults (Stanislaw Pusep)
 - YADA optimization for plain URL queues (Stanislaw Pusep)
 - remove ram comment about Parallel::Downloader (Christian Walde)
 - Fixed yet another test failing behind the proxy (Stanislaw Pusep)

0.045 2013-04-27T14:16:02
 - reverting #871313f1ed (Stanislaw Pusep)

0.044 2013-04-22T18:12:36
 - AnyEvent timers are now weak_ref (Stanislaw Pusep)
 - Perl v5.17.10 compatibility (Stanislaw Pusep)

0.043 2013-03-19T20:59:04
 - "AnyOf" usage requires MooX::Types::MooseLike >= 0.18 (Stanislaw Pusep)
 - fixed timers for AnyEvent::Impl::Perl (Stanislaw Pusep)

0.042 2013-03-18T14:35:07
 - typo fix (Stanislaw Pusep)
 - BROKEN COMPATIBILITY: added the "WARNING: GONE MOO!" POD section
   *everywhere* (Stanislaw Pusep)
 - removing further Mo[ou]se references from documentation (Stanislaw
   Pusep)
 - scope fix (Stanislaw Pusep)
 - dependency updates (Stanislaw Pusep)
 - --MooX::late (Stanislaw Pusep)

Changes  view on Meta::CPAN

   Pusep)
 - migrate N::C::Multi & N::C::Easy object capability checks into test
   (Stanislaw Pusep)
 - test boundaries fine-tuned (Stanislaw Pusep)
 - removed unmet conditions (Stanislaw Pusep)
 - test watchdog & timeout (Stanislaw Pusep)
 - clean up duplicate URL condition (Stanislaw Pusep)
 - removed Test::HTTP::Server dependency (Stanislaw Pusep)
 - implemented Test::HTTP::AnyEvent::Server, as fork() breaks Net::Curl :(
   (Stanislaw Pusep)
 - use AE::postpone instead of "instant timer" hack (Stanislaw Pusep)

0.026 2012-09-05T21:24:33
 - updated t/42-loopback-retry.t to use internal POST retry mechanism
   (Stanislaw Pusep)
 - attempt double GET at t/30-queued-single.t (to verify queue
   deduplication) (Stanislaw Pusep)
 - stripped dead code from AE::N::C::Q::Stats (Stanislaw Pusep)
 - fixed AE::N::C::Const cache typo (Stanislaw Pusep)
 - split queue accessors POD (Stanislaw Pusep)
 - correctly reenqueue POST requests (Stanislaw Pusep)

inc/Test/HTTP/AnyEvent/Server.pm  view on Meta::CPAN

    };
    AE::log warn => "shutdown() aborted\n"
        if not defined $r or $@;
    $h->destroy;
    return;
}


sub _reply {
    my ($h, $req, $hdr, $content) = @_;
    state $timer = {};

    my $res = HTTP::Response->new(
        200 => 'OK',
        HTTP::Headers->new(
            Connection      => 'close',
            Content_Type    => 'text/plain',
            Server          => __PACKAGE__ . "/$Test::HTTP::AnyEvent::Server::VERSION AnyEvent/$AE::VERSION Perl/$] ($^O)",
        )
    );
    $res->date(time);

inc/Test/HTTP/AnyEvent/Server.pm  view on Meta::CPAN

                    join(
                        "\015\012",
                        $req,
                        $hdr,
                    )
                );
            } when (m{^/echo/body$}x) {
                $res->content($content);
            } when (m{^/delay/(\d+)$}x) {
                $res->content(sprintf(qq(issued %s\n), scalar gmtime));
                $timer->{$h} = AE::timer $1, 0, sub {
                    delete $timer->{$h};
                    AE::log debug => "delayed response\n";
                    $h->push_write($res->as_string("\015\012"));
                    _cleanup($h);
                };
                return;
            } default {
                $res->code(404);
                $res->message('Not Found');
                $res->content('Not Found');
            }

lib/AnyEvent/Net/Curl/Queued.pm  view on Meta::CPAN

    } else {
        confess 'Should be initialized as ' . $class . '->new(Hash|HashRef|Int)';
    }
}


sub start {
    my ($self) = @_;

    # watchdog
    $self->set_watchdog(AE::timer 1, 1, sub {
        $self->multi->perform;
        $self->empty;
    });

    # populate queue
    $self->add($self->dequeue)
        while
            $self->count
            and ($self->multi->handles < $self->max);

lib/AnyEvent/Net/Curl/Queued/Multi.pm  view on Meta::CPAN


extends 'Net::Curl::Multi';


has active      => (is => 'ro', isa => Int, default => sub { -1 }, writer => 'set_active');


has pool        => (is => 'ro', isa => HashRef[Ref], default => sub { {} });


has timer       => (is => 'ro', isa => AnyOf[ArrayRef, Object], writer => 'set_timer', clearer => 'clear_timer', predicate => 'has_timer', weak_ref => 0);


has max         => (is => 'ro', isa => Num, default => sub { 4 });


has timeout     => (is => 'ro', isa => Num, default => sub { 60.0 });

our $VERSION = '0.049'; # VERSION


sub BUILD {
    my ($self) = @_;

    $self->setopt(Net::Curl::Multi::CURLMOPT_MAXCONNECTS        => $self->max << 2);
    $self->setopt(Net::Curl::Multi::CURLMOPT_SOCKETFUNCTION     => \&_cb_socket);
    $self->setopt(Net::Curl::Multi::CURLMOPT_TIMERFUNCTION      => \&_cb_timer);

    return;
}

## no critic (RequireArgUnpacking)
sub BUILDARGS { return $_[-1] }

# socket callback: will be called by curl any time events on some
# socket must be updated
sub _cb_socket {

lib/AnyEvent/Net/Curl/Queued/Multi.pm  view on Meta::CPAN


    # deregister old io events
    unless ($keep) {
        delete $self->pool->{"r$socket"};
        delete $self->pool->{"w$socket"};
    }

    return 0;
}

# timer callback: It triggers timeout update. Timeout value tells
# us how soon socket_action must be called if there were no actions
# on sockets. This will allow curl to trigger timeout events.
sub _cb_timer {
    my ($self, $timeout_ms) = @_;

    # deregister old timer
    $self->clear_timer;

    my $cb = sub {
        $self->socket_action(Net::Curl::Multi::CURL_SOCKET_TIMEOUT)
            #if $self->handles > 0;
    };

    if ($timeout_ms < 0) {
        # Negative timeout means there is no timeout at all.
        # Normally happens if there are no handles anymore.
        #
        # However, curl_multi_timeout(3) says:
        #
        # Note: if libcurl returns a -1 timeout here, it just means
        # that libcurl currently has no stored timeout value. You
        # must not wait too long (more than a few seconds perhaps)
        # before you call curl_multi_perform() again.

        $self->set_timer(AE::timer 1, 1, $cb);
    } elsif ($timeout_ms < 10) {
        # Short timeouts are just... Weird!
    } else {
        # This will trigger timeouts if there are any.
        $self->set_timer(AE::timer $timeout_ms / 1000, 0, $cb);
    }

    return 0;
}


around socket_action => sub {
    my $orig = shift;
    my $self = shift;

lib/AnyEvent/Net/Curl/Queued/Multi.pm  view on Meta::CPAN

=head1 ATTRIBUTES

=head2 active

Currently active sockets.

=head2 pool

Sockets pool.

=head2 timer

L<AnyEvent> C<timer()> handler.

=head2 max

Maximum parallel connections limit (default: 4).

=head2 timeout

Timeout threshold, in seconds (default: 10).

=head1 METHODS

lib/AnyEvent/Net/Curl/Queued/Multi.pm  view on Meta::CPAN


Wrapper around the C<socket_action()> from L<Net::Curl::Multi>.

=head2 add_handle(...)

Overrides the C<add_handle()> from L<Net::Curl::Multi>.
Add one handle and kickstart download.

=for Pod::Coverage BUILD
BUILDARGS
has_timer

=head1 SEE ALSO

=over 4

=item *

L<AnyEvent>

=item *



( run in 1.068 second using v1.01-cache-2.11-cpan-49f99fa48dc )