ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/myhttpd
(Generate patch)

Comparing Coro/eg/myhttpd (file contents):
Revision 1.10 by root, Wed Apr 11 02:50:01 2007 UTC vs.
Revision 1.11 by root, Wed Apr 11 03:05:15 2007 UTC

42} 42}
43 43
44my $connections = new Coro::Semaphore $MAX_CONNECTS; 44my $connections = new Coro::Semaphore $MAX_CONNECTS;
45 45
46my @fh; 46my @fh;
47my @pool;
48 47
49sub handler { 48# move the event main loop into a coroutine
49async { loop };
50
51slog 1, "accepting connections";
50 while () { 52while () {
51 my $fh = pop @fh; 53 $connections->down;
52 if ($fh) { 54 if (my $fh = $port->accept) {
55 #slog 3, "accepted @$connections ".scalar(@pool);
56 async_pool {
53 eval { 57 eval {
54 conn->new($fh)->handle; 58 conn->new($fh)->handle;
55 }; 59 };
56 close $fh; 60 close $fh;
57 slog 1, "$@" if $@ && !ref $@; 61 slog 1, "$@" if $@ && !ref $@;
58 $connections->up; 62 $connections->up;
59 } else {
60 last if @pool >= $MAX_POOL;
61 push @pool, $Coro::current;
62 schedule;
63 } 63 };
64 } 64 }
65}
66
67# move the event main loop into a coroutine
68async { loop };
69
70slog 1, "accepting connections";
71while () {
72 $connections->down;
73 push @fh, $port->accept;
74 #slog 3, "accepted @$connections ".scalar(@pool);
75 if (@pool) {
76 (pop @pool)->ready;
77 } else {
78 async \&handler;
79 }
80
81} 65}
82 66
83package conn; 67package conn;
84 68
85use Socket; 69use Socket;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines