first experiments with socket

This commit is contained in:
nek0 2023-12-09 08:55:56 +01:00
parent 554f483cd9
commit 73705f713c

View file

@ -12,6 +12,8 @@ import Data.Time
import Data.Yaml import Data.Yaml
import Network.Socket
import Options.Applicative import Options.Applicative
-- internal imports -- internal imports
@ -34,6 +36,20 @@ main = do
fromString (prettyPrintParseException msg) fromString (prettyPrintParseException msg)
) )
Right (Settings {..}) -> do Right (Settings {..}) -> do
let sockAddr = SockAddrUnix setSocketPath
unless (isSupportedSockAddr sockAddr)
(error $ "invalid socket path " <> setSocketPath)
let hints = defaultHints
{ addrFamily = AF_UNIX
, addrSocketType = Stream
, addrAddress = sockAddr
}
addr <- head <$> getAddrInfo (Just hints) Nothing Nothing
sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
bind sock (addrAddress addr)
putStrLn "Bound to socket:"
print =<< getSocketName sock
putStrLn "-----------------------------------------------------------------------------------"
arena <- generateArena setMapRows setMapColumns setSpawnerProbability arena <- generateArena setMapRows setMapColumns setSpawnerProbability
putStrLn "generated arena:" putStrLn "generated arena:"
print (arenaMap arena) print (arenaMap arena)