GHC's Socket libraries only half-heartedly support non-blocking
socket ops at the moment, which is the reason for the behaviour
you're seeing.

Either make the necessary changes to the lib sources or turn
blocking back on again, i.e., use the gratituitous 'blockSocket',

-- make socket ops block - pretty disgusting.
-- Need to import Posix to use.
blockSocket :: Socket -> IO ()
blockSocket sock = do
  h    <- socketToHandle sock ReadMode
  fd   <- handleToFd h
  _casm_ `` { int flags = fcntl(%0, F_GETFL);  fcntl(%0, F_SETFL, flags &
~O_NONBLOCK); } '' fd

inside 'createSocket' (remember to add '-#include <fcntl.h>' when
compiling.)

hth
--sigbjorn

-----Original Message-----
From: Wojciech Moczydlowski, Jr [mailto:[EMAIL PROTECTED]]
Sent: Saturday, April 01, 2000 12:46
To: [EMAIL PROTECTED]
Subject: Socket and SocketPrim


  I've just had a couple of troubles with Socket and SocketPrim. Let's take
the following program:

---------------------------------------------------------------
module Main where

import Socket hiding (recvFrom)
import SocketPrim

createSocket:: IO Socket
createSocket = do
         sock <- socket AF_INET Datagram 0
         let addr = (SockAddrInet (mkPortNumber 2000) iNADDR_ANY) in do
              bindSocket sock addr
              return sock

proc1 = connectTo "localhost" (PortNumber $ mkPortNumber 0) >>= 
        hGetContents >>= 
        print
        
proc2 = do
        sock <- createSocket
        recvFrom sock 1000

main = proc1 >> proc2
---------------------------------------------------------------
IMO proc1 should throw some exception or report error. Yet it just outputs
"".
proc2 should hang on a socket until someone connects to it. Nevertheless,
the program outputs:

Fail: resource exhausted
Action: recvFrom
Reason: insufficient resources

Maybe I'm doing sth wrong here?

Khaliff TM                                   [EMAIL PROTECTED]
                                             http://www2.ids.pl/~khaliff

"The bridge is crossed, so stand and watch it burn."




Reply via email to