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

Comparing Coro/myhttpd/access.pl (file contents):
Revision 1.8 by root, Sun Aug 26 14:55:46 2001 UTC vs.
Revision 1.15 by root, Fri Nov 30 03:06:37 2001 UTC

1package transferqueue;
2
3sub new {
4 my $class = shift;
5 bless {
6 conns => $_[0],
7 }, $class;
8}
9
10sub start_transfer {
11 my $self = shift;
12
13 my $trans = bless [ $self ], transfer::;
14 Scalar::Util::weaken($trans->[0]);
15
16 push @{$self->{wait}}, $trans;
17 Scalar::Util::weaken($self->{wait}[-1]);
18
19 if (--$self->{conns} >= 0) {
20 $self->wake_next;
21 }
22
23 $trans;
24}
25
26sub wake_next {
27 my $self = shift;
28
29 if ($self->{conns} >= 0) {
30 while(@{$self->{wait}}) {
31 my $transfer = shift @{$self->{wait}};
32 if ($transfer) {
33 $transfer->wake;
34 last;
35 }
36 }
37 }
38}
39
40sub waiters {
41 map $_->[1], @{$_[0]{wait}};
42}
43
44package transfer;
45
46use Coro::Timer ();
47
48sub try {
49 my $self = shift;
50 my $timeout = Coro::Timer::timeout $_[0];
51
52 unless ($self->[2]) {
53 local $self->[1] = $Coro::current;
54 Coro::schedule;
55 }
56
57 return $self->[2];
58}
59
60sub wake {
61 my $self = shift;
62 $self->[2] = 1;
63 ref $self->[1] and $self->[1]->ready;
64}
65
66sub DESTROY {
67 my $self = shift;
68 $self->[0]{conns}++;
69 $self->[0]->wake_next;
70}
71
1package conn; 72package conn;
2 73
3our %blockuri; 74our %blockuri;
4our $blockref; 75our $blockref;
5 76
56 127
57read_blockuri; 128read_blockuri;
58read_blockref; 129read_blockref;
59 130
60use Tie::Cache; 131use Tie::Cache;
61tie %whois_cache, Tie::Cache::, $::MAX_CONNECTS * 1.5; 132tie %whois_cache, Tie::Cache::, 32;
62 133
63sub access_check { 134sub access_check {
64 my $self = shift; 135 my $self = shift;
65 136
66 my $ref = $self->{h}{referer}; 137 my $ref = $self->{h}{referer};
69 140
70 $self->err_block_referer 141 $self->err_block_referer
71 if $self->{h}{referer} =~ $blockref; 142 if $self->{h}{referer} =~ $blockref;
72 143
73 my $whois = $whois_cache{$self->{remote_addr}} 144 my $whois = $whois_cache{$self->{remote_addr}}
74 ||= ::ip_request($self->{remote_addr}); 145 ||= netgeo::ip_request($self->{remote_addr});
75 146
76 my $country = "XX"; 147 my $country = "XX";
77 148
78 if ($whois =~ /^\*cy: (\S+)/m) { 149 if ($whois =~ /^\*cy: (\S+)/m) {
79 $country = uc $1; 150 $country = uc $1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines