Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hostname option #98

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions argo/src/Argo/DefaultMain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ newtype Port = Port String deriving (Eq, Ord)
data TransportOpt
= StdIONetstring
-- ^ NetStrings over standard IO
| SocketNetstring (Maybe Session) (Maybe Publicity) (Maybe Port)
| SocketNetstring (Maybe Session) (Maybe Publicity) (Maybe Port) (Maybe HostName)
-- ^ NetStrings over some socket

data Publicity
Expand All @@ -53,7 +53,7 @@ options desc =
transport :: Opt.Parser TransportOpt
transport =
(\p pub s -> SocketNetstring s pub p)
<$> port <*> publicity <*> session
<$> port <*> publicity <*> session <*> hostname
<|> stdio
where
port = (Just . Port <$>
Expand All @@ -77,6 +77,13 @@ transport =
Opt.help "Create or look up a globally available session")
<|> pure Nothing

hostname =
(fmap Just . Opt.strOption $
Opt.long "host"
<> Opt.metavar "HOST"
<> Opt.help "Make server available at the specified hostname")
<|> pure Nothing

selectHost :: Maybe Publicity -> HostName
selectHost (Just Public) = "::"
selectHost Nothing = "::1"
Expand Down Expand Up @@ -166,18 +173,18 @@ realMain theApp opts =
case transportOpt opts of
StdIONetstring ->
serveStdIONS theApp
SocketNetstring sessionOpt publicityOpt portOpt ->
SocketNetstring sessionOpt publicityOpt portOpt hostNameOpt ->
do sessionResult <- getOrLockSession sessionOpt publicityOpt portOpt
let hostname = fromMaybe (selectHost publicityOpt) hostNameOpt
hSetBuffering stdout NoBuffering
case sessionResult of
UseExisting (Port port) ->
putStrLn ("PORT " ++ port)
MakeNew (Port port) ->
do putStrLn ("PORT " ++ port)
serveSocket (selectHost publicityOpt) port theApp
serveSocket hostname port theApp
MakeNewDyn registerPort ->
do let h = selectHost publicityOpt
(a, port) <- serveSocketDynamic h theApp
do (a, port) <- serveSocketDynamic hostname theApp
registerPort (Port (show port))
putStrLn ("PORT " ++ show port)
wait a
Expand Down