… | |
… | |
99 | my $self = bless { fh => $fh }, $class; |
99 | my $self = bless { fh => $fh }, $class; |
100 | my (undef, $iaddr) = unpack_sockaddr_in $peername |
100 | my (undef, $iaddr) = unpack_sockaddr_in $peername |
101 | or $self->err(500, "unable to decode peername"); |
101 | or $self->err(500, "unable to decode peername"); |
102 | |
102 | |
103 | $self->{remote_addr} = inet_ntoa $iaddr; |
103 | $self->{remote_addr} = inet_ntoa $iaddr; |
|
|
104 | $self->{time} = $::NOW; |
104 | |
105 | |
105 | # enter ourselves into various lists |
106 | # enter ourselves into various lists |
106 | weaken ($conn{$self->{remote_addr}}{$self*1} = $self); |
107 | weaken ($conn{$self->{remote_addr}}{$self*1} = $self); |
107 | |
108 | |
108 | $self; |
109 | $self; |
… | |
… | |
133 | |
134 | |
134 | $res .= $content if defined $content and $self->{method} eq "GET"; |
135 | $res .= $content if defined $content and $self->{method} eq "GET"; |
135 | |
136 | |
136 | print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n";#d# |
137 | print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n";#d# |
137 | |
138 | |
|
|
139 | $self->{written} += |
138 | print {$self->{fh}} $res; |
140 | print {$self->{fh}} $res; |
139 | } |
141 | } |
140 | |
142 | |
141 | sub err { |
143 | sub err { |
142 | my $self = shift; |
144 | my $self = shift; |
143 | my ($code, $msg, $hdr, $content) = @_; |
145 | my ($code, $msg, $hdr, $content) = @_; |
… | |
… | |
432 | |
434 | |
433 | $h -= $l - 1; |
435 | $h -= $l - 1; |
434 | |
436 | |
435 | while ($h > 0) { |
437 | while ($h > 0) { |
436 | $h -= sysread $fh, $buf, $h > $::BUFSIZE ? $::BUFSIZE : $h; |
438 | $h -= sysread $fh, $buf, $h > $::BUFSIZE ? $::BUFSIZE : $h; |
437 | $self->{fh}->syswrite($buf) |
439 | my $w = $self->{fh}->syswrite($buf) |
438 | or last; |
440 | or last; |
|
|
441 | $::written += $w; |
|
|
442 | $self->{written} += $w; |
439 | } |
443 | } |
440 | } |
444 | } |
441 | |
445 | |
442 | close $fh; |
446 | close $fh; |
443 | } |
447 | } |