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.11 by root, Thu Nov 29 01:50:41 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, $Coro::current ], transfer::;
14 print "$self $trans $trans->[0] <<\n";#d#
15 Scalar::Util::weaken($trans->[0]);
16
17 push @{$self->{wait}}, $trans;
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 return unless $self->{conns} >= 0;
30
31 (pop @{$self->{wait}})->wake if @{$self->{wait}};
32}
33
34sub waiters {
35 map $_->[1], @{$_[0]{wait}};
36}
37
38package transfer;
39
40use Coro::Timer ();
41
42sub try {
43 my $self = shift;
44 my $timeout = Coro::Timer::timeout $_[0];
45
46 Coro::schedule;
47
48 return $self->[2];
49}
50
51sub wake {
52 my $self = shift;
53 $self->[2] = 1;
54 $self->[1]->ready;
55}
56
57sub DESTROY {
58 my $self = shift;
59 $self->[0]{conns}++;
60 $self->[0]->wake_next;
61}
62
1package conn; 63package conn;
2 64
3our %blockuri; 65our %blockuri;
4our $blockref; 66our $blockref;
5 67
56 118
57read_blockuri; 119read_blockuri;
58read_blockref; 120read_blockref;
59 121
60use Tie::Cache; 122use Tie::Cache;
61tie %whois_cache, Tie::Cache::, $::MAX_CONNECTS * 1.5; 123tie %whois_cache, Tie::Cache::, 32;
62 124
63sub access_check { 125sub access_check {
64 my $self = shift; 126 my $self = shift;
65 127
66 my $ref = $self->{h}{referer}; 128 my $ref = $self->{h}{referer};
69 131
70 $self->err_block_referer 132 $self->err_block_referer
71 if $self->{h}{referer} =~ $blockref; 133 if $self->{h}{referer} =~ $blockref;
72 134
73 my $whois = $whois_cache{$self->{remote_addr}} 135 my $whois = $whois_cache{$self->{remote_addr}}
74 ||= ::ip_request($self->{remote_addr}); 136 ||= netgeo::ip_request($self->{remote_addr});
75 137
76 my $country = "XX"; 138 my $country = "XX";
77 139
78 if ($whois =~ /^\*cy: (\S+)/m) { 140 if ($whois =~ /^\*cy: (\S+)/m) {
79 $country = uc $1; 141 $country = uc $1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines