@@ -1,4 +1,4 @@
1−
1+{-# LANGUAGE OverloadedStrings #-}
2module Network.Wai.Handler.Warp.WithApplication (
2module Network.Wai.Handler.Warp.WithApplication (
3 withApplication,
3 withApplication,
4 withApplicationSettings,
4 withApplicationSettings,
@@ -12,6 +12,7 @@ import Control.Concurrent
12import Control.Concurrent.Async
12import Control.Concurrent.Async
13import Control.Exception
13import Control.Exception
14import Control.Monad (when)
14import Control.Monad (when)
15+import Data.Streaming.Network (bindRandomPortTCP)
15import Network.Socket
16import Network.Socket
16import Network.Wai
17import Network.Wai
17import Network.Wai.Handler.Warp.Run
18import Network.Wai.Handler.Warp.Run
@@ -96,17 +97,7 @@ mkWaiter = do
97-- @since 3.2.4
98-- @since 3.2.4
98openFreePort :: IO (Port, Socket)
99openFreePort :: IO (Port, Socket)
99−openFreePort = do
100+openFreePort = bindRandomPortTCP "127.0.0.1"
100− let hints = defaultHints {
101− addrFlags = [AI_PASSIVE]
102− , addrSocketType = Stream
104− addr:_ <- getAddrInfo (Just hints) (Just "127.0.0.1") Nothing
105− s <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
106− bind s $ addrAddress addr
108− port <- socketPort s
109− return (fromIntegral port, s)
111-- | Like 'openFreePort' but closes the socket before exiting.
102-- | Like 'openFreePort' but closes the socket before exiting.
112withFreePort :: ((Port, Socket) -> IO a) -> IO a
103withFreePort :: ((Port, Socket) -> IO a) -> IO a