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.15 by root, Fri Nov 30 03:06:37 2001 UTC vs.
Revision 1.17 by root, Sat Dec 1 01:09:56 2001 UTC

9 9
10sub start_transfer { 10sub start_transfer {
11 my $self = shift; 11 my $self = shift;
12 12
13 my $trans = bless [ $self ], 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 print "ALLOC $Coro::current\n";#d#
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 if ($self->{conns} >= 0) { 28 while ($self->{conns} >= 0 && @{$self->{wait}}) {
29 print "WAKING some\n";#d#
30 while(@{$self->{wait}}) { 30 while(@{$self->{wait}}) {
31 my $transfer = shift @{$self->{wait}}; 31 my $transfer = shift @{$self->{wait}};
32 if ($transfer) { 32 if ($transfer) {
33 print "WAKING $transfer\n";#d#
33 $transfer->wake; 34 $transfer->wake;
34 last; 35 last;
35 } 36 }
36 } 37 }
37 } 38 }
43 44
44package transfer; 45package transfer;
45 46
46use Coro::Timer (); 47use Coro::Timer ();
47 48
48sub try {
49 my $self = shift;
50 my $timeout = Coro::Timer::timeout $_[0];
51
52 unless ($self->[2]) {
53 local $self->[1] = $Coro::current;
54 Coro::schedule;
55 }
56
57 return $self->[2];
58}
59
60sub wake { 49sub wake {
61 my $self = shift; 50 my $self = shift;
62 $self->[2] = 1; 51 $self->[2] = 1;
63 ref $self->[1] and $self->[1]->ready; 52 ref $self->[1] and $self->[1]->ready;
64} 53}
65 54
55sub try {
56 my $self = shift;
57
58 unless ($self->[2]) {
59 my $timeout = Coro::Timer::timeout $_[0];
60 local $self->[1] = $Coro::current;
61
62 Coro::schedule;
63 print "WOKE $Coro::current\n" if $self->[2];
64 }
65
66 return $self->[2];
67}
68
66sub DESTROY { 69sub DESTROY {
67 my $self = shift; 70 my $self = shift;
71 eval {
68 $self->[0]{conns}++; 72 $self->[0]{conns}++;
69 $self->[0]->wake_next; 73 $self->[0]->wake_next;
74 };
75 print "DESTROY $Coro::current $@\n";#d#
70} 76}
71 77
72package conn; 78package conn;
73 79
74our %blockuri; 80our %blockuri;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines