
From: "Sigbjorn Finne"
module Main where
import BSD import SocketPrim import Socket (withSocketsDo)
main = Socket.withSocketsDo (do protNum <- getProtocolNumber "tcp" s <- socket AF_INET Stream protNum hostAddr <- inet_addr "157.189.164.68" let sAddr = (SockAddrInet (toEnum 8080) hostAddr) connect s sAddr i <- sendTo s "GET / HTTP/1.0\r\n\r\n" sAddr (str,l,imsAddr) <- recvFrom s 1000 putStr str )
But something I seem to be doing wrong. During evaluation of 'recvFrom s 1000' I get the following error message (consistently for unix and windows): Fail: SocketPrim.hsc:241: Non-exhaustive patterns in case As the log of the webserver reveals the sendTo works fine. Any idea what could be my problem? Sven Eric

"Sven Eric Panitz"
...
I tried the following little test, which stays away from above functions:
module Main where
import BSD import SocketPrim import Socket (withSocketsDo)
main = Socket.withSocketsDo (do protNum <- getProtocolNumber "tcp" s <- socket AF_INET Stream protNum hostAddr <- inet_addr "157.189.164.68" let sAddr = (SockAddrInet (toEnum 8080) hostAddr) connect s sAddr i <- sendTo s "GET / HTTP/1.0\r\n\r\n" sAddr (str,l,imsAddr) <- recvFrom s 1000 putStr str )
But something I seem to be doing wrong.
During evaluation of 'recvFrom s 1000' I get the following error message (consistently for unix and windows):
Fail: SocketPrim.hsc:241: Non-exhaustive patterns in case
You're doing something slightly non-standard here, using recvfrom() on a connected socket, but I understand why you're doing it (as you don't have any other SocketPrim alternatives for sucking data off of a connected socket). This shows up a bug/problem in the implementation of 'recvFrom', I'm afraid. Conclusion: you're hosed with ghc-5.02.1 and its socket libs under Win32. Sorry. --sigbjorn btw, I've checked in a fix to 'recvFrom' and added wrappers for send() and recv(), but that won't help you short-term.

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
participants (2)
-
Sigbjorn Finne
-
Sven Eric Panitz