on master help sign in
0 of settingsFdCacheDuration means disabling FD caching.
commit85aaa7aff3341dc126d57e408d7d28cf1543e744 authorKazu Yamamoto <kazu@iij.ad.jp> dateWed 3 Oct 2012, 16:35 (14 years ago) parentb335538
3 files changed+12−6
warp/Network/Wai/Handler/Warp/Run.hs+10−4 warp/Network/Wai/Handler/Warp/Settings.hs+1−1 warp/Network/Wai/Handler/Warp/Types.hs+1−1
warp/Network/Wai/Handler/Warp/Run.hs+10−4
@@ -44,6 +44,7 @@ import Network.Socket (withSocketsDo)
4444#endif
4545
4646#if SENDFILEFD
47+import Control.Applicative
4748import qualified Network.Wai.Handler.Warp.FdCache as F
4849#endif
4950
@@ -71,9 +72,11 @@ socketConnection s = Connection
7172
7273sendFile :: Socket -> FilePath -> Integer -> Integer -> IO () -> [ByteString] -> Cleaner -> IO ()
7374#if SENDFILEFD
74−sendFile s path off len act hdr cleaner = do
75− (fd, fresher) <- F.getFd (fdCacher cleaner) path
76− sendfileFdWithHeader s fd (PartOfFile off len) (act>>fresher) hdr
75+sendFile s path off len act hdr cleaner = case fdCacher cleaner of
76+ Nothing -> sendfileWithHeader s path (PartOfFile off len) act hdr
77+ Just fdc -> do
78+ (fd, fresher) <- F.getFd fdc path
79+ sendfileFdWithHeader s fd (PartOfFile off len) (act>>fresher) hdr
7780#else
7881sendFile s path off len act hdr _ =
7982 sendfileWithHeader s path (PartOfFile off len) act hdr
@@ -129,7 +132,10 @@ runSettingsConnection set getConn app = do
129132 tm <- maybe (T.initialize $ settingsTimeout set * 1000000) return
130133 $ settingsManager set
131134#if SENDFILEFD
132− fc <- F.initialize (settingsFdCacheDuration set * 1000000)
135+ let duration = settingsFdCacheDuration set
136+ fc <- case duration of
137+ 0 -> return Nothing
138+ _ -> Just <$> F.initialize (duration * 1000000)
133139#endif
134140 mask $ \restore -> forever $ do
135141 allowInterrupt
warp/Network/Wai/Handler/Warp/Settings.hs+1−1
@@ -25,7 +25,7 @@ data Settings = Settings
2525 , settingsTimeout :: Int -- ^ Timeout value in seconds. Default value: 30
2626 , settingsIntercept :: Request -> Maybe (Source (ResourceT IO) S.ByteString -> Connection -> ResourceT IO ())
2727 , settingsManager :: Maybe Manager -- ^ Use an existing timeout manager instead of spawning a new one. If used, 'settingsTimeout' is ignored. Default is 'Nothing'
28− , settingsFdCacheDuration :: Int -- ^ Cache duratoin time of file descriptors in seconds. Default value: 10
28+ , settingsFdCacheDuration :: Int -- ^ Cache duratoin time of file descriptors in seconds. 0 means that the cache mechanism is not used. Default value: 10
2929 , settingsResourceTPerRequest :: Bool
3030 -- ^ If @True@, each request\/response pair will run in a separate
3131 -- @ResourceT@. This provides more intuitive behavior for dynamic code,
warp/Network/Wai/Handler/Warp/Types.hs+1−1
@@ -81,7 +81,7 @@ data Connection = Connection
8181#if SENDFILEFD
8282data Cleaner = Cleaner {
8383 threadHandle :: T.Handle
84− , fdCacher :: F.MutableFdCache
84+ , fdCacher :: Maybe F.MutableFdCache
8585 }
8686#else
8787newtype Cleaner = Cleaner { threadHandle :: T.Handle }