You can clone with
If connectTo is used with a UnixSocket, it completely ignores the hostname argument. Which is good because there's nothing sensible to put in there, but bad because you have to fill it with a useless value (e.g. undefined), and this isn't at all mentioned in the docs.
When Network.accept is used with a socket from Network.listenOn with a UnixSocket argument, the host is filled with garbage and the port is always 65535. This is highly worrying:
module NetworkTest where
path :: String
path = "/tmp/networktest.sock"
server :: IO ()
server = bracket (listenOn (UnixSocket path)) close $ \s ->
bracket (accept s) (\(h,_,_) -> hClose h) $ \(h,them,themport) ->
putStrLn $ "Connection from: " ++ show (them,themport)
client :: IO ()
client = bracket (connectTo undefined (UnixSocket path)) hClose $ \h ->
ghci> forkIO server
Connection from: ("rkov-chain-0.0.3.1ry-0\228\US\DC2\t\SO",65535)
I have no idea what is being printed here but it doesn't look safe.
I'll have a look. The API for connectTo is quite odd indeed. Perhaps we should change it to something more sane in the next major release.