@@ -35,12 +35,11 @@ module Network.Wai.Handler.WarpTLS (
3535import Control.Applicative ((<$>))
3636#endif
3737import Control.Exception (Exception, throwIO, bracket, finally, handle, fromException, try, IOException, onException)
38−import Control.Monad (unless, void)
38+import Control.Monad (void)
3939import qualified Crypto.Random.AESCtr
4040import qualified Data.ByteString as B
4141import qualified Data.ByteString as S
4242import qualified Data.ByteString.Lazy as L
43−import Data.ByteString.Lazy.Internal (defaultChunkSize)
4443import Data.Default.Class (def)
4544import qualified Data.IORef as I
4645import Data.Streaming.Network (bindPortTCP, safeRecv)
@@ -52,7 +51,6 @@ import qualified Network.TLS.Extra as TLSExtra
5251import Network.Wai (Application)
5352import Network.Wai.Handler.Warp
5453import Network.Wai.Handler.Warp.Buffer (allocateBuffer, bufferSize, freeBuffer)
55−import qualified System.IO as IO
5654import System.IO.Error (isEOFError)
5755
5856----------------------------------------------------------------
@@ -285,7 +283,7 @@ httpOverTls TLSSettings{..} s cachedRef params = do
285283 }
286284 conn ctx pool writeBuf = Connection {
287285 connSendMany = TLS.sendData ctx . L.fromChunks
288− , connSendAll = TLS.sendData ctx . L.fromChunks . return
286+ , connSendAll = sendall
289287 , connSendFile = sendfile
290288 , connClose = close
291289 , connRecv = recv
@@ -294,21 +292,9 @@ httpOverTls TLSSettings{..} s cachedRef params = do
294292 , connBufferSize = bufferSize
295293 }
296294 where
297− sendfile fid offset len tickle' headers = do
298− let fp = fileIdPath fid
299− TLS.sendData ctx $ L.fromChunks headers
300− IO.withBinaryFile fp IO.ReadMode $ \h -> do
301− IO.hSeek h IO.AbsoluteSeek offset
302− loop h $ fromIntegral len
303− where
304− loop _ remaining | remaining <= 0 = return ()
305− loop h remaining = do
306− bs <- B.hGetSome h defaultChunkSize
307− unless (B.null bs) $ do
308− let x = B.take remaining bs
309− TLS.sendData ctx $ L.fromChunks [x]
310− void $ tickle' -- This tickles the Timer. It MUST be called per chunk.
311− loop h $ remaining - B.length x
295+ sendall = TLS.sendData ctx . L.fromChunks . return
296+ sendfile fid offset len hook headers =
297+ readSendFile writeBuf bufferSize sendall fid offset len hook headers
312298
313299 close = freeBuffer writeBuf `finally`
314300 void (tryIO $ TLS.bye ctx) `finally`