@@ -1,4 +1,4 @@
1−
1+{-# LANGUAGE OverloadedStrings #-}
22module Network.Wai.Handler.Warp.WithApplication (
33 withApplication,
44 withApplicationSettings,
@@ -12,6 +12,7 @@ import Control.Concurrent
1212import Control.Concurrent.Async
1313import Control.Exception
1414import Control.Monad (when)
15+import Data.Streaming.Network (bindRandomPortTCP)
1516import Network.Socket
1617import Network.Wai
1718import Network.Wai.Handler.Warp.Run
@@ -96,17 +97,7 @@ mkWaiter = do
9697--
9798-- @since 3.2.4
9899openFreePort :: IO (Port, Socket)
99−openFreePort = do
100− let hints = defaultHints {
101− addrFlags = [AI_PASSIVE]
102− , addrSocketType = Stream
103− }
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
107− listen s 1
108− port <- socketPort s
109− return (fromIntegral port, s)
100+openFreePort = bindRandomPortTCP "127.0.0.1"
110101
111102-- | Like 'openFreePort' but closes the socket before exiting.
112103withFreePort :: ((Port, Socket) -> IO a) -> IO a