Try calling 'blockSocket' before binding it.

--sigbjorn

-----Original Message-----
From: Wojciech Moczydlowski, Jr [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 02, 2000 00:48
To: Sigbjorn Finne
Cc: [EMAIL PROTECTED]
Subject: RE: Socket and SocketPrim


On Sat, 1 Apr 2000, Sigbjorn Finne wrote:

> 
> Either make the necessary changes to the lib sources or turn

I tried it, but I have some troubles with compiling ghc from current cvs
sources. 

> 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
> 
Doesn't work either. The following:
-----------------------------------------------
createSocket:: IO Socket
createSocket = do
         sock <- socket AF_INET Stream 0
         let addr = (SockAddrInet (mkPortNumber 2000) iNADDR_ANY) in do
              bindSocket sock addr
              return sock

-- 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

proc2 = do
        sock <- createSocket
        print "d"
        blockSocket sock
        (res, _, _) <- recvFrom sock 1000
        print res

main = do
        proc2
-----------------------------------------------
just outputs:
"d"
""
, without any waiting. I tried to do it also by:
--------------------------------------------------
      h <- socketToHandle sock ReadWriteMode
      f <- handleToFd h
      b <- queryFdOption f NonBlockingRead
      setFdOption f NonBlockingRead False
------------------------------------------------

Yet it didn't work either - didn't block.
What's the point in making the socket nonblocking when creating it?

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

"Mais espoir il y a quand meme!"



Reply via email to