> 
> Conclusion: you're hosed with ghc-5.02.1 and its socket libs under
> Win32. Sorry.
> 

If you don't mind getting your hands a (little) bit dirty, here's a story
that will work ghc-5.02.1:

* edit SocketPrim.hi (and SocketPrim.p_hi), to instead of saying 
   "Socket" in its __export section it says "Socket{MkSocket}"

   (you'll find the .hi file in imports/net/ inside your 5.02.1 tree).

* compile up the attached NetExtra.hs as follows:
  
     foo$ ghc -c NetExtra.hs -fvia-C -fglasgow-exts -package net

* import and include NetExtra with your socket code, e.g.,

    main = Socket.withSocketsDo $ do
       protNum <- getProtocolNumber "tcp"
       s <- socket AF_INET Stream protNum
       hostAddr <- inet_addr "127.0.0.1"
       let sAddr =  (SockAddrInet 80 hostAddr)
       connect s sAddr
       send s "GET / HTTP/1.0\r\n\r\n"
       str <- recvAll s
       putStr str

    recvAll :: Socket -> IO String
    recvAll sock = do
         str <- catch (recv s 100) (\ _ -> return "")
         case str of
          "" -> return str
          _  -> do
             ls <- recvAll sock
             return (str ++ ls)


hth
--sigbjorn

Attachment: NetExtra.hs
Description: Binary data

Reply via email to