~ubuntu-branches/ubuntu/vivid/apt-cacher/vivid-proposed

« back to all changes in this revision

Viewing changes to test/curlmulti.pl

  • Committer: Package Import Robot
  • Author(s): Mark Hindley
  • Date: 2011-11-27 08:39:23 UTC
  • mfrom: (4.2.8 sid)
  • Revision ID: package-import@ubuntu.com-20111127083923-bgg2i3seunmxdeqx
Tags: 1.7.2
* Clear SysV semaphore block on install.
* Brazilian Portuguese debconf translation. Thanks to Marco Juliano e
  Silva (closes: #649499).
* When refreshing Release files internally, use Cache-Control: no-cache
* Add support for "status" action to init.d script. Patch from Peter
  Eisentraut (closes: #647984).
* Allow source files to be xv compressed. Patch from Ansgar Burghardt
  (closes: #648470).
* Support setting IO priority to reduce load in apt-cacher-cleanup.pl.
* Move library files to lib/ subdir.
* Document support for incoming request Cache-Control headers.
* Remove deprecated/* from source tarball.
* Workaround features missing in perl versions less than 5.10. 
* Improve child process management using process groups.
* Fix reading checksums from patched index files when using pdiff option
  to apt-cacher-cleanup.pl.
* New option concurrent_import_limit to control simultaneous reading of
  checksums from new index files. Default is the number of virtual CPU
  cores as parsed from /proc/cpuinfo (where possible).  
* Replace cron.daily script with more flexible cron.d fragment.
* Precompile regexps where possible.
* Don't try to checksum installer files.
* Fix libcurl low speed timeout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
use WWW::Curl::Easy;
 
6
use WWW::Curl::Multi;
 
7
 
 
8
 
 
9
pipe(my $libcurl, my $daemon)|| die $!;
 
10
 
 
11
unless (my $libcurlpid = fork) {
 
12
    # Child -- libcurl thread
 
13
    close $daemon;
 
14
 
 
15
    my %easy;
 
16
    my $curlm = WWW::Curl::Multi->new;
 
17
    my $curl_id = $$; # This should be a handle unique id.
 
18
    my $active_handles = 0;
 
19
 
 
20
    # Loop requests
 
21
    while (<$libcurl>) {
 
22
        print "Got request $_\n";
 
23
        my $curl = new WWW::Curl::Easy;
 
24
        $easy{$curl_id} = $curl; # Register handle
 
25
        $curl->setopt(CURLOPT_PRIVATE,$curl_id); # Assign Multi ID
 
26
        # do the usual configuration on the handle
 
27
 
 
28
        $curl->setopt(CURLOPT_VERBOSE, 1);
 
29
        $curl->setopt(CURLOPT_DNS_CACHE_TIMEOUT, -1);
 
30
        $curl->setopt(CURLOPT_NOBODY, 1);
 
31
 
 
32
        $curl->setopt(CURLOPT_URL, $_);
 
33
 
 
34
        # Add easy handles to multi
 
35
        $curlm->add_handle($curl);
 
36
        $active_handles++;
 
37
 
 
38
        while (my $active_transfers = $curlm->perform) {
 
39
            if ($active_transfers != $active_handles) {
 
40
                while (my ($id,$return_value) = $curlm->info_read) {
 
41
                    if ($id) {
 
42
                        $active_handles--;
 
43
                        my $actual_easy_handle = $easy{$id};
 
44
                        # do the usual result/error checking routine here
 
45
                        #           ...
 
46
                        # letting the curl handle get garbage collected, or we leak memory.
 
47
                        delete $easy{$id};
 
48
                    }
 
49
                }
 
50
            }
 
51
        }
 
52
    }
 
53
    exit;
 
54
}
 
55
 
 
56
close $libcurl;
 
57
if (my $pid = fork) {
 
58
    &doloop;
 
59
}
 
60
else {
 
61
    &doloop;
 
62
}
 
63
 
 
64
sub doloop
 
65
  {
 
66
      my $n=4;
 
67
     while ($n--) {
 
68
          print "$$: Sending request\n";
 
69
          print $daemon "http://ftp.us.debian.org\n";
 
70
     }
 
71
  }
 
72
 
 
73