/[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 118 by dpavlin, Mon Aug 3 08:52:32 2009 UTC
# Line 17  use Carp qw/confess/; Line 17  use Carp qw/confess/;
17  use File::Slurp;  use File::Slurp;
18  #use JSON;  #use JSON;
19  use IO::Socket::INET;  use IO::Socket::INET;
 use Module::Refresh;  
20    
21  our $pids;  our $pids;
22  $pids = { httpd => $$ } unless defined $pids; # keep pids on refresh  $pids = { httpd => $$ } unless defined $pids; # keep pids on refresh
# Line 38  our $url = "http://$server::ip:$port"; Line 37  our $url = "http://$server::ip:$port";
37    
38  use html;  use html;
39  our $static_pids;  our $static_pids;
40    use progress_bar;
41    
42  sub static {  sub static {
43          my ($client,$path) = @_;          my ($client,$path) = @_;
# Line 61  sub static { Line 61  sub static {
61    
62          my $size = -s $full || return;          my $size = -s $full || return;
63    
         $client->autoflush(1);  
   
64          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";
65    
66          open(my $fh, $full);          open(my $fh, $full);
# Line 71  sub static { Line 69  sub static {
69          my $buff;          my $buff;
70          my $pos = 0;          my $pos = 0;
71    
72          print "static $path $type $size block: $block\n";          warn "static $path $type $size block: $block\n";
73    
74            progress_bar::start;
75    
76          while( my $len = read $fh, $buff, $block ) {          while( my $len = read $fh, $buff, $block ) {
77                  print $client $buff;                  print $client $buff;
78                    $client->flush;
79                  $pos += $len;                  $pos += $len;
80                  printf "%s %d/%d %.2f%%\r", $path, $pos, $size, $pos * 100 / $size;                  progress_bar::tick( $path, $pos, $size );
81          }          }
82          close($fh);          close($fh);
83          close($client);          close($client);
84    
85          print "\n";          print STDERR "\n";
86    
87          exit;          warn "exit static child";
88    
89            exit(0);
90  }  }
91    
92  use boolean;  use boolean;
# Line 253  sub start { Line 256  sub start {
256          start_stop 'screen';          start_stop 'screen';
257          start_stop 'kvm';          start_stop 'kvm';
258    
259          while (my $client = $server->accept()) {          while (1) {
260                  $client->autoflush(1);                  my $client = $server->accept() || next; # ALARM trickle us
261                  my $request = <$client>;                  my $request = <$client>;
262    
263                  warn "request $request\n" if $debug;                  warn "request $request\n" if $debug;
264    
                 Module::Refresh->refresh;  
   
265                  if ($request =~ m{^GET (/.*) HTTP/1.[01]}) {                  if ($request =~ m{^GET (/.*) HTTP/1.[01]}) {
266                          my $path = $1;                          my $path = $1;
267                          my $param;                          my $param;

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

  ViewVC Help
Powered by ViewVC 1.1.26