first experiments with socket
This commit is contained in:
parent
554f483cd9
commit
73705f713c
1 changed files with 16 additions and 0 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue