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.14 by root, Fri Nov 30 03:02: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, $Coro::current ], 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 $self->[2] or Coro::schedule;
53
54 return $self->[2];
55}
56
57sub wake {
58 my $self = shift;
59 $self->[2] = 1;
60 $self->[1]->ready;
61}
62
63sub DESTROY {
64 my $self = shift;
65 $self->[0]{conns}++;
66 $self->[0]->wake_next;
67}
68
1package conn; 69package conn;
2 70
3our %blockuri; 71our %blockuri;
4our $blockref; 72our $blockref;
5 73
56 124
57read_blockuri; 125read_blockuri;
58read_blockref; 126read_blockref;
59 127
60use Tie::Cache; 128use Tie::Cache;
61tie %whois_cache, Tie::Cache::, $::MAX_CONNECTS * 1.5; 129tie %whois_cache, Tie::Cache::, 32;
62 130
63sub access_check { 131sub access_check {
64 my $self = shift; 132 my $self = shift;
65 133
66 my $ref = $self->{h}{referer}; 134 my $ref = $self->{h}{referer};
69 137
70 $self->err_block_referer 138 $self->err_block_referer
71 if $self->{h}{referer} =~ $blockref; 139 if $self->{h}{referer} =~ $blockref;
72 140
73 my $whois = $whois_cache{$self->{remote_addr}} 141 my $whois = $whois_cache{$self->{remote_addr}}
74 ||= ::ip_request($self->{remote_addr}); 142 ||= netgeo::ip_request($self->{remote_addr});
75 143
76 my $country = "XX"; 144 my $country = "XX";
77 145
78 if ($whois =~ /^\*cy: (\S+)/m) { 146 if ($whois =~ /^\*cy: (\S+)/m) {
79 $country = uc $1; 147 $country = uc $1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines