help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Timeouts for BlockClosures


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Timeouts for BlockClosures
Date: Thu, 21 Apr 2011 07:52:28 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.9

On 04/20/2011 08:35 PM, Holger Hans Peter Freyther wrote:
> (Delay forSeconds: 3)
>       value: [socket next: N]
>       onTimeoutDo: [a) socket readBuffer.. ->  ptr is back to 1]
> 
> so there must be some ensure: [] block that resets the endptr.

No, it's just that "ptr := 1" is set before calling the fillBlock.  I
can apply this patch:

diff --git a/packages/sockets/Buffers.st b/packages/sockets/Buffers.st
index 2084797..de02511 100644
--- a/packages/sockets/Buffers.st
+++ b/packages/sockets/Buffers.st
@@ -137,8 +137,8 @@ evaluates an user defined block to try to get some more 
data.'>
        <category: 'buffer handling'>
        self basicAtEnd ifFalse: [^false].
        fillBlock isNil ifTrue: [^true].
-       ptr := 1.
        endPtr := fillBlock value: collection value: collection size.
+       ptr := 1.
        ^self basicAtEnd
     ]
 

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.

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]