catch in streamBody

This commit is contained in:
spaced4ndy
2023-04-25 13:16:15 +04:00
parent 4a64061aab
commit 50ee2df48d
+9 -3
View File
@@ -9,6 +9,7 @@
module Simplex.FileTransfer.Client where
import qualified Control.Exception as E
import Control.Monad.Except
import Data.Bifunctor (first)
import Data.ByteString.Builder (Builder, byteString)
@@ -154,9 +155,14 @@ sendXFTPCommand XFTPClient {config, http2Client = http2@HTTP2Client {sessionId}}
streamBody t send done = do
send $ byteString t
forM_ chunkSpec_ $ \XFTPChunkSpec {filePath, chunkOffset, chunkSize} ->
withFile filePath ReadMode $ \h -> do
hSeek h AbsoluteSeek $ fromIntegral chunkOffset
sendFile h send $ fromIntegral chunkSize
do
( withFile filePath ReadMode $ \h -> do
hSeek h AbsoluteSeek $ fromIntegral chunkOffset
sendFile h send $ fromIntegral chunkSize
)
`E.catch` \(e :: SomeException) -> do
print $ "in sendXFTPCommand streamBody " <> show e
E.throw e
done
createXFTPChunk ::