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.14 by root, Fri Nov 30 03:02:23 2001 UTC vs.
Revision 1.17 by root, Sat Dec 1 01:09:56 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 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
49sub wake {
50 my $self = shift;
51 $self->[2] = 1;
52 ref $self->[1] and $self->[1]->ready;
53}
54
48sub try { 55sub try {
49 my $self = shift; 56 my $self = shift;
50 my $timeout = Coro::Timer::timeout $_[0];
51 57
52 $self->[2] or Coro::schedule; 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 }
53 65
54 return $self->[2]; 66 return $self->[2];
55} 67}
56 68
57sub wake {
58 my $self = shift;
59 $self->[2] = 1;
60 $self->[1]->ready;
61}
62
63sub DESTROY { 69sub DESTROY {
64 my $self = shift; 70 my $self = shift;
71 eval {
65 $self->[0]{conns}++; 72 $self->[0]{conns}++;
66 $self->[0]->wake_next; 73 $self->[0]->wake_next;
74 };
75 print "DESTROY $Coro::current $@\n";#d#
67} 76}
68 77
69package conn; 78package conn;
70 79
71our %blockuri; 80our %blockuri;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines