Hi, I am implementing a modest webserver using GHC (as an example program). I am using the Socket library. In the Socket library, the following function is provided: accept :: Socket -> IO (Handle, HostName, PortNumber) Unfortunately, this is a blocking function, which means that the whole program blocks when it is waiting for a connection. This is not nice, since I would like to do something else in the meantime (such as serving other clients). I do not want to use the "concurrent" package (for a good reason). Ideally, I would like to integrate this with the function "hSelect" from the Select module. Has anybody had this problem before, and, if so, what could be a solution? Thanks, /Koen. -- Koen Claessen http://www.cs.chalmers.se/~koen phone:+46-31-772 5424 mailto:koen@cs.chalmers.se ----------------------------------------------------- Chalmers University of Technology, Gothenburg, Sweden
Koen writes:
accept :: Socket -> IO (Handle, HostName, PortNumber)
Unfortunately, this is a blocking function, which means that the whole program blocks when it is waiting for a connection. [..] Ideally, I would like to integrate this with the function "hSelect" from the Select module.
man 2 accept on my Linux says: In order to be notified of incoming connections on a socket, you can use select(2) or poll(2). A readable event will be delivered when a new connection is attempted and you may then call accept to get a socket for that con- nection. So I imagine if you passed the socket as the first arg to Select.hSelect, you'd get what you want. SocketPrim.socketToHandle claims to do the required conversion. disclaimer: I haven't tried this. --KW 8-) -- Keith Wansbrough <kw217@cl.cam.ac.uk> http://www.cl.cam.ac.uk/users/kw217/ Cambridge University Computer Laboratory.
Keith writes: | So I imagine if you passed the socket as the first arg | to Select.hSelect, you'd get what you want. | SocketPrim.socketToHandle claims to do the required | conversion. Yes, this works. Thanks. (BTW, The documentation of "SocketPrim.socketToHandle" reports the wrong type ("IOMode" argument is missing). Forwarded to glasgow-haskell-bugs.) /Koen.
participants (2)
-
Keith Wansbrough -
Koen Claessen