Re: Socket library ghc 5.02.1
From: "Sigbjorn Finne" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Date: Tue, 27 Nov 2001 09:30:04 -0800 > > 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., Thanks Danke Mercie, this works (although I did not fully understand, what I was doing). Sven Eric ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Socket library ghc 5.02.1
> > 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 NetExtra.hs Description: Binary data
Re: Socket library ghc 5.02.1
"Sven Eric Panitz" <[EMAIL PROTECTED]> writes: > ... > > 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. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Socket library ghc 5.02.1
From: "Sigbjorn Finne" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> References: <[EMAIL PROTECTED]> Date: Mon, 26 Nov 2001 12:30:47 -0800 "Sven Eric Panitz" <[EMAIL PROTECTED]> writes: > > It seems that the Socket library does still not work > with ghc 5.02.1. > I tried the simple test: > > > main = > > do > > d <- connectTo "localhost" (PortNumber 80) > > hPutStr d "GET / HTTP/1.0\n\n" > > hFlush d > > c <- hGetContents d > > putStr c > > On Windows2000 I get the known error: > > *** Exception: does not exist > Action: getProtocolByName > Reason: no such protocol entry > (You, of course, need to wrap up that code with Socket.withSocketDo to start up WinSock first). FYI, in case you're planning on doing socket programming with GHC-5.02 on a Win32 platform, stay away from using the higher-level Socket module, since its IO.Handle based view of sockets is just broken. Stick with the lower-level SocketPrim interface instead. Specifically, stay away from using the following: * Socket. connectTo * Socket.accept * Socket.sendTo * Socket. recvFrom * SocketPrim.socketToHandle --sigbjorn Thanks for the help and valuable information. 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 As the log of the webserver reveals the sendTo works fine. Any idea what could be my problem? Sven Eric ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Socket library ghc 5.02.1
"Sven Eric Panitz" <[EMAIL PROTECTED]> writes: > > It seems that the Socket library does still not work > with ghc 5.02.1. > I tried the simple test: > > > main = > > do > > d <- connectTo "localhost" (PortNumber 80) > > hPutStr d "GET / HTTP/1.0\n\n" > > hFlush d > > c <- hGetContents d > > putStr c > > On Windows2000 I get the known error: > > *** Exception: does not exist > Action: getProtocolByName > Reason: no such protocol entry > (You, of course, need to wrap up that code with Socket.withSocketDo to start up WinSock first). FYI, in case you're planning on doing socket programming with GHC-5.02 on a Win32 platform, stay away from using the higher-level Socket module, since its IO.Handle based view of sockets is just broken. Stick with the lower-level SocketPrim interface instead. Specifically, stay away from using the following: * Socket. connectTo * Socket.accept * Socket.sendTo * Socket. recvFrom * SocketPrim.socketToHandle --sigbjorn ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: Socket library ghc 5.02.1
> Am 22. Nov 2001 um 16:22 MET schrieb Simon Marlow: > > I'm sad to say there was another bug in > SocketPrim.getSocketOption in > > 5.02.1. Please try the enclosed patch. > > How does this explain the two differing behaviours? > And why didn't it happen in a compiled version? Because the 'optlen' parameter to getsockopt was wrong (1 instead of sizeof(int)), which means that the other 3 bytes would be garbage. If the other 3 bytes happened to be zero, you probably wouldn't notice. Anyway, I've tested this with the latest sources and it seems to work, whereas I can repro the bug with 5.02.1 in GHCi. Cheers, Simon ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Socket library ghc 5.02.1
Am 22. Nov 2001 um 16:22 MET schrieb Simon Marlow: > I'm sad to say there was another bug in SocketPrim.getSocketOption in > 5.02.1. Please try the enclosed patch. How does this explain the two differing behaviours? And why didn't it happen in a compiled version? -- Volker Stolz * [EMAIL PROTECTED] * PGP + S/MIME ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: Socket library ghc 5.02.1
> In local.glasgow-haskell-users, you wrote: > > It seems that the Socket library does still not work > > with ghc 5.02.1. > > [ghci clarification] > There, it crashes for me even on the 2nd invocation: > > connect(13, {sin_family=AF_INET, sin_port=htons(80), > sin_addr=inet_addr("137.226.194.33")}}, 16) = -1 EINPROGRESS > (Operation now in progress) > gettimeofday({1006436761, 219035}, NULL) = 0 > select(14, [], [13], NULL, {134, 217727}) = 1 (out [13], left > {134, 22}) > getsockopt(13, SOL_SOCKET, SO_ERROR, [1835091456], [1]) = 0 > write(1, "*", 1)= 1 > > whereas on the first, succeeding call to 'connect' it says; > > select(14, [], [13], NULL, {134, 217727}) = 1 (out [13], left > {134, 21}) > getsockopt(13, SOL_SOCKET, SO_ERROR, [0], [1]) = 0 I'm sad to say there was another bug in SocketPrim.getSocketOption in 5.02.1. Please try the enclosed patch. Cheers, Simon patch Description: patch
Re: Socket library ghc 5.02.1
In local.glasgow-haskell-users, you wrote: > It seems that the Socket library does still not work > with ghc 5.02.1. [ghci clarification] There, it crashes for me even on the 2nd invocation: connect(13, {sin_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("137.226.194.33")}}, 16) = -1 EINPROGRESS (Operation now in progress) gettimeofday({1006436761, 219035}, NULL) = 0 select(14, [], [13], NULL, {134, 217727}) = 1 (out [13], left {134, 22}) getsockopt(13, SOL_SOCKET, SO_ERROR, [1835091456], [1]) = 0 write(1, "*", 1)= 1 whereas on the first, succeeding call to 'connect' it says; select(14, [], [13], NULL, {134, 217727}) = 1 (out [13], left {134, 21}) getsockopt(13, SOL_SOCKET, SO_ERROR, [0], [1]) = 0 This looks like some on-the-fly bitrotting in ghci :-/ -- Volker Stolz * [EMAIL PROTECTED] * PGP + S/MIME ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Socket library ghc 5.02.1
From: Volker Stolz <[EMAIL PROTECTED]> Cc: [EMAIL PROTECTED] In local.glasgow-haskell-users, you wrote: >> main = >> do >> d <- connectTo "localhost" (PortNumber 80) >> hPutStr d "GET / HTTP/1.0\n\n" >> hFlush d >> c <- hGetContents d >> putStr c > > whereas on Linux I get the following error: > *** Exception: failed > Action: connect > Reason: Unknown error 142731264 Please run the program with 'strace', e.g. strace -o log ./a.out and post the log when it fails. Be aware that 'hGetContents' is broken on 5.02.1 if you use it extensively (the GC will close already-reused fds and cause your program to crash!), the patch was recently postet to -bugs by Simon Marlow and works. OTOH, this is not the bug you're seeing. As I just figured out, reported error above only occurs within ghci. Otherwise Sockets seem to work on ghc 5.02.1 for Linux. Sven Eric ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Socket library ghc 5.02.1
In local.glasgow-haskell-users, you wrote: >> main = >> do >> d <- connectTo "localhost" (PortNumber 80) >> hPutStr d "GET / HTTP/1.0\n\n" >> hFlush d >> c <- hGetContents d >> putStr c > > whereas on Linux I get the following error: > *** Exception: failed > Action: connect > Reason: Unknown error 142731264 Please run the program with 'strace', e.g. strace -o log ./a.out and post the log when it fails. Be aware that 'hGetContents' is broken on 5.02.1 if you use it extensively (the GC will close already-reused fds and cause your program to crash!), the patch was recently postet to -bugs by Simon Marlow and works. OTOH, this is not the bug you're seeing. -- Volker Stolz * [EMAIL PROTECTED] * PGP + S/MIME ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Socket library ghc 5.02.1
It seems that the Socket library does still not work with ghc 5.02.1. I tried the simple test: > main = > do > d <- connectTo "localhost" (PortNumber 80) > hPutStr d "GET / HTTP/1.0\n\n" > hFlush d > c <- hGetContents d > putStr c On Windows2000 I get the known error: *** Exception: does not exist Action: getProtocolByName Reason: no such protocol entry whereas on Linux I get the following error: *** Exception: failed Action: connect Reason: Unknown error 142731264 The error number changes for every invocation and every 20th time or so it works on the linux machine. Can anyone recommend me, how to get a working Socket library with ghc 5.02. (I really need it now...) Sven Eric ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users