Re: Socket library ghc 5.02.1

2001-11-28 Thread Sven Eric Panitz



 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

2001-11-27 Thread Sven Eric Panitz



 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

2001-11-27 Thread Sigbjorn Finne


 
 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

2001-11-26 Thread Sigbjorn Finne


 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

2001-11-22 Thread Volker Stolz

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



Re: Socket library ghc 5.02.1

2001-11-22 Thread Volker Stolz

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

2001-11-22 Thread Simon Marlow


 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

2001-10-25 Thread Sven Eric Panitz



as I have learnt now, there are problems with Sockets and ghc 5.02:

http://haskell.org/pipermail/glasgow-haskell-users/2001-October/001008.html


Unfortunately, I am currently working on WinNT and would not like to
go back and install ghc4.08. Is there an easy way to patch this problem
in my 5.02 installation.

Sven Eric



___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: Socket library

2001-10-25 Thread Volker Stolz

In local.glasgow-haskell-users, you wrote:
 Unfortunately, I am currently working on WinNT and would not like to
 go back and install ghc4.08. Is there an easy way to patch this problem
 in my 5.02 installation.

Maybe you're just lacking the Wintendo equivalent of /etc/protocols, but
I don't know how Windows/cygwin handle these things. You could modify
SocketPrim to use the number 6 instead of trying to do the getprotobyname
lookup, but that's not a real remedy.
-- 
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

2001-10-24 Thread Sven Eric Panitz


I just wanted to play a bit with the Socket library comming
with Haskell. However, whatever I try to do, I get the following
runtime error, eg in ghci:

Socket  connectTo pcsep (PortNumber 80)
*** Exception: does not exist
Action: getProtocolByName
Reason: no such protocol entry


Seems that I am doing something wrong here?

Sven Eric

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



RE: Socket library

2001-10-24 Thread Simon Marlow

 I just wanted to play a bit with the Socket library comming
 with Haskell. However, whatever I try to do, I get the following
 runtime error, eg in ghci:
 
 Socket  connectTo pcsep (PortNumber 80)
 *** Exception: does not exist
 Action: getProtocolByName
 Reason: no such protocol entry
 
 
 Seems that I am doing something wrong here?

Which platform are you on?  (there is a bug in 5.02's networking library
which means that Socket.conncetTo might not work - but I haven't seen it
produce the error that you quote above).

Simon

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users