… | |
… | |
34 | our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; |
34 | our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; |
35 | our $httpevent = new Coro::Signal; |
35 | our $httpevent = new Coro::Signal; |
36 | |
36 | |
37 | our $wait_factor = 0.95; |
37 | our $wait_factor = 0.95; |
38 | |
38 | |
39 | our @transfers = ( |
|
|
40 | (new transferqueue $MAX_TRANSFERS_SMALL), |
39 | our $queue_small = new transferqueue $MAX_TRANSFERS_SMALL; |
41 | (new transferqueue $MAX_TRANSFERS_LARGE), |
40 | our $queue_large = new transferqueue $MAX_TRANSFERS_LARGE; |
42 | ); |
41 | our $queue_index = new transferqueue 5; |
43 | |
42 | |
44 | my @newcons; |
43 | my @newcons; |
45 | my @pool; |
44 | my @pool; |
46 | |
45 | |
47 | # one "execution thread" |
46 | # one "execution thread" |
… | |
… | |
448 | or $self->err(304, "not modified"); |
447 | or $self->err(304, "not modified"); |
449 | |
448 | |
450 | if (-r "$path/index.html") { |
449 | if (-r "$path/index.html") { |
451 | # replace directory "size" by index.html filesize |
450 | # replace directory "size" by index.html filesize |
452 | $self->{stat}[7] = (stat ($self->{path} .= "/index.html"))[7]; |
451 | $self->{stat}[7] = (stat ($self->{path} .= "/index.html"))[7]; |
453 | $self->handle_file; |
452 | $self->handle_file($queue_index); |
454 | } else { |
453 | } else { |
455 | $self->handle_dir; |
454 | $self->handle_dir; |
456 | } |
455 | } |
457 | } |
456 | } |
458 | } elsif (-f _ && -r _) { |
457 | } elsif (-f _ && -r _) { |
459 | -x _ and $self->err(403, "forbidden"); |
458 | -x _ and $self->err(403, "forbidden"); |
460 | $self->handle_file; |
459 | $self->handle_file(-s _ >= $::TRANSFER_SMALL ? $queue_large : $queue_small); |
461 | } else { |
460 | } else { |
462 | $self->err(404, "not found"); |
461 | $self->err(404, "not found"); |
463 | } |
462 | } |
464 | } |
463 | } |
465 | } |
464 | } |
… | |
… | |
477 | }, |
476 | }, |
478 | $idx); |
477 | $idx); |
479 | } |
478 | } |
480 | |
479 | |
481 | sub handle_file { |
480 | sub handle_file { |
482 | my $self = shift; |
481 | my ($self, $queue) = @_; |
483 | my $length = $self->{stat}[7]; |
482 | my $length = $self->{stat}[7]; |
484 | my $queue = $::transfers[$length >= $::TRANSFER_SMALL]; |
|
|
485 | my $hdr = { |
483 | my $hdr = { |
486 | "Last-Modified" => time2str ((stat _)[9]), |
484 | "Last-Modified" => time2str ((stat _)[9]), |
487 | }; |
485 | }; |
488 | |
486 | |
489 | my @code = (200, "ok"); |
487 | my @code = (200, "ok"); |