/[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 115 by dpavlin, Sun Aug 2 12:09:02 2009 UTC
# Line 38  our $url = "http://$server::ip:$port"; Line 38  our $url = "http://$server::ip:$port";
38    
39  use html;  use html;
40  our $static_pids;  our $static_pids;
41    use progress_bar;
 use Time::HiRes qw/time/;  
42    
43  sub static {  sub static {
44          my ($client,$path) = @_;          my ($client,$path) = @_;
# Line 48  sub static { Line 47  sub static {
47    
48          return if ! -f $full;          return if ! -f $full;
49    
         my $start_t = time();  
   
50          if ( my $pid = fork ) {          if ( my $pid = fork ) {
51                  # parent                  # parent
52                  close($client);                  close($client);
# Line 65  sub static { Line 62  sub static {
62    
63          my $size = -s $full || return;          my $size = -s $full || return;
64    
         $client->autoflush(1);  
   
65          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";
66    
67          open(my $fh, $full);          open(my $fh, $full);
# Line 75  sub static { Line 70  sub static {
70          my $buff;          my $buff;
71          my $pos = 0;          my $pos = 0;
72    
73          print "static $path $type $size block: $block\n";          warn "static $path $type $size block: $block\n";
74    
75            progress_bar::start;
76    
77          while( my $len = read $fh, $buff, $block ) {          while( my $len = read $fh, $buff, $block ) {
78                  print $client $buff;                  print $client $buff;
79                    $client->flush;
80                  $pos += $len;                  $pos += $len;
81                  printf "%s %d/%d %.2f%% %.2f K/s\r"                  progress_bar::tick( $path, $pos, $size );
                         , $path, $pos  
                         , $size, $pos * 100 / $size  
                         , ( $pos / 1024 ) / ( time() - $start_t )  
                         ;  
82          }          }
83          close($fh);          close($fh);
84          close($client);          close($client);
85    
86          print "\n";          print STDERR "\n";
87    
88            warn "exit static child";
89    
90          exit;          exit(0);
91  }  }
92    
93  use boolean;  use boolean;

Legend:
Removed from v.104  
changed lines
  Added in v.115

  ViewVC Help
Powered by ViewVC 1.1.26