Mantis - Squeak
Viewing Issue Advanced Details
7446 Network minor always 01-13-10 19:47 04-18-10 21:57
sig  
laza  
normal  
closed trunk  
fixed  
none    
none trunk  
0007446: [BUG][FIX] SocketStream>>peek
Peek should answer a next item to read , but do not advance the stream position.
Therefore a following test should yield true:

a := anyStream peek.
b := anyStream next.

self assert: (a = b).

In a SocketStream, however , #next, first advances the lastRead ivar,
then reads a next char
answering inBuffer at: pos+1 ( where pos is the lastRead value
before sending #next )

SocketStream>>next
       "Return next byte, if inBuffer is empty
       we recieve some more data and try again."

       self atEnd ifTrue: [^nil].
       self isInBufferEmpty ifTrue:
               [self receiveData.
               self atEnd ifTrue: [^nil]].
       lastRead := lastRead + 1.
       ^inBuffer at: lastRead

But peek, answering a char from inBuffer at: pos !!!

peek
       "Return next byte, if inBuffer is empty
       we recieve some more data and try again.
       Do not consume the byte."

       self atEnd ifTrue: [^nil].
       self isInBufferEmpty ifTrue:
               [self receiveData.
               self atEnd ifTrue: [^nil]].
       ^inBuffer at: lastRead

The fix is:

--- ^inBuffer at: lastRead
+++ ^inBuffer at: lastRead+1
 socketstream-peek.1.cs [^] (435 bytes) 01-13-10 19:47

Notes
(0013473)
sig   
01-13-10 19:54   
"fix begin"

Installer mantis bug: 7446 fix: 'socketstream-peek.1.cs'.

"fix end"
(0013474)
nicolas cellier   
01-13-10 22:28   
#peekFor: is a bit sick. Need cure too.
#peekForAll: curiously feels better.
(0013537)
laza   
03-09-10 20:19   
Patch is in trunk image