on master help sign in
making Run.hs more readable.
commit443a93c4631b4c520382f553c347eddf9191d1f5 authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 11 Oct 2013, 15:18 (13 years ago) parent04e9438
4 files changed+22−31
warp/Network/Wai/Handler/Warp/FdCache.hs+17−3 warp/Network/Wai/Handler/Warp/Run.hs+2−15 warp/Network/Wai/Handler/Warp/Types.hs−10 warp/warp.cabal+3−3
warp/Network/Wai/Handler/Warp/FdCache.hs+17−3
@@ -1,5 +1,17 @@
1−{-# LANGUAGE BangPatterns, FlexibleInstances #-}
1+{-# LANGUAGE BangPatterns, FlexibleInstances, CPP #-}
22
3+#ifndef SENDFILEFD
4+module Network.Wai.Handler.Warp.FdCache (
5+ initialize
6+ , MutableFdCache
7+ ) where
8+
9+data MutableFdCache = MutableFdCache
10+
11+initialize :: Int -> IO (Maybe MutableFdCache)
12+initialize _ = return Nothing
13+
14+#else
315module Network.Wai.Handler.Warp.FdCache (
416 initialize
517 , getFd
@@ -76,7 +88,8 @@ look mfc path key = searchWith key check <$> fdCache mfc
7688
7789----------------------------------------------------------------
7890
79−initialize :: Int -> IO MutableFdCache
91+initialize :: Int -> IO (Maybe MutableFdCache)
92+initialize 0 = return Nothing
8093initialize duration = do
8194 mfc <- newMutableFdCache
8295 tid <- forkIO $ loop mfc
@@ -84,7 +97,7 @@ initialize duration = do
8497 -- When Warp is finished in GHCi, this IORef is GCed.
8598 -- At that time, we should close all opened file descriptors.
8699 _ <- mkWeakIORef (unMutableFdCache mfc) $ terminate mfc tid
87− return mfc
100+ return (Just mfc)
88101 where
89102 loop mfc = do
90103 mask_ $ do
@@ -130,3 +143,4 @@ getFd mfc path = look mfc path key >>= getFd'
130143 getFd' (Just (FdEntry _ fd mst)) = do
131144 refresh mst
132145 return (fd, refresh mst)
146+#endif
warp/Network/Wai/Handler/Warp/Run.hs+2−15
@@ -21,6 +21,7 @@ import Network.Sendfile
2121import Network.Socket (accept, SockAddr)
2222import qualified Network.Socket.ByteString as Sock
2323import Network.Wai
24+import qualified Network.Wai.Handler.Warp.FdCache as F
2425import Network.Wai.Handler.Warp.Recv
2526import Network.Wai.Handler.Warp.Request
2627import Network.Wai.Handler.Warp.Response
@@ -37,11 +38,6 @@ import System.Posix.IO (FdOption(CloseOnExec), setFdOption)
3738import Network.Socket (fdSocket)
3839#endif
3940
40−#if SENDFILEFD
41−import Control.Applicative
42−import qualified Network.Wai.Handler.Warp.FdCache as F
43−#endif
44−
4541-- FIXME come up with good values here
4642bytesPerRead :: Int
4743bytesPerRead = 4096
@@ -136,12 +132,7 @@ runSettingsConnection set getConn app = runSettingsConnectionMaker set getConnMa
136132-- which will return 'Connection'.
137133runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO ()
138134runSettingsConnectionMaker set getConnMaker app = do
139−#if SENDFILEFD
140− let duration = settingsFdCacheDuration set
141− fc <- case duration of
142− 0 -> return Nothing
143− _ -> Just <$> F.initialize (duration * 1000000)
144−#endif
135+ fc <- F.initialize (settingsFdCacheDuration set * 1000000)
145136 settingsBeforeMainLoop set
146137
147138 -- Note that there is a thorough discussion of the exception safety of the
@@ -192,11 +183,7 @@ runSettingsConnectionMaker set getConnMaker app = do
192183 -- We need to register a timeout handler for this thread, and
193184 -- cancel that handler as soon as we exit.
194185 bracket (T.registerKillThread tm) T.cancel $ \th ->
195−#if SENDFILEFD
196186 let cleaner = Cleaner th fc
197−#else
198− let cleaner = Cleaner th
199−#endif
200187 -- We now have fully registered a connection close handler
201188 -- in the case of all exceptions, so it is safe to one
202189 -- again allow async exceptions.
warp/Network/Wai/Handler/Warp/Types.hs−10
@@ -11,9 +11,7 @@ import Data.Version (showVersion)
1111import Network.HTTP.Types.Header
1212import qualified Paths_warp
1313import qualified Network.Wai.Handler.Warp.Timeout as T
14−#if SENDFILEFD
1514import qualified Network.Wai.Handler.Warp.FdCache as F
16−#endif
1715
1816----------------------------------------------------------------
1917
@@ -68,8 +66,6 @@ data Connection = Connection
6866--
6967-- Since 1.3.4
7068dummyCleaner :: Cleaner
71−
72−#if SENDFILEFD
7369dummyCleaner = Cleaner T.dummyHandle Nothing
7470
7571-- | A type used to clean up file descriptor caches.
@@ -77,9 +73,3 @@ data Cleaner = Cleaner {
7773 threadHandle :: T.Handle
7874 , fdCacher :: Maybe F.MutableFdCache
7975 }
80−
81−#else
82−dummyCleaner = Cleaner T.dummyHandle
83−
84−newtype Cleaner = Cleaner { threadHandle :: T.Handle }
85−#endif
warp/warp.cabal+3−3
@@ -54,21 +54,21 @@ Library
5454 Exposed-modules: Network.Wai.Handler.Warp
5555 Network.Wai.Handler.Warp.Timeout
5656 Other-modules: Network.Wai.Handler.Warp.Conduit
57+ Network.Wai.Handler.Warp.FdCache
5758 Network.Wai.Handler.Warp.ReadInt
59+ Network.Wai.Handler.Warp.Recv
5860 Network.Wai.Handler.Warp.Request
5961 Network.Wai.Handler.Warp.Response
6062 Network.Wai.Handler.Warp.ResponseHeader
6163 Network.Wai.Handler.Warp.Run
6264 Network.Wai.Handler.Warp.Settings
6365 Network.Wai.Handler.Warp.Types
64− Network.Wai.Handler.Warp.Recv
6566 Paths_warp
6667 Ghc-Options: -Wall
6768 if (os(linux) || os(freebsd) || os(darwin)) && flag(allow-sendfilefd)
6869 Cpp-Options: -DSENDFILEFD
6970 Build-Depends: hashable
70− Other-modules: Network.Wai.Handler.Warp.FdCache
71− Network.Wai.Handler.Warp.MultiMap
71+ Other-modules: Network.Wai.Handler.Warp.MultiMap
7272 if os(windows)
7373 Cpp-Options: -DWINDOWS
7474 else