avoid hGetMetered 0 closing the handle
This is an edge case, which happened to be triggered by the P2P protocol seeing DATA 0. When reading 0 bytes, getting an empty string does not mean the handle has reached EOF. I verified there was in fact a bug, where get of an empty file followed by another file would get the empty file and then fail with "handle is closed". This fixes it. This commit was sponsored by Boyd Stephen Smith Jr. on Patreon.
This commit is contained in:
parent
41bb873319
commit
92136284b1
3 changed files with 33 additions and 2 deletions
|
@ -169,8 +169,9 @@ hGetMetered h wantsize meterupdate = lazyRead zeroBytesProcessed
|
|||
c <- S.hGet h (nextchunksize (fromBytesProcessed sofar))
|
||||
if S.null c
|
||||
then do
|
||||
hClose h
|
||||
return $ L.empty
|
||||
when (wantsize /= Just 0) $
|
||||
hClose h
|
||||
return L.empty
|
||||
else do
|
||||
let !sofar' = addBytesProcessed sofar (S.length c)
|
||||
meterupdate sofar'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue