[Haskell-cafe] interrupting an accept()ing thread
rich.neswold at gmail.com
Sat Jul 7 00:38:47 EDT 2007
On 7/5/07, Lukas Mai <l.mai at web.de> wrote:
> Hello, cafe!
> I have the following code (paraphrased):
> forkIO spin
> spin = do
> (t, _) <- accept s -- (*)
> forkIO $ dealWith t -- (**)
> My problem is that I want to stop spin from another thread. The "obvious"
> solution would be to throw it an exception. However, that leaks a socket
> (t) if the exception arrives between (*) and (**). I could wrap the whole
> thing in block, but from looking at the source of Network.Socket it seems
> that accept itself is not exception safe; so no matter what I do, I can't
> use asynchronous exceptions to make spin exit.
What about using "bracketOnError"?
nextClient s = bracketOnError (fst . accept s) sClose
spin = do
nextClient s (\s' -> forkIO $ dealWith s')
If "bracketOnError" leaks the resource in the event of an exception, then it
needs to be fixed.
JID: rich at neswold.homeunix.net
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe