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.11 by root, Thu Nov 29 01:50:41 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 print "$self $trans $trans->[0] <<\n";#d#
15 Scalar::Util::weaken($trans->[0]);
16 14
17 push @{$self->{wait}}, $trans; 15 push @{$self->{wait}}, $trans;
16 Scalar::Util::weaken($self->{wait}[-1]);
18 17
19 if (--$self->{conns} >= 0) { 18 if (--$self->{conns} >= 0) {
20 $self->wake_next; 19 $self->wake_next;
21 } 20 }
22 21
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; 28 while(@{$self->{wait}}) {
30 29 my $transfer = shift @{$self->{wait}};
31 (pop @{$self->{wait}})->wake if @{$self->{wait}}; 30 if ($transfer) {
31 $transfer->wake;
32 last;
33 }
34 }
32} 35}
33 36
34sub waiters { 37sub waiters {
35 map $_->[1], @{$_[0]{wait}}; 38 map $_->[1], @{$_[0]{wait}};
36} 39}
37 40
38package transfer; 41package transfer;
39 42
40use Coro::Timer (); 43use Coro::Timer ();
41 44
42sub try {
43 my $self = shift;
44 my $timeout = Coro::Timer::timeout $_[0];
45
46 Coro::schedule;
47
48 return $self->[2];
49}
50
51sub wake { 45sub wake {
52 my $self = shift; 46 my $self = shift;
53 $self->[2] = 1; 47 $self->[2] = 1;
54 $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];
55} 62}
56 63
57sub DESTROY { 64sub DESTROY {
58 my $self = shift; 65 my $self = shift;
59 $self->[0]{conns}++; 66 $self->[0]{conns}++;
60 $self->[0]->wake_next; 67 $self->[0]->wake_next if $self->[2];
61} 68}
62 69
63package conn; 70package conn;
64 71
65our %blockuri; 72our %blockuri;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines