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.15 by root, Fri Nov 30 03:06:37 2001 UTC vs.
Revision 1.30 by root, Sun May 19 21:00:47 2002 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines