/[pxelator]/lib/PXElator/httpd.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/httpd.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 96 by dpavlin, Fri Jul 31 20:45:09 2009 UTC revision 105 by dpavlin, Fri Jul 31 23:22:05 2009 UTC
# Line 39  our $url = "http://$server::ip:$port"; Line 39  our $url = "http://$server::ip:$port";
39  use html;  use html;
40  our $static_pids;  our $static_pids;
41    
42    use Time::HiRes qw/time/;
43    
44  sub static {  sub static {
45          my ($client,$path) = @_;          my ($client,$path) = @_;
46    
# Line 61  sub static { Line 63  sub static {
63    
64          my $size = -s $full || return;          my $size = -s $full || return;
65    
         $client->autoflush(1);  
   
66          print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n";          print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n";
67    
68          open(my $fh, $full);          open(my $fh, $full);
# Line 71  sub static { Line 71  sub static {
71          my $buff;          my $buff;
72          my $pos = 0;          my $pos = 0;
73    
74          print "static $path $type $size block: $block\n";          STDERR->autoflush(1);
75            warn "static $path $type $size block: $block\n";
76    
77            my $start_t = time();
78            my $last_t = $start_t;
79    
80          while( my $len = read $fh, $buff, $block ) {          while( my $len = read $fh, $buff, $block ) {
81                  print $client $buff;                  syswrite $client,$buff;
82                    $client->flush;
83                  $pos += $len;                  $pos += $len;
84                  printf "%s %d/%d %.2f%%\r", $path, $pos, $size, $pos * 100 / $size;                  my $t = time();
85                    next unless $t - $last_t > 0.75;
86                    $last_t = $t;
87                    my $speed = ( $pos ) / ( $t - $start_t );
88                    printf STDERR "%s %d/%d %.2f%% %.2f K/s ETA %.1fs\r"
89                            , $path, $pos
90                            , $size, $pos * 100 / $size
91                            , $speed / 1024
92                            , ( $size - $pos ) / $speed
93                            ;
94          }          }
95          close($fh);          close($fh);
96          close($client);          close($client);
97    
98          print "\n";          print STDERR "\n";
99    
100          exit;          exit;
101  }  }

Legend:
Removed from v.96  
changed lines
  Added in v.105

  ViewVC Help
Powered by ViewVC 1.1.26