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.18 by root, Sat Dec 1 01:37:24 2001 UTC vs.
Revision 1.31 by root, Thu Nov 21 09:52:34 2002 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
15 push @{$self->{wait}}, $trans;
16 Scalar::Util::weaken($self->{wait}[-1]);
17
18 if (--$self->{conns} >= 0) {
19 $self->wake_next;
20 }
21
22 $trans;
23}
24
25sub wake_next {
26 my $self = shift;
27
28 while(@{$self->{wait}}) {
29 my $transfer = shift @{$self->{wait}};
30 if ($transfer) {
31 $transfer->wake;
32 last;
33 }
34 }
35}
36
37sub waiters {
38 map $_->[1], @{$_[0]{wait}};
39}
40
41package transfer;
42
43use Coro::Timer ();
44
45sub wake {
46 my $self = shift;
47 $self->[2] = 1;
48 ref $self->[1] and $self->[1]->ready;
49}
50
51sub try {
52 my $self = shift;
53
54 unless ($self->[2]) {
55 my $timeout = Coro::Timer::timeout $_[0];
56 local $self->[1] = $Coro::current;
57
58 Coro::schedule;
59 }
60
61 return $self->[2];
62}
63
64sub DESTROY {
65 my $self = shift;
66 $self->[0]{conns}++;
67 $self->[0]->wake_next if $self->[2];
68}
69
70package conn; 1package conn;
71 2
72our %blockuri; 3our %blockuri;
73our $blockref; 4our $blockref;
74 5
137 my %disallow; 68 my %disallow;
138 69
139 $self->err_block_referer 70 $self->err_block_referer
140 if $self->{h}{referer} =~ $blockref; 71 if $self->{h}{referer} =~ $blockref;
141 72
142 my $whois = $whois_cache{$self->{remote_addr}} 73 my $ra = $self->{remote_addr};
143 ||= netgeo::ip_request($self->{remote_addr}); 74 my $whois = $whois_cache{$ra} ||= netgeo::ip_request($ra);
144 75
145 my $country = "XX"; 76 my $country = "XX";
146 77
147 if ($whois =~ /^\*cy: (\S+)/m) { 78 if ($whois =~ /^\*cy: (\S+)/m) {
148 $country = uc $1; 79 $country = uc $1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines