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

Comparing Coro/eg/myhttpd (file contents):
Revision 1.7 by root, Mon Feb 25 03:21:09 2002 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} 65}
66
67async {
68 slog 1, "accepting connections";
69 while () {
70 $connections->down;
71 push @fh, $port->accept;
72 #slog 3, "accepted @$connections ".scalar(@pool);
73 if (@pool) {
74 (pop @pool)->ready;
75 } else {
76 async \&handler;
77 }
78
79 }
80};
81
82loop;
83print "ende\n";#d#
84 66
85package conn; 67package conn;
86 68
87use Socket; 69use Socket;
88use HTTP::Date; 70use HTTP::Date;
363 } 345 }
364 } 346 }
365 347
366 close $fh; 348 close $fh;
367} 349}
350

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines