refactor: Simplify App.initServerSocket
This change gets rid of unnecessary explicit bindRandomPortTCP in initServerSocket. Returned port value was ignored in removed code anyway as assigned port retrieval from an open socket is handled elsewhere.
This commit is contained in:
+6
-25
@@ -63,8 +63,7 @@ import PostgREST.Version (docsVersion, prettyVersion)
|
|||||||
|
|
||||||
import qualified Data.ByteString.Char8 as BS
|
import qualified Data.ByteString.Char8 as BS
|
||||||
import qualified Data.List as L
|
import qualified Data.List as L
|
||||||
import Data.Streaming.Network (bindPortTCP,
|
import Data.Streaming.Network (bindPortTCP)
|
||||||
bindRandomPortTCP)
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Network.HTTP.Types as HTTP
|
import qualified Network.HTTP.Types as HTTP
|
||||||
import qualified Network.HTTP.Types.Header as HTTP (hVary)
|
import qualified Network.HTTP.Types.Header as HTTP (hVary)
|
||||||
@@ -262,33 +261,15 @@ type AppSockets = (NS.Socket, Maybe NS.Socket)
|
|||||||
|
|
||||||
initSockets :: AppConfig -> IO AppSockets
|
initSockets :: AppConfig -> IO AppSockets
|
||||||
initSockets AppConfig{..} = do
|
initSockets AppConfig{..} = do
|
||||||
let
|
sock <- case configServerUnixSocket of
|
||||||
cfg'usp = configServerUnixSocket
|
|
||||||
cfg'uspm = configServerUnixSocketMode
|
|
||||||
cfg'host = configServerHost
|
|
||||||
cfg'port = configServerPort
|
|
||||||
cfg'adminHost = configAdminServerHost
|
|
||||||
cfg'adminPort = configAdminServerPort
|
|
||||||
|
|
||||||
sock <- case cfg'usp of
|
|
||||||
-- I'm not using `streaming-commons`' bindPath function here because it's not defined for Windows,
|
-- I'm not using `streaming-commons`' bindPath function here because it's not defined for Windows,
|
||||||
-- but we need to have runtime error if we try to use it in Windows, not compile time error
|
-- but we need to have runtime error if we try to use it in Windows, not compile time error
|
||||||
Just path -> createAndBindDomainSocket path cfg'uspm
|
Just path -> createAndBindDomainSocket path configServerUnixSocketMode
|
||||||
Nothing -> do
|
Nothing -> bindPortTCP configServerPort (fromString $ T.unpack configServerHost)
|
||||||
(_, sock) <-
|
|
||||||
if cfg'port /= 0
|
|
||||||
then do
|
|
||||||
sock <- bindPortTCP cfg'port (fromString $ T.unpack cfg'host)
|
|
||||||
pure (cfg'port, sock)
|
|
||||||
else do
|
|
||||||
-- explicitly bind to a random port, returning bound port number
|
|
||||||
(num, sock) <- bindRandomPortTCP (fromString $ T.unpack cfg'host)
|
|
||||||
pure (num, sock)
|
|
||||||
pure sock
|
|
||||||
|
|
||||||
adminSock <- case cfg'adminPort of
|
adminSock <- case configAdminServerPort of
|
||||||
Just adminPort -> do
|
Just adminPort -> do
|
||||||
adminSock <- bindPortTCP adminPort (fromString $ T.unpack cfg'adminHost)
|
adminSock <- bindPortTCP adminPort (fromString $ T.unpack configAdminServerHost)
|
||||||
pure $ Just adminSock
|
pure $ Just adminSock
|
||||||
Nothing -> pure Nothing
|
Nothing -> pure Nothing
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user