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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines