on master help sign in
warp with bound threads #308
commit6edfbccd3976e38884c7458eb1b18a617a4da0b7 authorDavid Barbour <dmbarbour@gmail.com> dateMon 1 Dec 2014, 13:56 (12 years ago) parent0be7202
3 files changed+18−5
warp/Network/Wai/Handler/Warp/Run.hs+2−2 warp/Network/Wai/Handler/Warp/Settings.hs+15−2 warp/warp.cabal+1−1
warp/Network/Wai/Handler/Warp/Run.hs+2−2
@@ -7,7 +7,7 @@
77module Network.Wai.Handler.Warp.Run where
88
99import Control.Arrow (first)
10−import Control.Concurrent (threadDelay, forkIOWithUnmask)
10+import Control.Concurrent (threadDelay)
1111import qualified Control.Concurrent as Conc (yield)
1212import Control.Exception as E
1313import Control.Monad (when, unless, void)
@@ -225,7 +225,7 @@ fork :: Settings
225225 -> T.Manager
226226 -> Counter
227227 -> IO ()
228−fork set mkConn addr app dc fc tm counter = void $ forkIOWithUnmask $ \unmask ->
228+fork set mkConn addr app dc fc tm counter = settingsFork set $ \ unmask ->
229229 -- Run the connection maker to get a new connection, and ensure
230230 -- that the connection is closed. If the mkConn call throws an
231231 -- exception, we will leak the connection. If the mkConn call is
warp/Network/Wai/Handler/Warp/Settings.hs+15−2
@@ -1,10 +1,11 @@
11{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, ViewPatterns #-}
2−{-# LANGUAGE PatternGuards #-}
2+{-# LANGUAGE PatternGuards, RankNTypes #-}
33
44module Network.Wai.Handler.Warp.Settings where
55
66import Control.Exception
7−import Control.Monad (when)
7+import Control.Monad (when, void)
8+import Control.Concurrent (forkIOWithUnmask)
89import qualified Data.Text as T
910import qualified Data.Text.IO as TIO
1011import Data.Streaming.Network (HostPreference)
@@ -52,6 +53,17 @@ data Settings = Settings
5253 -- Default: do nothing.
5354 --
5455 -- Since 1.3.6
56+
57+ , settingsFork :: ((forall a. IO a -> IO a) -> IO ()) -> IO ()
58+ -- ^ Code to fork a new thread to accept a connection.
59+ --
60+ -- This may be useful if you need OS bound threads, or if
61+ -- you wish to develop an alternative threading model.
62+ --
63+ -- Default: void . forkIOWithUnmask
64+ --
65+ -- Since 3.0.4
66+
5567 , settingsNoParsePath :: Bool
5668 -- ^ Perform no parsing on the rawPathInfo.
5769 --
@@ -85,6 +97,7 @@ defaultSettings = Settings
8597 , settingsManager = Nothing
8698 , settingsFdCacheDuration = 10
8799 , settingsBeforeMainLoop = return ()
100+ , settingsFork = void . forkIOWithUnmask
88101 , settingsNoParsePath = False
89102 , settingsInstallShutdownHandler = const $ return ()
90103 , settingsServerName = S8.pack $ "Warp/" ++ showVersion Paths_warp.version
warp/warp.cabal+1−1
@@ -1,5 +1,5 @@
11Name: warp
2−Version: 3.0.3
2+Version: 3.0.4
33Synopsis: A fast, light-weight web server for WAI applications.
44License: MIT
55License-file: LICENSE