@@ -26,7 +26,6 @@ module Network.Wai.Handler.Warp
26 ( -- * Run a Warp server
26 ( -- * Run a Warp server
30 , serveConnections
29 , serveConnections
31 -- * Datatypes
30 -- * Datatypes
@@ -57,7 +56,7 @@ import Network.Socket
58import qualified Network.Socket.ByteString as Sock
57import qualified Network.Socket.ByteString as Sock
59import Control.Exception (bracket, finally, Exception, SomeException, catch)
58import Control.Exception (bracket, finally, Exception, SomeException, catch)
60−import Control.Concurrent (forkIO, threadDelay)
59+import Control.Concurrent (forkIO)
61import Data.Maybe (fromMaybe)
60import Data.Maybe (fromMaybe)
63import Data.Typeable (Typeable)
62import Data.Typeable (Typeable)
@@ -80,8 +79,12 @@ import Control.Monad.IO.Class (liftIO)
80import System.Timeout (timeout)
79import System.Timeout (timeout)
81import Data.Word (Word8)
80import Data.Word (Word8)
82import Data.List (foldl')
81import Data.List (foldl')
84+import Control.Concurrent (threadDelay)
83import qualified Control.Concurrent.MVar as MV
85import qualified Control.Concurrent.MVar as MV
84import Control.Monad (forever)
86import Control.Monad (forever)
86-- | Run an 'Application' on the given port, ignoring all exceptions.
89-- | Run an 'Application' on the given port, ignoring all exceptions.
87run :: Port -> Application -> IO ()
90run :: Port -> Application -> IO ()
@@ -90,18 +93,8 @@ run = runEx (const $ return ())
90-- | Run an 'Application' on the given port, with the given exception handler.
93-- | Run an 'Application' on the given port, with the given exception handler.
91-- Please note that you will also receive 'InvalidRequest' exceptions.
94-- Please note that you will also receive 'InvalidRequest' exceptions.
92runEx :: (SomeException -> IO ()) -> Port -> Application -> IO ()
95runEx :: (SomeException -> IO ()) -> Port -> Application -> IO ()
93−runEx onE port = withSocketsDo . -- FIXME should this be called by client user instead?
96+#if WINDOWS
95− (listenOn $ PortNumber $ fromIntegral port)
97− serveConnections onE port
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
97+runEx onE port app = withSocketsDo $ do
105 var <- MV.newMVar Nothing
98 var <- MV.newMVar Nothing
106 let clean = MV.modifyMVar_ var $ \s -> maybe (return ()) sClose s >> return Nothing
99 let clean = MV.modifyMVar_ var $ \s -> maybe (return ()) sClose s >> return Nothing
107 _ <- forkIO $ bracket
100 _ <- forkIO $ bracket
@@ -109,8 +102,15 @@ runInteractive port app = withSocketsDo $ do
109 (const clean)
102 (const clean)
110 (\s -> do
103 (\s -> do
111 MV.modifyMVar_ var (\_ -> return $ Just s)
104 MV.modifyMVar_ var (\_ -> return $ Just s)
112− serveConnections (const $ return ()) port app s)
105+ serveConnections onE port app s)
113 forever (threadDelay maxBound) `finally` clean
106 forever (threadDelay maxBound) `finally` clean
108+runEx onE port = withSocketsDo . -- FIXME should this be called by client user instead?
110+ (listenOn $ PortNumber $ fromIntegral port)
112+ serveConnections onE port
115type Port = Int
115type Port = Int