@@ -56,10 +56,10 @@ sub reply {
56
56
push @hdrs , " Content-Length: " .length ($str ) if defined ($str );
57
57
my $data = join (" \r\n " , @hdrs )." \r\n\r\n " ;
58
58
$data .= $str if defined $str ;
59
- fcntl ($sock , F_SETFL,O_NONBLOCK);
59
+ fcntl ($sock , F_SETFL, O_NONBLOCK);
60
60
my $dummy = ' ' ;
61
61
1 while sysread ($sock , $dummy , 1024, 0);
62
- fcntl ($sock , F_SETFL,0);
62
+ fcntl ($sock , F_SETFL, 0);
63
63
replyraw($data );
64
64
}
65
65
@@ -206,23 +206,23 @@ eval {
206
206
die (" stat: $! \n " ) unless @s ;
207
207
my $l = $s [7];
208
208
reply(undef , " Content-Length: $l " , ' Content-Type: application/octet-stream' );
209
+ $l = 0 if $action eq ' HEAD' ;
209
210
my $data ;
210
- while (1) {
211
- last unless $l ;
212
- my $r = sysread ($f , $data , 8192);
211
+ while ($l > 0) {
212
+ die (" unexpected EOF in data\n " ) unless sysread ($f , $data , 8192);
213
213
$data = substr ($data , 0, $l ) if length ($data ) > $l ;
214
214
$l -= length ($data );
215
- while (length ($data )) {
216
- my $l2 = syswrite ($sock , $data , length ($data ));
217
- die (" socket write: $! \n " ) unless $l2 ;
218
- $data = substr ($data , $l2 );
219
- }
215
+ replyraw($data );
220
216
}
221
217
close ($f );
222
218
} else {
223
219
die (" 404 File not found\n " );
224
220
}
225
221
};
226
- reply_error($@ ) if $@ ;
222
+ if ($@ ) {
223
+ my $err = $@ ;
224
+ eval { reply_error($err ) };
225
+ print " [$@ ]" if $@ ;
226
+ }
227
227
close $sock ;
228
228
print " [$status $path ]" ;
0 commit comments