@@ 66,8 66,11 @@ hGetBytes (SecureHandle h session) n = liftTLS session $ do
pending <- TLS.checkPending
let wait = void $ IO.hWaitForInput h (- 1)
when (pending == 0) (liftIO wait)
- lazy <- TLS.getBytes n
- return (Data.ByteString.concat (Data.ByteString.Lazy.toChunks lazy))
+ Data.ByteString.concat . Data.ByteString.Lazy.toChunks <$> getBytes
+ where
+ getBytes = TLS.getBytes n `E.catchError` handleGetBytesErr
+ handleGetBytesErr (TLS.Error (-28)) = getBytes
+ handleGetBytesErr e = E.throwError e
handleIsSecure :: Handle -> Bool
handleIsSecure PlainHandle{} = False