<div dir="ltr">Hi Ron,<div><br></div><div>Thanks for that - but I can only see #dataAvailable for Sockets, not for FileStream (named pipes). I think the same kind of thing is available for pipes (you can do `pipe size` to see how much data is there), but it still doesn&#39;t wait. I&#39;m trying to avoid a busy loop waiting for the data - like this:</div>

<div><br></div><div>start := DateAndTime millisecondClockValue.</div><div>(pipe size &lt; 32) &amp; (DateAndTime millisecondClockValue - start &lt; 3000) ifTrue: [</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>(Delay forMilliseconds 50) wait.</div>

<div>]</div><div>pipe size = 32 ifTrue: [</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Get data&quot;</div><div>] ifFalse: [</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Deal with timeout&quot;</div>

<div>]</div><div><br></div><div>The shorter the &#39;wait&#39;, the more responsive the code is to data arriving on the pipe, but the more CPU it will use as it spins round the loop. The longer the &#39;wait&#39;, the more lag it has for data coming back. That&#39;s what I&#39;m trying to avoid by blocking on the read, but with a way to escape after some timeout.</div>

<div><br></div><div>I&#39;m guessing the call to &#39;pipe next:&#39; is a primitive, and blocks there, which is why valueWithin:onTimeout: doesn&#39;t return after the timeout, but does eventually return the correct answer. So, I&#39;m guessing I&#39;ll have to do something like this:</div>

<div><ul><li>Set up a semaphore</li><li>Fork the blocking read process, which will signal the semaphore if it ever returns its 32 bytes</li><li>In the main thread, wait for up to 3 seconds for the semaphore to be signalled</li>

<li>If the semaphore times out, kill the forked process</li></ul>Obviously there&#39;s a potential race at the end there, but the worst case is we throw away data which was returned at the last moment. Is there anything else you can see wrong with this approach?</div>

<div><br></div><div>Thanks,</div><div><br></div><div>Dave</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jan 9, 2014 at 9:16 PM, Ron Teitelbaum [via Smalltalk] <span dir="ltr">&lt;<a href="/user/SendEmail.jtp?type=node&node=4735661&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>&gt;</span> wrote:<br>

<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

        Hi Dave,
<br><br>See #dataAvailable  and #recieveAvailableData.
<br><br>It&#39;s never good to call for data if you don&#39;t know you have any.  Better to
<br>setup a wait for data until call instead.  
<br><br>All the best,
<br><br>Ron Teitelbaum
<br>Head Of Engineering
<br>3d Immersive Collaboration Consulting
<br><a href="http://user/SendEmail.jtp?type=node&amp;node=4735547&amp;i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>
<br>Follow Me On Twitter: @RonTeitelbaum
<br><a href="http://www.3dicc.com" target="_blank" rel="nofollow" link="external">www.3dicc.com</a> 
<br><a href="https://www.google.com/+3dicc" rel="nofollow" link="external" target="_blank">https://www.google.com/+3dicc</a><br><br><div><div class='shrinkable-quote'><br>&gt; -----Original Message-----
<br>&gt; From: <a href="http://user/SendEmail.jtp?type=node&amp;node=4735547&amp;i=1" rel="nofollow" link="external" target="_blank">[hidden email]</a> [mailto:<a href="/user/SendEmail.jtp?type=node&node=4735661&i=1" target="_top" rel="nofollow" link="external">[hidden email]</a>
<br>&gt; <a href="http://user/SendEmail.jtp?type=node&amp;node=4735547&amp;i=2" rel="nofollow" link="external" target="_blank">[hidden email]</a>] On Behalf Of dsl101
<br>&gt; Sent: Thursday, January 09, 2014 10:16 AM
<br>&gt; To: <a href="http://user/SendEmail.jtp?type=node&amp;node=4735547&amp;i=3" rel="nofollow" link="external" target="_blank">[hidden email]</a>
<br>&gt; Subject: [Newbies] Read a filestream (named pipe) with a timeout
<br>&gt; 
<br>&gt; I&#39;m using Squeak 4.2 and working on the smalltalk end of a named pipe
<br>&gt; connection, which sends a message to the named pipe server with:
<br>&gt; 
<br>&gt;         msg := &#39;Here&#39;&#39;s Johnny!!!!&#39;.
<br>&gt;         pipe nextPutAll: msg; flush.
<br>&gt; 
<br>&gt; It should then receive an acknowledgement, which will be a 32-byte md5
</div>hash of
<br>&gt; the received message (which the smalltalk app can then verify). It&#39;s
</div>possible the
<br>&gt; named pipe server may have gone away or otherwise been unable to deal with
<br>&gt; the request, and so I&#39;d like to set a timeout on reading the
<br>acknowledgement.
<br>&gt; I&#39;ve tried using this:
<br>&gt; 
<br>&gt;         ack := [ pipe next: 32 ] valueWithin: (Duration seconds: 3)
<br>onTimeout: [
<br>&gt; &#39;timeout&#39;. ].
<br>&gt; 
<br>&gt; and then made the pipe server pause artificially to test the code. But the
<br>&gt; smalltalk thread blocks on the read and doesn&#39;t carry on (even after the
<br>&gt; timeout), although if I then get the pipe server to send the correct
<br>response
<br>&gt; (after a 5 second delay, for example), the value of &#39;ack&#39; is &#39;timeout&#39;.
<br>Obviously
<br>&gt; the timeout did what it&#39;s supposed to do, but couldn&#39;t &#39;unblock&#39; the
<br>blocking
<br>&gt; read on the pipe.
<br>&gt; 
<br>&gt; Is there a way to accomplish this even with a blocking FileStream read?
<br>I&#39;d rather
<br>&gt; avoid a busy wait on there being 32 characters available if at all
<br>possible.
<br>&gt; 
<br>&gt; Thanks,
<br>&gt; 
<br>&gt; Dave
<br>&gt; 
<br>&gt; 
<br>&gt; 
<br>&gt; --
<br>&gt; View this message in context:
<br><a href="http://forum.world.st/Read-a-filestream-named-" rel="nofollow" link="external" target="_blank">http://forum.world.st/Read-a-filestream-named-</a><br>&gt; pipe-with-a-timeout-tp4735456.html
<br>&gt; Sent from the Squeak - Beginners mailing list archive at Nabble.com.
<br>&gt; _______________________________________________
<br>&gt; Beginners mailing list
<br>&gt; <a href="http://user/SendEmail.jtp?type=node&amp;node=4735547&amp;i=4" rel="nofollow" link="external" target="_blank">[hidden email]</a>
<br>&gt; <a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" rel="nofollow" link="external" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br><br><br>_______________________________________________
<br>Beginners mailing list
<br><a href="http://user/SendEmail.jtp?type=node&amp;node=4735547&amp;i=5" rel="nofollow" link="external" target="_blank">[hidden email]</a>
<br><a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" rel="nofollow" link="external" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>

        
        
        
        <br>
        <br>
        <hr noshade size="1" color="#cccccc">
        <div style="color:#444;font:12px tahoma,geneva,helvetica,arial,sans-serif">
                <div style="font-weight:bold">If you reply to this email, your message will be added to the discussion below:</div>
                <a href="http://forum.world.st/Read-a-filestream-named-pipe-with-a-timeout-tp4735456p4735547.html" target="_blank" rel="nofollow" link="external">http://forum.world.st/Read-a-filestream-named-pipe-with-a-timeout-tp4735456p4735547.html</a>
        </div>
        <div style="color:#666;font:11px tahoma,geneva,helvetica,arial,sans-serif;margin-top:.4em;line-height:1.5em">
                
                To unsubscribe from Read a filestream (named pipe) with a timeout, <a href="" target="_blank" rel="nofollow" link="external">click here</a>.<br>


                <a href="http://forum.world.st/template/NamlServlet.jtp?macro=macro_viewer&amp;id=instant_html%21nabble%3Aemail.naml&amp;base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&amp;breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" rel="nofollow" style="font:9px serif" target="_blank" link="external">NAML</a>
        </div></blockquote></div><br></div>


        
        
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://forum.world.st/Read-a-filestream-named-pipe-with-a-timeout-tp4735456p4735661.html">Re: Read a filestream (named pipe) with a timeout</a><br/>
Sent from the <a href="http://forum.world.st/Squeak-Beginners-f107673.html">Squeak - Beginners mailing list archive</a> at Nabble.com.<br/>