Hello!
I have this problem with a self compiled GHC, checked out with
-rghc-4-07-branch (which should be 4.08, at most with additional
commits *on that branch*), checked out about July 18.
When I compile the program below with the command
ghc -syslib net -fvia-C -o main Main.hs
and then run it with
./main
the output is this:
ok
ok
main: no threads to run: infinite loop or deadlock?
then, the program aborts.
Why is this? This is a test case reproducing the same problem appearing
in a bigger program. And there, I really *want* to use hClose to ensure
that the file descriptor is freed as early as possible, because I want
to open many file descriptors in short succession or in parallel (using
forkIO).
Kind regards, Hannah.
module Main (main) where
import IO
import Socket
-- adapt to a working file on a working http server which can stand
-- the endless loop below
server = "c3po.schlund.de"
port = PortNumber (mkPortNumber 80)
file = "/"
-- end adapt
doTest :: IO ()
doTest = do
sd <- connectTo server port
hPutStr sd ("GET " ++ file ++ " HTTP/1.0\r\n\r\n")
result <- hGetContents sd
slurp result
hClose sd
if "" `elem` lines (filter (/= '\r') result)
then
putStrLn "ok"
else
putStrLn "fail"
slurp :: String -> IO ()
slurp [] = return ()
slurp (x:xs) = x `seq` slurp xs
main :: IO ()
main = doTest >> main