/[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 104 by dpavlin, Fri Jul 31 22:52:22 2009 UTC revision 105 by dpavlin, Fri Jul 31 23:22:05 2009 UTC
# Line 48  sub static { Line 48  sub static {
48    
49          return if ! -f $full;          return if ! -f $full;
50    
         my $start_t = time();  
   
51          if ( my $pid = fork ) {          if ( my $pid = fork ) {
52                  # parent                  # parent
53                  close($client);                  close($client);
# Line 65  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 75  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%% %.2f K/s\r"                  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                          , $path, $pos
90                          , $size, $pos * 100 / $size                          , $size, $pos * 100 / $size
91                          , ( $pos / 1024 ) / ( time() - $start_t )                          , $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.104  
changed lines
  Added in v.105

  ViewVC Help
Powered by ViewVC 1.1.26