On 7/5/07, <b class="gmail_sendername">Lukas Mai</b> &lt;<a href="mailto:l.mai@web.de">l.mai@web.de</a>&gt; 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>&nbsp;&nbsp;&nbsp;&nbsp;(t, _) &lt;- accept s&nbsp;&nbsp; -- (*)<br>&nbsp;&nbsp;&nbsp;&nbsp;forkIO $ dealWith t&nbsp;&nbsp;-- (**)<br>&nbsp;&nbsp;&nbsp;&nbsp;spin<br><br>My problem is that I want to stop spin from another thread. The &quot;obvious&quot;
<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&#39;t<br>use asynchronous exceptions to make spin exit.<br></blockquote></div><br>What about using &quot;bracketOnError&quot;?<br clear="all">
<br>nextClient s = bracketOnError (fst . accept s) sClose<br><br>spin = do<br>&nbsp;&nbsp;&nbsp; nextClient s (\s&#39; -&gt; forkIO $ dealWith s&#39;)<br>&nbsp;&nbsp;&nbsp; spin<br><br>If &quot;bracketOnError&quot; 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