#!/opt/bin/perl BEGIN { require "common.pl" } our $NUM_DOWNLOADERS = 5; our $db_http = table "http"; our $db_torrent = table "torrent"; ############################################################################# my $finish = new Coro::Channel 25; my @finishers = async { while (my $info = $finish->get) { my ($i, $data) = @$info; $stat{data} += length $data; db_put $db_torrent, undef, $i, $data, 0; } }; ############################################################################# my $download = new Coro::Channel 200; my @downloaders = map { async { while (my $info = $download->get) { my ($i, $url) = @$info; my ($data, $hdr) = GET $url; if ($hdr->{Status} == 200) { $finish->put ([$i, $data]); } elsif ($hdr->{Status} == 404) { warn "$url: status $hdr->{Status}\n"; #$finish->put ([$i, undef]); } else { warn "$url: status $hdr->{Status}\n"; } } } } 1..$NUM_DOWNLOADERS; ############################################################################# async { my $c = $db_http->cursor; while () { db_c_get $c, my $i, my $data, BDB::NEXT; last if $!; $stat{stat} = $i; $data = decompress $data; $data =~ m%put ([$i, $url]); }; undef $c; $download->shutdown; $_->join for @downloaders; $finish->shutdown; $_->join for @finishers; EV::unloop; }; EV::loop;