on master help sign in
warp with bound threads #308
6edfbccDavid Barbour
warp/Network/Wai/Handler/Warp/Run.hs+2−2
@@ -7,7 +7,7 @@
7module Network.Wai.Handler.Warp.Run where
7module Network.Wai.Handler.Warp.Run where
8
8
9import Control.Arrow (first)
9import Control.Arrow (first)
10−import Control.Concurrent (threadDelay, forkIOWithUnmask)
10+import Control.Concurrent (threadDelay)
11import qualified Control.Concurrent as Conc (yield)
11import qualified Control.Concurrent as Conc (yield)
12import Control.Exception as E
12import Control.Exception as E
13import Control.Monad (when, unless, void)
13import Control.Monad (when, unless, void)
@@ -225,7 +225,7 @@ fork :: Settings
225 -> T.Manager
225 -> T.Manager
226 -> Counter
226 -> Counter
227 -> IO ()
227 -> 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 ->
229 -- Run the connection maker to get a new connection, and ensure
229 -- Run the connection maker to get a new connection, and ensure
230 -- that the connection is closed. If the mkConn call throws an
230 -- that the connection is closed. If the mkConn call throws an
231 -- exception, we will leak the connection. If the mkConn call is
231 -- exception, we will leak the connection. If the mkConn call is
warp/Network/Wai/Handler/Warp/Settings.hs+15−2
@@ -1,10 +1,11 @@
1{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, ViewPatterns #-}
1{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, ViewPatterns #-}
2−{-# LANGUAGE PatternGuards #-}
2+{-# LANGUAGE PatternGuards, RankNTypes #-}
3
3
4module Network.Wai.Handler.Warp.Settings where
4module Network.Wai.Handler.Warp.Settings where
5
5
6import Control.Exception
6import Control.Exception
7−import Control.Monad (when)
7+import Control.Monad (when, void)
8+import Control.Concurrent (forkIOWithUnmask)
8import qualified Data.Text as T
9import qualified Data.Text as T
9import qualified Data.Text.IO as TIO
10import qualified Data.Text.IO as TIO
10import Data.Streaming.Network (HostPreference)
11import Data.Streaming.Network (HostPreference)
@@ -52,6 +53,17 @@ data Settings = Settings
52 -- Default: do nothing.
53 -- Default: do nothing.
53 --
54 --
54 -- Since 1.3.6
55 -- 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+
55 , settingsNoParsePath :: Bool
67 , settingsNoParsePath :: Bool
56 -- ^ Perform no parsing on the rawPathInfo.
68 -- ^ Perform no parsing on the rawPathInfo.
57 --
69 --
@@ -85,6 +97,7 @@ defaultSettings = Settings
85 , settingsManager = Nothing
97 , settingsManager = Nothing
86 , settingsFdCacheDuration = 10
98 , settingsFdCacheDuration = 10
87 , settingsBeforeMainLoop = return ()
99 , settingsBeforeMainLoop = return ()
100+ , settingsFork = void . forkIOWithUnmask
88 , settingsNoParsePath = False
101 , settingsNoParsePath = False
89 , settingsInstallShutdownHandler = const $ return ()
102 , settingsInstallShutdownHandler = const $ return ()
90 , settingsServerName = S8.pack $ "Warp/" ++ showVersion Paths_warp.version
103 , settingsServerName = S8.pack $ "Warp/" ++ showVersion Paths_warp.version
warp/warp.cabal+1−1
@@ -1,5 +1,5 @@
1Name: warp
1Name: warp
2−Version: 3.0.3
2+Version: 3.0.4
3Synopsis: A fast, light-weight web server for WAI applications.
3Synopsis: A fast, light-weight web server for WAI applications.
4License: MIT
4License: MIT
5License-file: LICENSE
5License-file: LICENSE