on master help sign in
Merge pull request #7 from kazu-yamamoto/master

simple-sendfile

commit6221c2323eb722220fd845791e4bb7038b01f391 authorMichael Snoyman <michael@snoyman.com> dateWed 22 Jun 2011, 00:38 (15 years ago) parent6af6111921f7e3
2 files changed+9−21
Network/Wai/Handler/Warp.hs+8−20 warp.cabal+1−1
Network/Wai/Handler/Warp.hs+8−20
@@ -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
@@ -303,23 +300,14 @@ sendResponse th req hv socket (ResponseFile s hs fp mpart) = do
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 (T.tickle th)
304+ Just part -> sendfile socket fp PartOfFile {
305+ rangeOffset = filePartOffset part
306+ , rangeLength = filePartByteCount part
307+ } (T.tickle th)
308+ T.tickle th
311309 return $ lookup "content-length" hs /= Nothing
312310 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
323311sendResponse th req hv socket (ResponseBuilder s hs b)
324312 | hasBody s req = do
325313 toByteStringIO (\bs -> do
warp.cabal+1−1
@@ -22,7 +22,7 @@ Library
2222 , transformers >= 0.2 && < 0.3
2323 , enumerator >= 0.4.5 && < 0.5
2424 , blaze-builder >= 0.2.1.4 && < 0.4
25− , sendfile >= 0.7.2 && < 0.8
25+ , simple-sendfile >= 0.1 && < 0.2
2626 , http-types >= 0.6 && < 0.7
2727 , case-insensitive >= 0.2 && < 0.3
2828 if flag(network-bytestring)