ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Coro/myhttpd/httpd.pl
(Generate patch)

Comparing cvsroot/Coro/myhttpd/httpd.pl (file contents):
Revision 1.86 by root, Tue Jun 3 13:35:13 2008 UTC vs.
Revision 1.89 by root, Sun Jan 24 20:44:34 2010 UTC

75 $queue_file->force_wake_next; 75 $queue_file->force_wake_next;
76 slog 1, "forced filetransfer due to unused bandwidth"; 76 slog 1, "forced filetransfer due to unused bandwidth";
77 } 77 }
78} 78}
79 79
80my @newcons;
81my @pool;
82
83# one "execution thread"
84sub handler {
85 while () {
86 if (@newcons) {
87 eval {
88 conn->new (@{pop @newcons})->handle;
89 };
90 slog 1, "$@" if $@ && !ref $@;
91
92 $httpevent->broadcast; # only for testing, but doesn't matter much
93
94 $connections->up;
95 } else {
96 last if @pool >= $MAX_POOL;
97 push @pool, $Coro::current;
98 schedule;
99 }
100 }
101}
102
103sub listen_on { 80sub listen_on {
104 my $listen = $_[0]; 81 my $listen = $_[0];
105 82
106 push @listen_sockets, $listen; 83 push @listen_sockets, $listen;
107 84
108 # the "main thread" 85 # the "main thread"
109 async { 86 async {
110 slog 1, "accepting connections"; 87 slog 1, "accepting connections";
111 while () { 88 while () {
112 $connections->down; 89 $connections->down;
113 push @newcons, [$listen->accept]; 90 my @conn = $listen->accept;
114 #slog 3, "accepted @$connections ".scalar(@pool); 91 #slog 3, "accepted @$connections ".scalar(@pool);
115 if (@pool) { 92
116 (pop @pool)->ready; 93 async_pool {
117 } else { 94 eval {
118 async \&handler; 95 conn->new (@conn)->handle;
96 };
97 slog 1, "$@" if $@ && !ref $@;
98
99 $httpevent->broadcast; # only for testing, but doesn't matter much
100
101 $connections->up;
119 } 102 }
120 } 103 }
121 }; 104 };
122} 105}
123 106
483 } else { 466 } else {
484 $self->err (404, "not found"); 467 $self->err (404, "not found");
485 } 468 }
486 } else { 469 } else {
487 470
488 stat $path 471 Coro::AIO::aio_stat $path
489 or $self->err (404, "not found"); 472 and $self->err (404, "not found");
490 473
491 $self->{stat} = [stat _]; 474 $self->{stat} = [stat _];
492 475
493 # idiotic netscape sends idiotic headers AGAIN 476 # idiotic netscape sends idiotic headers AGAIN
494 my $ims = $self->{h}{"if-modified-since"} =~ /^([^;]+)/ 477 my $ims = $self->{h}{"if-modified-since"} =~ /^([^;]+)/
631 614
632 Coro::AIO::aio_read $fh, $l, ($h > $bufsize ? $bufsize : $h), my $buf, 0 615 Coro::AIO::aio_read $fh, $l, ($h > $bufsize ? $bufsize : $h), my $buf, 0
633 or last; 616 or last;
634 617
635 $tbf->request (length $buf); 618 $tbf->request (length $buf);
636 my $w = syswrite $self->{fh}, $buf 619 my $w = $self->{fh}->syswrite ($buf)
637 or last; 620 or last;
638 $::written += $w; 621 $::written += $w;
639 $self->{written} += $w; 622 $self->{written} += $w;
640 $l += $w; 623 $l += $w;
641 } 624 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines