Skip to content
This repository

UnixSocket handled strangely by connectTo and accept #10

bmillwood opened this Issue May 14, 2011 · 1 comment

2 participants

Ben Millwood Johan Tibell
Ben Millwood

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

import Control.Exception

import Network
import System.IO

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 ->
  return ()
ghci> forkIO server
ThreadId 173
ghci> client
Connection from: ("rkov-chain-\228\US\DC2\t\SO",65535)

I have no idea what is being printed here but it doesn't look safe.

Johan Tibell
tibbe commented May 15, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.