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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines