Read a filestream (named pipe) with a timeout in Smalltalk
Asked Answered
R

1

7

I posted this to the Squeak Beginners list too - I'll be sure to make sure any answers from there get here :)

I'm using Squeak 4.2 and working on the smalltalk end of a named pipe connection, which sends a message to the named pipe server with:

    msg := 'Here''s Johnny!!!!'. 
    pipe nextPutAll: msg; flush. 

It should then receive an acknowledgement, which will be a 32-byte md5 hash of the received message (which the smalltalk app can then verify). It's possible the named pipe server may have gone away or otherwise been unable to deal with the request, and so I'd like to set a timeout on reading the acknowledgement. I've tried using this:

    ack := [ pipe next: 32 ] valueWithin: (Duration seconds: 3) onTimeout: [ 'timeout'. ]. 

and then made the pipe server pause artificially to test the code. But the smalltalk thread blocks on the read and doesn't carry on (even after the timeout), although if I then get the pipe server to send the correct response (after a 5 second delay, for example), the value of 'ack' is 'timeout'. Obviously the timeout did what it's supposed to do, but couldn't 'unblock' the blocking read on the pipe.

Is there a way to accomplish this even with a blocking FileStream read? I'd rather avoid a busy wait on there being 32 characters available if at all possible.

Renfroe answered 9/1, 2014 at 15:23 Comment(1)
Just for info, I never did find a satisfactory answer to this. The reason I was using a named pipe was because starting a socket server would throw up firewall warnings. However, I then found that binding the socket server to 127.0.0.1 (rather than the default 0.0.0.0) doesn't trigger the warnings - at least on the Windows platform. So, problem, er, avoided.Renfroe
E
1

This one may come in handy but not on Windows I am afraid.

http://www.samadhiweb.com/blog/2013.07.27.unixdomainsockets.html

Edmonton answered 27/11, 2014 at 10:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.