On 7/5/07, Lukas Mai <[EMAIL PROTECTED]> wrote:

Hello, cafe!

I have the following code (paraphrased):

...
forkIO spin
...
spin = do
    (t, _) <- accept s   -- (*)
    forkIO $ dealWith t  -- (**)
    spin

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')
   spin

If "bracketOnError" leaks the resource in the event of an exception, then it
needs to be fixed.

--
Rich

JID: [EMAIL PROTECTED]
AIM: rnezzy
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to