ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Coro/myhttpd/access.pl
(Generate patch)

Comparing cvsroot/Coro/myhttpd/access.pl (file contents):
Revision 1.8 by root, Sun Aug 26 14:55:46 2001 UTC vs.
Revision 1.19 by root, Mon Dec 3 04:57:22 2001 UTC

1package transferqueue;
2
3sub new {
4 my $class = shift;
5 bless {
6 slots => $_[0],
7 lastspb => 0,
8 }, $class;
9}
10
11sub start_transfer {
12 my $self = shift;
13 my $size = $_[0];
14
15 my $trans = bless {
16 queue => $self,
17 time => $::NOW,
18 size => $size,
19 coro => $Coro::current,
20 }, transfer::;
21
22 push @{$self->{wait}}, $trans;
23 Scalar::Util::weaken($self->{wait}[-1]);
24
25 $self->wake_next;
26
27 $trans;
28}
29
30sub wake_next {
31 my $self = shift;
32
33 $self->sort;
34
35 while($self->{slots} && @{$self->{wait}}) {
36 my $transfer = shift @{$self->{wait}};
37 if ($transfer) {
38 $self->{lastspb} = $transfer->{spb};
39 $transfer->wake;
40 last;
41 }
42 }
43}
44
45sub sort {
46 $_[0]{wait} = [
47 sort { $b->{spb} <=> $a->{spb} }
48 grep { $_ && ($_->{spb} = ($::NOW-$_->{time})/($_->{size}||1)), $_ }
49 @{$_[0]{wait}}
50 ];
51}
52
53sub waiters {
54 $_[0]->sort;
55 @{$_[0]{wait}};
56}
57
58package transfer;
59
60use Coro::Timer ();
61
62sub wake {
63 my $self = shift;
64
65 $self->{alloc} = 1;
66 $self->{queue}{slots}--;
67 $self->{wake} and $self->{wake}->ready;
68}
69
70sub try {
71 my $self = shift;
72
73 $self->{alloc} || do {
74 my $timeout = Coro::Timer::timeout $_[0];
75 local $self->{wake} = $self->{coro};
76
77 Coro::schedule;
78
79 $self->{alloc};
80 }
81}
82
83sub DESTROY {
84 my $self = shift;
85
86 if ($self->{alloc}) {
87 $self->{queue}{slots}++;
88 $self->{queue}->wake_next;
89 }
90}
91
1package conn; 92package conn;
2 93
3our %blockuri; 94our %blockuri;
4our $blockref; 95our $blockref;
5 96
56 147
57read_blockuri; 148read_blockuri;
58read_blockref; 149read_blockref;
59 150
60use Tie::Cache; 151use Tie::Cache;
61tie %whois_cache, Tie::Cache::, $::MAX_CONNECTS * 1.5; 152tie %whois_cache, Tie::Cache::, 32;
62 153
63sub access_check { 154sub access_check {
64 my $self = shift; 155 my $self = shift;
65 156
66 my $ref = $self->{h}{referer}; 157 my $ref = $self->{h}{referer};
69 160
70 $self->err_block_referer 161 $self->err_block_referer
71 if $self->{h}{referer} =~ $blockref; 162 if $self->{h}{referer} =~ $blockref;
72 163
73 my $whois = $whois_cache{$self->{remote_addr}} 164 my $whois = $whois_cache{$self->{remote_addr}}
74 ||= ::ip_request($self->{remote_addr}); 165 ||= netgeo::ip_request($self->{remote_addr});
75 166
76 my $country = "XX"; 167 my $country = "XX";
77 168
78 if ($whois =~ /^\*cy: (\S+)/m) { 169 if ($whois =~ /^\*cy: (\S+)/m) {
79 $country = uc $1; 170 $country = uc $1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines