Since there is #peek there is no reason not to add #peekFor: as peekFor: object "Answer false and do not move over the next element if it is not equal to object, or if the receiver is at the end. Answer true and move over the next element when it is equal to object." ^ self peek = object ifTrue: [ self next. true ] ifFalse: [ false ] But note that the Zdc socket streams do not make a difference between synchronous / asynchronous - IIRC I would say they block (they are also always binary and flush when their buffer is full). Peeking in the context of a socket / network stream will block, just like reading.
On 16 Mar 2019, at 19:44, Alistair Grant <akgrant0710@gmail.com> wrote:
Hi Esteban, On Sat, 16 Mar 2019 at 19:37, Esteban Maringolo <emaringolo@gmail.com> wrote:
I don't know the answer but how could you peek for data that has yet not come through the socket? In the buffer? Should it block?
From memory: It depends on the mode of the stream:
If synchronous: peeking will block until data is available. If asynchronous: if data is available, the next byte / character is returned. If no data is available, nil is returned. If nil is returned, you need to check if the socked is #atEnd to determine whether it is the end of the stream or just nothing available now.
Cheers, Alistair
Regards.
El sáb., 16 de mar. de 2019 12:23, Alistair Grant <akgrant0710@gmail.com> escribió:
Hi Sven,
Unlike most streams that support #peek, ZdcAbstractSocketStream doesn't support #peekFor:.
Is this intentional, or an oversight?
Thanks, Alistair