@@ -5,6 +5,7 @@ module Network.Wai.Handler.Warp.Run where
6import Control.Concurrent (threadDelay, forkIOWithUnmask)
6import Control.Concurrent (threadDelay, forkIOWithUnmask)
7import Control.Exception
7import Control.Exception
8+import qualified Control.Exception.Lifted as Lifted
8import Control.Monad (forever, when, unless, void)
9import Control.Monad (forever, when, unless, void)
9import Control.Monad.IO.Class (MonadIO, liftIO)
10import Control.Monad.IO.Class (MonadIO, liftIO)
10import qualified Control.Monad.Trans.Resource as Res
11import qualified Control.Monad.Trans.Resource as Res
@@ -200,7 +201,7 @@ runSettingsConnectionMaker set getConn app = do
200 in unmask .
201 in unmask .
201 -- Call the user-supplied on exception code if any
202 -- Call the user-supplied on exception code if any
202 -- exceptions are thrown.
203 -- exceptions are thrown.
203− handle onE .
204+ handle (onE Nothing) .
205 -- Call the user-supplied code for connection open and close events
206 -- Call the user-supplied code for connection open and close events
206 bracket_ onOpen onClose $
207 bracket_ onOpen onClose $
@@ -210,7 +211,7 @@ runSettingsConnectionMaker set getConn app = do
211 -- FIXME: only IOEception is caught. What about other exceptions?
212 -- FIXME: only IOEception is caught. What about other exceptions?
212 getConnLoop = getConn `catch` \(e :: IOException) -> do
213 getConnLoop = getConn `catch` \(e :: IOException) -> do
213− onE (toException e)
214+ onE Nothing (toException e)
214 -- "resource exhausted (Too many open files)" may happen by accept().
215 -- "resource exhausted (Too many open files)" may happen by accept().
215 -- Wait a second hoping that resource will be available.
216 -- Wait a second hoping that resource will be available.
216 threadDelay 1000000
217 threadDelay 1000000
@@ -241,9 +242,11 @@ serveConnection timeoutHandle settings cleaner app conn remoteHost' =
241 | otherwise = f env
242 | otherwise = f env
242 th = threadHandle cleaner
243 th = threadHandle cleaner
245+ onE env = liftIO . settingsOnException settings env
244 serveConnection'' fromClient internalState = do
247 serveConnection'' fromClient internalState = do
245 (env, getSource) <- parseRequest conn timeoutHandle internalState remoteHost' fromClient
248 (env, getSource) <- parseRequest conn timeoutHandle internalState remoteHost' fromClient
246− case settingsIntercept settings env of
249+ Lifted.handle (onE (Just env)) $ case settingsIntercept settings env of
247 Nothing -> do
250 Nothing -> do
248 -- Let the application run for as long as it wants
251 -- Let the application run for as long as it wants
249 liftIO $ T.pause th
252 liftIO $ T.pause th