on master help sign in
runInteractive is now runEx, for Windows only
commit8e4a1cbbe7bf4f32c8184ef034e63f1169c55ac8 authorMichael Snoyman <michael@snoyman.com> dateThu 27 Jan 2011, 17:13 (16 years ago) parent43c5821
2 files changed+17−15
Network/Wai/Handler/Warp.hs+15−15 warp.cabal+2
Network/Wai/Handler/Warp.hs+15−15
@@ -26,7 +26,6 @@ module Network.Wai.Handler.Warp
2626 ( -- * Run a Warp server
2727 run
2828 , runEx
29− , runInteractive
3029 , serveConnections
3130 -- * Datatypes
3231 , Port
@@ -57,7 +56,7 @@ import Network.Socket
5756 )
5857import qualified Network.Socket.ByteString as Sock
5958import Control.Exception (bracket, finally, Exception, SomeException, catch)
60−import Control.Concurrent (forkIO, threadDelay)
59+import Control.Concurrent (forkIO)
6160import Data.Maybe (fromMaybe)
6261
6362import Data.Typeable (Typeable)
@@ -80,8 +79,12 @@ import Control.Monad.IO.Class (liftIO)
8079import System.Timeout (timeout)
8180import Data.Word (Word8)
8281import Data.List (foldl')
82+
83+#if WINDOWS
84+import Control.Concurrent (threadDelay)
8385import qualified Control.Concurrent.MVar as MV
8486import Control.Monad (forever)
87+#endif
8588
8689-- | Run an 'Application' on the given port, ignoring all exceptions.
8790run :: Port -> Application -> IO ()
@@ -90,18 +93,8 @@ run = runEx (const $ return ())
9093-- | Run an 'Application' on the given port, with the given exception handler.
9194-- Please note that you will also receive 'InvalidRequest' exceptions.
9295runEx :: (SomeException -> IO ()) -> Port -> Application -> IO ()
93−runEx onE port = withSocketsDo . -- FIXME should this be called by client user instead?
94− bracket
95− (listenOn $ PortNumber $ fromIntegral port)
96− sClose .
97− serveConnections onE port
98−
99−-- | When using the standard 'run' function on Windows in GHCi, ctrl-C becomes
100−-- unresponsive. This function should be a drop-in replacement allowing normal
101−-- operations. This does have a minor performance hit, and therefore this
102−-- function is recommended only for development, not production.
103−runInteractive :: Port -> Application -> IO ()
104−runInteractive port app = withSocketsDo $ do
96+#if WINDOWS
97+runEx onE port app = withSocketsDo $ do
10598 var <- MV.newMVar Nothing
10699 let clean = MV.modifyMVar_ var $ \s -> maybe (return ()) sClose s >> return Nothing
107100 _ <- forkIO $ bracket
@@ -109,8 +102,15 @@ runInteractive port app = withSocketsDo $ do
109102 (const clean)
110103 (\s -> do
111104 MV.modifyMVar_ var (\_ -> return $ Just s)
112− serveConnections (const $ return ()) port app s)
105+ serveConnections onE port app s)
113106 forever (threadDelay maxBound) `finally` clean
107+#else
108+runEx onE port = withSocketsDo . -- FIXME should this be called by client user instead?
109+ bracket
110+ (listenOn $ PortNumber $ fromIntegral port)
111+ sClose .
112+ serveConnections onE port
113+#endif
114114
115115type Port = Int
116116
warp.cabal+2
@@ -35,6 +35,8 @@ Library
3535 ghc-options: -Wall
3636 if !flag(timeout-protection)
3737 Cpp-options: -DNO_TIMEOUT_PROTECTION
38+ if os(windows)
39+ Cpp-options: -DWINDOWS
3840
3941source-repository head
4042 type: git