on master help sign in
defining SENDFILEFD to save Unix without sendfile.
commiteea7686463af064c50815f71f024d49c78ae4ed7 authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 28 Sep 2012, 15:35 (14 years ago) parent1b37bf1
3 files changed+23−19
warp/Network/Wai/Handler/Warp/Run.hs+11−9 warp/Network/Wai/Handler/Warp/Types.hs+4−4 warp/warp.cabal+8−6
warp/Network/Wai/Handler/Warp/Run.hs+11−9
@@ -40,7 +40,9 @@ import Network.Socket (Socket(..))
4040#if WINDOWS
4141import qualified Control.Concurrent.MVar as MV
4242import Network.Socket (withSocketsDo)
43−#else
43+#endif
44+
45+#if SENDFILEFD
4446import qualified Network.Wai.Handler.Warp.FdCache as F
4547#endif
4648
@@ -67,13 +69,13 @@ socketConnection s = Connection
6769 }
6870
6971sendFile :: Socket -> FilePath -> Integer -> Integer -> IO () -> [ByteString] -> Cleaner -> IO ()
70−#if WINDOWS
71−sendFile s path off len act hdr _ =
72− sendfileWithHeader s path (PartOfFile off len) act hdr
73−#else
72+#if SENDFILEFD
7473sendFile s path off len act hdr cleaner = do
7574 (fd, fresher) <- F.getFd (fdCacher cleaner) path
7675 sendfileFdWithHeader s fd (PartOfFile off len) (act>>fresher) hdr
76+#else
77+sendFile s path off len act hdr _ =
78+ sendfileWithHeader s path (PartOfFile off len) act hdr
7779#endif
7880
7981#if __GLASGOW_HASKELL__ < 702
@@ -125,7 +127,7 @@ runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application ->
125127runSettingsConnection set getConn app = do
126128 tm <- maybe (T.initialize $ settingsTimeout set * 1000000) return
127129 $ settingsManager set
128−#if !WINDOWS
130+#if SENDFILEFD
129131 fc <- F.initialize (settingsFdCacheDuration set * 1000000)
130132#endif
131133 mask $ \restore -> forever $ do
@@ -133,10 +135,10 @@ runSettingsConnection set getConn app = do
133135 (conn, addr) <- getConnLoop
134136 void . forkIO $ do
135137 th <- T.registerKillThread tm
136−#if WINDOWS
137− let cleaner = Cleaner th
138−#else
138+#if SENDFILEFD
139139 let cleaner = Cleaner th fc
140+#else
141+ let cleaner = Cleaner th
140142#endif
141143 let serve = do
142144 onOpen
warp/Network/Wai/Handler/Warp/Types.hs+4−4
@@ -11,7 +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 !WINDOWS
14+#if SENDFILEFD
1515import qualified Network.Wai.Handler.Warp.FdCache as F
1616#endif
1717
@@ -78,11 +78,11 @@ data Connection = Connection
7878
7979----------------------------------------------------------------
8080
81−#if WINDOWS
82−newtype Cleaner = Cleaner { threadHandle :: T.Handle }
83−#else
81+#if SENDFILEFD
8482data Cleaner = Cleaner {
8583 threadHandle :: T.Handle
8684 , fdCacher :: F.MutableFdCache
8785 }
86+#else
87+newtype Cleaner = Cleaner { threadHandle :: T.Handle }
8888#endif
warp/warp.cabal+8−6
@@ -48,13 +48,14 @@ Library
4848 Network.Wai.Handler.Warp.Types
4949 Paths_warp
5050 Ghc-Options: -Wall
51− if os(windows)
52− Cpp-options: -DWINDOWS
53− else
51+ if os(linux) || os(freebsd) || os(darwin)
52+ Cpp-Options: -DSENDFILEFD
5453 Build-Depends: unix
5554 , hashable
5655 Other-modules: Network.Wai.Handler.Warp.FdCache
5756 Network.Wai.Handler.Warp.MultiMap
57+ if os(windows)
58+ Cpp-Options: -DWINDOWS
5859
5960Test-Suite spec
6061 Main-Is: Spec.hs
@@ -81,11 +82,12 @@ Test-Suite spec
8182 , HUnit
8283 , QuickCheck
8384 , hspec == 1.3.*
84− if os(windows)
85− Cpp-options: -DWINDOWS
86− else
85+ if os(linux) || os(freebsd) || os(darwin)
86+ Cpp-Options: -DSENDFILEFD
8787 Build-Depends: unix
8888 , hashable
89+ if os(windows)
90+ Cpp-Options: -DWINDOWS
8991
9092Source-Repository head
9193 Type: git