@@ -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
@@ -303,23 +300,14 @@ sendResponse th req hv socket (ResponseFile s hs fp mpart) = do
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 (T.tickle th)
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
309 return $ lookup "content-length" hs /= Nothing
312 else return True
310 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)
311sendResponse th req hv socket (ResponseBuilder s hs b)
324 | hasBody s req = do
312 | hasBody s req = do
325 toByteStringIO (\bs -> do
313 toByteStringIO (\bs -> do