on master help sign in
Reuse bindRandomPortTCP #671

Turns out that the real issue was having too small a backlog. But may as well reuse the existing random port functionality in streaming-commons.

commitc548f55873e8e36486473dc0d164ed4f9ba304e9 authorMichael Snoyman <michael@snoyman.com> dateWed 7 Feb 2018, 17:15 (9 years ago) parente8aa56e
2 files changed+5−13
warp/ChangeLog.md+2−1 warp/Network/Wai/Handler/Warp/WithApplication.hs+3−12
warp/ChangeLog.md+2−1
@@ -1,7 +1,8 @@
11## 3.2.16
22
33* In `testWithApplication`, don't `throwTo` ignorable exceptions
4− [#671](https://github.com/yesodweb/wai/issues/671)
4+ [#671](https://github.com/yesodweb/wai/issues/671), and
5+ reuse `bindRandomPortTCP`
56
67## 3.2.15
78
warp/Network/Wai/Handler/Warp/WithApplication.hs+3−12
@@ -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