on master help sign in
using simple-sendfile.
fd73ffbKazu Yamamoto
Network/Wai/Handler/Warp.hs+8−21
@@ -62,7 +62,7 @@ import Control.Exception
62 ( bracket, finally, Exception, SomeException, catch
62 ( bracket, finally, Exception, SomeException, catch
63 , fromException
63 , fromException
64 )
64 )
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)
68
68
@@ -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
83
83
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
185
185
186−sendFileCount :: Integer
187−sendFileCount = 65536
188−
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"
298
295
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
304 then do
301 then do
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
307+ }
311 return $ lookup "content-length" hs /= Nothing
308 return $ lookup "content-length" hs /= Nothing
312 else return True
309 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
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
warp.cabal+1−1
@@ -22,7 +22,7 @@ Library
22 , transformers >= 0.2 && < 0.3
22 , transformers >= 0.2 && < 0.3
23 , enumerator >= 0.4.5 && < 0.5
23 , enumerator >= 0.4.5 && < 0.5
24 , blaze-builder >= 0.2.1.4 && < 0.4
24 , blaze-builder >= 0.2.1.4 && < 0.4
25− , sendfile >= 0.7.2 && < 0.8
25+ , simple-sendfile
26 , http-types >= 0.6 && < 0.7
26 , http-types >= 0.6 && < 0.7
27 , case-insensitive >= 0.2 && < 0.3
27 , case-insensitive >= 0.2 && < 0.3
28 if flag(network-bytestring)
28 if flag(network-bytestring)