@@ -62,7 +62,7 @@ import Control.Exception
6262 ( bracket, finally, Exception, SomeException, catch
6363 , fromException
6464 )
65−import Control.Concurrent (forkIO, threadWaitWrite)
65+import Control.Concurrent (forkIO)
6666import qualified Data.Char as C
6767import Data.Maybe (fromMaybe)
6868
@@ -79,7 +79,7 @@ import Blaze.ByteString.Builder
7979 (copyByteString, Builder, toLazyByteString, toByteStringIO)
8080import Blaze.ByteString.Builder.Char8 (fromChar, fromShow)
8181import Data.Monoid (mappend, mconcat)
82−import Network.Socket.SendFile (sendFileIterWith,sendFileIterWith', Iter (..))
82+import Network.Sendfile
8383
8484import Control.Monad.IO.Class (liftIO)
8585import qualified Timeout as T
@@ -183,9 +183,6 @@ bytesPerRead, maxTotalHeaderLength :: Int
183183bytesPerRead = 4096
184184maxTotalHeaderLength = 50 * 1024
185185
186−sendFileCount :: Integer
187−sendFileCount = 65536
188−
189186data InvalidRequest =
190187 NotEnoughLines [String]
191188 | BadFirstLine String
@@ -298,28 +295,18 @@ hasBody s req = s /= (H.Status 204 "") && requestMethod req /= "HEAD"
298295
299296sendResponse :: T.Handle
300297 -> Request -> H.HttpVersion -> Socket -> Response -> IO Bool
301−sendResponse th req hv socket (ResponseFile s hs fp mpart) = do
298+sendResponse _ req hv socket (ResponseFile s hs fp mpart) = do
302299 Sock.sendMany socket $ L.toChunks $ toLazyByteString $ headers hv s hs False
303300 if hasBody s req
304301 then do
305302 case mpart of
306− Nothing -> sendFileIterWith tickler socket fp sendFileCount
307− Just part ->
308− sendFileIterWith' tickler socket fp sendFileCount
309− (filePartOffset part)
310− (filePartByteCount part)
303+ Nothing -> sendfile socket fp EntireFile
304+ Just part -> sendfile socket fp PartOfFile {
305+ rangeOffset = filePartOffset part
306+ , rangeLength = filePartByteCount part
307+ }
311308 return $ lookup "content-length" hs /= Nothing
312309 else return True
313− where
314− tickler iter = do
315− r <- iter
316− case r of
317− Done _ -> return ()
318− Sent _ cont -> T.tickle th >> tickler cont
319− WouldBlock _ fd cont -> do
320− -- FIXME do we want to tickle here?
321− threadWaitWrite fd
322− tickler cont
323310sendResponse th req hv socket (ResponseBuilder s hs b)
324311 | hasBody s req = do
325312 toByteStringIO (\bs -> do