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.18 by root, Sat Dec 1 01:37:24 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
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
1package conn; 70package conn;
2 71
3our %blockuri; 72our %blockuri;
4our $blockref; 73our $blockref;
5 74
56 125
57read_blockuri; 126read_blockuri;
58read_blockref; 127read_blockref;
59 128
60use Tie::Cache; 129use Tie::Cache;
61tie %whois_cache, Tie::Cache::, $::MAX_CONNECTS * 1.5; 130tie %whois_cache, Tie::Cache::, 32;
62 131
63sub access_check { 132sub access_check {
64 my $self = shift; 133 my $self = shift;
65 134
66 my $ref = $self->{h}{referer}; 135 my $ref = $self->{h}{referer};
69 138
70 $self->err_block_referer 139 $self->err_block_referer
71 if $self->{h}{referer} =~ $blockref; 140 if $self->{h}{referer} =~ $blockref;
72 141
73 my $whois = $whois_cache{$self->{remote_addr}} 142 my $whois = $whois_cache{$self->{remote_addr}}
74 ||= ::ip_request($self->{remote_addr}); 143 ||= netgeo::ip_request($self->{remote_addr});
75 144
76 my $country = "XX"; 145 my $country = "XX";
77 146
78 if ($whois =~ /^\*cy: (\S+)/m) { 147 if ($whois =~ /^\*cy: (\S+)/m) {
79 $country = uc $1; 148 $country = uc $1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines