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.13 by root, Thu Nov 29 02:30:04 2001 UTC vs.
Revision 1.18 by root, Sat Dec 1 01:37:24 2001 UTC

8} 8}
9 9
10sub start_transfer { 10sub start_transfer {
11 my $self = shift; 11 my $self = shift;
12 12
13 my $trans = bless [ $self, $Coro::current ], transfer::; 13 my $trans = bless [ $self ], transfer::;
14 Scalar::Util::weaken($trans->[0]);
15 14
16 push @{$self->{wait}}, $trans; 15 push @{$self->{wait}}, $trans;
17 Scalar::Util::weaken($self->{wait}[-1]); 16 Scalar::Util::weaken($self->{wait}[-1]);
18 17
19 if (--$self->{conns} >= 0) { 18 if (--$self->{conns} >= 0) {
24} 23}
25 24
26sub wake_next { 25sub wake_next {
27 my $self = shift; 26 my $self = shift;
28 27
29 return unless $self->{conns} >= 0;
30
31 if (@{$self->{wait}}) { 28 while(@{$self->{wait}}) {
32 while() {
33 my $transfer = shift @{$self->{wait}}; 29 my $transfer = shift @{$self->{wait}};
34 if ($transfer) { 30 if ($transfer) {
35 $transfer->wake; 31 $transfer->wake;
36 last; 32 last;
37 }
38 } 33 }
39 } 34 }
40} 35}
41 36
42sub waiters { 37sub waiters {
45 40
46package transfer; 41package transfer;
47 42
48use Coro::Timer (); 43use Coro::Timer ();
49 44
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 { 45sub wake {
60 my $self = shift; 46 my $self = shift;
61 $self->[2] = 1; 47 $self->[2] = 1;
62 $self->[1]->ready; 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];
63} 62}
64 63
65sub DESTROY { 64sub DESTROY {
66 my $self = shift; 65 my $self = shift;
67 $self->[0]{conns}++; 66 $self->[0]{conns}++;
68 $self->[0]->wake_next; 67 $self->[0]->wake_next if $self->[2];
69} 68}
70 69
71package conn; 70package conn;
72 71
73our %blockuri; 72our %blockuri;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines