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

Comparing Coro/myhttpd/httpd.pl (file contents):
Revision 1.15 by root, Tue Aug 14 02:28:51 2001 UTC vs.
Revision 1.16 by root, Tue Aug 14 19:38:25 2001 UTC

70package conn; 70package conn;
71 71
72use Socket; 72use Socket;
73use HTTP::Date; 73use HTTP::Date;
74use Convert::Scalar 'weaken'; 74use Convert::Scalar 'weaken';
75use Linux::AIO;
76
77Linux::AIO::min_parallel $::AIO_PARALLEL;
78
79Event->io(fd => Linux::AIO::poll_fileno,
80 poll => 'r',
81 async => 1,
82 cb => \&Linux::AIO::poll_cb );
83
84Event->add_hooks(prepare => sub {
85 &Coro::cede while &Coro::nready;
86 1e6;
87});
75 88
76our %conn; # $conn{ip}{fh} => connobj 89our %conn; # $conn{ip}{fh} => connobj
77our %blocked; 90our %blocked;
78our %mimetype; 91our %mimetype;
79 92
427 $hdr->{"Content-Length"} = $length; 440 $hdr->{"Content-Length"} = $length;
428 441
429 $self->response(@code, $hdr, ""); 442 $self->response(@code, $hdr, "");
430 443
431 if ($self->{method} eq "GET") { 444 if ($self->{method} eq "GET") {
432 my ($fh, $buf); 445 my ($fh, $buf, $r);
446 my $current = $Coro::current;
433 open $fh, "<", $self->{path} 447 open $fh, "<", $self->{path}
434 or die "$self->{path}: late open failure ($!)"; 448 or die "$self->{path}: late open failure ($!)";
435 449
436 if ($l) {
437 sysseek $fh, $l, 0
438 or die "$self->{path}: cannot seek to $l ($!)";
439 }
440
441 $h -= $l - 1; 450 $h -= $l - 1;
442 451
443 while ($h > 0) { 452 while ($h > 0) {
444 $h -= sysread $fh, $buf, $h > $::BUFSIZE ? $::BUFSIZE : $h; 453 aio_read($fh, $l, ($h > $::BUFSIZE ? $::BUFSIZE : $h),
454 $buf, 0, sub {
455 $r = $_[0];
456 $current->ready;
457 });
458 &Coro::schedule;
459 last unless $r;
445 my $w = $self->{fh}->syswrite($buf) 460 my $w = $self->{fh}->syswrite($buf)
446 or last; 461 or last;
447 $::written += $w; 462 $::written += $w;
448 $self->{written} += $w; 463 $self->{written} += $w;
464 $l += $r;
449 } 465 }
450 } 466 }
451 467
452 close $fh; 468 close $fh;
453} 469}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines