@@ -62,7 +62,7 @@ import Control.Exception
62 ( bracket, finally, Exception, SomeException, catch
62 ( bracket, finally, Exception, SomeException, catch
63 , fromException
63 , fromException
65−import Control.Concurrent (forkIO, threadWaitWrite)
65+import Control.Concurrent (forkIO)
66import qualified Data.Char as C
66import qualified Data.Char as C
67import Data.Maybe (fromMaybe)
67import Data.Maybe (fromMaybe)
@@ -79,7 +79,7 @@ import Blaze.ByteString.Builder
79 (copyByteString, Builder, toLazyByteString, toByteStringIO)
79 (copyByteString, Builder, toLazyByteString, toByteStringIO)
80import Blaze.ByteString.Builder.Char8 (fromChar, fromShow)
80import Blaze.ByteString.Builder.Char8 (fromChar, fromShow)
81import Data.Monoid (mappend, mconcat)
81import Data.Monoid (mappend, mconcat)
82−import Network.Socket.SendFile (sendFileIterWith,sendFileIterWith', Iter (..))
82+import Network.Sendfile
84import Control.Monad.IO.Class (liftIO)
84import Control.Monad.IO.Class (liftIO)
85import qualified Timeout as T
85import qualified Timeout as T
@@ -183,9 +183,6 @@ bytesPerRead, maxTotalHeaderLength :: Int
183bytesPerRead = 4096
183bytesPerRead = 4096
184maxTotalHeaderLength = 50 * 1024
184maxTotalHeaderLength = 50 * 1024
186−sendFileCount :: Integer
187−sendFileCount = 65536
189data InvalidRequest =
186data InvalidRequest =
190 NotEnoughLines [String]
187 NotEnoughLines [String]
191 | BadFirstLine String
188 | BadFirstLine String
@@ -298,28 +295,18 @@ hasBody s req = s /= (H.Status 204 "") && requestMethod req /= "HEAD"
299sendResponse :: T.Handle
296sendResponse :: T.Handle
300 -> Request -> H.HttpVersion -> Socket -> Response -> IO Bool
297 -> 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
302 Sock.sendMany socket $ L.toChunks $ toLazyByteString $ headers hv s hs False
299 Sock.sendMany socket $ L.toChunks $ toLazyByteString $ headers hv s hs False
303 if hasBody s req
300 if hasBody s req
305 case mpart of
302 case mpart of
306− Nothing -> sendFileIterWith tickler socket fp sendFileCount
303+ Nothing -> sendfile socket fp EntireFile
307− Just part ->
304+ Just part -> sendfile socket fp PartOfFile {
308− sendFileIterWith' tickler socket fp sendFileCount
309− (filePartOffset part)
305+ rangeOffset = filePartOffset part
310− (filePartByteCount part)
306+ , rangeLength = filePartByteCount part
311 return $ lookup "content-length" hs /= Nothing
308 return $ lookup "content-length" hs /= Nothing
312 else return True
309 else return True
318− Sent _ cont -> T.tickle th >> tickler cont
319− WouldBlock _ fd cont -> do
320− -- FIXME do we want to tickle here?
323sendResponse th req hv socket (ResponseBuilder s hs b)
310sendResponse th req hv socket (ResponseBuilder s hs b)
324 | hasBody s req = do
311 | hasBody s req = do
325 toByteStringIO (\bs -> do
312 toByteStringIO (\bs -> do