SocketReadStream positionable?

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

SocketReadStream positionable?

Bill Schwab-2
Blair,

SocketReadStream resets its position in #readPage.  It is reasonable to
conclude that one could get into trouble if trying to "rewind"?  For
example, I frequently have need to read ahead into a stream, decide what
kind of data lurks therein, then backup to allow the appropriate type of
object read from the stream.

One obvious solution would be to have the target object read all but the
initial data.  However, it's easier<g> to reposition.

I first encountered this with serial ports, but it's often necessary to do
some parsing and/or decoding to get the data I need, so in most cases, I end
up reading from a derived ReadStream over a string or byte array where
positioning works as expected.

I now have a problem that would be easier to solve if I could reposition a
SocketReadStream, but I'm afraid that it would not be reliable.  Am I
missing something?  If not, is SocketReadStream's behavior a bug or a
feature?

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: SocketReadStream positionable?

Blair McGlashan
"Bill Schwab" <[hidden email]> wrote in message
news:bmhivh$ms0oh$[hidden email]...

> Blair,
>
> SocketReadStream resets its position in #readPage.  It is reasonable to
> conclude that one could get into trouble if trying to "rewind"?  For
> example, I frequently have need to read ahead into a stream, decide what
> kind of data lurks therein, then backup to allow the appropriate type of
> object read from the stream.
>...
> I now have a problem that would be easier to solve if I could reposition a
> SocketReadStream, but I'm afraid that it would not be reliable.  Am I
> missing something?  If not, is SocketReadStream's behavior a bug or a
> feature?

I think you should assume that it can really only be read forwards-only. The
implementation should disallow backwards repositioning at the very least. I
think the whole meaning of "position" on SocketReadStream is a bit dubious.
Recorded as defect #1345.

Thanks

Blair


Reply | Threaded
Open this post in threaded view
|

Re: SocketReadStream positionable?

Bill Schwab-2
Blair,

> I think you should assume that it can really only be read forwards-only.
The
> implementation should disallow backwards repositioning at the very least.

I don't envy you the task of deciding what backwards means =:0

> I
> think the whole meaning of "position" on SocketReadStream is a bit
dubious.
> Recorded as defect #1345.

Fair enough.  There might also be room for a decorator.  I have something
that works in a limited context with serial ports.  IIRC, it copies
everything read through it (from the decorated stream) until it is asked to
rewind - it assumes that will happen.  Then it replays the buffer, and then
finally switches over to the real stream.  I can send it to you if you think
you might want to do something similar for sockets.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]