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.9 by root, Tue Aug 28 02:30:48 2001 UTC vs.
Revision 1.13 by root, Thu Nov 29 02:30:04 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 return unless $self->{conns} >= 0;
30
31 if (@{$self->{wait}}) {
32 while() {
33 my $transfer = shift @{$self->{wait}};
34 if ($transfer) {
35 $transfer->wake;
36 last;
37 }
38 }
39 }
40}
41
42sub waiters {
43 map $_->[1], @{$_[0]{wait}};
44}
45
46package transfer;
47
48use Coro::Timer ();
49
50sub try {
51 my $self = shift;
52 my $timeout = Coro::Timer::timeout $_[0];
53
54 Coro::schedule;
55
56 return $self->[2];
57}
58
59sub wake {
60 my $self = shift;
61 $self->[2] = 1;
62 $self->[1]->ready;
63}
64
65sub DESTROY {
66 my $self = shift;
67 $self->[0]{conns}++;
68 $self->[0]->wake_next;
69}
70
1package conn; 71package conn;
2 72
3our %blockuri; 73our %blockuri;
4our $blockref; 74our $blockref;
5 75
56 126
57read_blockuri; 127read_blockuri;
58read_blockref; 128read_blockref;
59 129
60use Tie::Cache; 130use Tie::Cache;
61tie %whois_cache, Tie::Cache::, $::MAX_CONNECTS * 1.5; 131tie %whois_cache, Tie::Cache::, 32;
62 132
63sub access_check { 133sub access_check {
64 my $self = shift; 134 my $self = shift;
65 135
66 my $ref = $self->{h}{referer}; 136 my $ref = $self->{h}{referer};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines