On 7/5/07, <b class="gmail_sendername">Lukas Mai</b> <<a href="mailto:l.mai@web.de">l.mai@web.de</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello, cafe!<br><br>I have the following code (paraphrased):<br><br>...<br>forkIO spin<br>...<br>spin = do<br> (t, _) <- accept s -- (*)<br> forkIO $ dealWith t -- (**)<br> spin<br><br>My problem is that I want to stop spin from another thread. The "obvious"
<br>solution would be to throw it an exception. However, that leaks a socket<br>(t) if the exception arrives between (*) and (**). I could wrap the whole<br>thing in block, but from looking at the source of Network.Socket
it seems<br>that accept itself is not exception safe; so no matter what I do, I can't<br>use asynchronous exceptions to make spin exit.<br></blockquote></div><br>What about using "bracketOnError"?<br clear="all">
<br>nextClient s = bracketOnError (fst . accept s) sClose<br><br>spin = do<br> nextClient s (\s' -> forkIO $ dealWith s')<br> spin<br><br>If "bracketOnError" leaks the resource in the event of an exception, then it needs to be fixed.
<br><br>-- <br>Rich<br><br>JID: <a href="mailto:rich@neswold.homeunix.net">rich@neswold.homeunix.net</a><br>AIM: rnezzy