Timeouts for BlockClosures

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Timeouts for BlockClosures

Paolo Bonzini-2
On 04/21/2011 10:41 AM, Holger Hans Peter Freyther wrote:

> On 04/21/2011 07:52 AM, Paolo Bonzini wrote:
>
>> but you're walking on thin ice here.  Every time you have a timeout,
>> you should assume that the data structures are in an inconsistent
>> state (just like when you #terminate a Process).  I suggest making
>> your sockets unbuffered if it's not too much overhead.
>
> Right. It is not Erlang after all and we have side-effects. I am not sure on
> the semantics of the following. My work around would be something like
>
> [
> socket waitUntilItCanRead
> ] timeout...
>
> but I am not sure if canRead and such will behave better.

Yes, #ensureReadable will behave better.  It does not have side effects:

        self isOpen ifFalse: [^self].
        self
            fileOp: 14
            with: 0
            with: Semaphore new
            ifFail: [[File checkError: self soError] ensure: [^self close]].
        self
            fileOp: 13
            with: 0
            ifFail: [[File checkError: self soError] ensure: [self close]]

Of course it may be that you don't have 3 bytes available when
#ensureReadable returns...

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
12