Socket
Simon Marlow
simonmar@microsoft.com
Thu, 9 Aug 2001 17:30:03 +0100
> Koen writes:
>=20
> > accept :: Socket -> IO (Handle, HostName, PortNumber)
> >=20
> > 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.
>=20
> man 2 accept on my Linux says:
>=20
> 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.
>=20
> So I imagine if you passed the socket as the first arg to=20
> Select.hSelect, you'd get what you want. =20
> SocketPrim.socketToHandle claims to do the required conversion.
>=20
> disclaimer: I haven't tried this.
Strange, I haven't received the original message in this thread yet (I
read it from the archives).
'accept' doesn't block the whole program, it only blocks the current
thread - it's designed to be well-behaved in a multi-threaded program.
If you need the select() behaviour, I recommend using multiple threads
and let GHC's RTS handle the I/O multiplexing.
You mentioned that you weren't using concurrency for a good reason -
care to elaborate?
Cheers,
Simon