2

When processing input, it can be useful to know if you are being sent data in a firehose-like manner; that is, you get to see the data once and it's forever lost once it goes through the stream.

There are lots of examples of firehoses, such as console input, signal capture devices, data streams from network sockets, or named pipes.

C++ streams and streambufs are supposed to encapsulate input and output behavior, but I'm not sure there's a standard non-destructive way to detect whether the associated sequence lurking behind a streambuf you've been handed is seekable or not.

What if you called streambuf::pubseekoff (0, cur, std::ios_base::in) ? Can you rely on that?

Does the standard (or at least design sense) require such a call to seekoff to return streampos(-1) if the associated sequence is not physically seekable? Would it set failbit? Is it undefined behavior?

These streams don't have a viable concept of "absolute position" and so a seekoff probably should return -1 even if the seek does nothing.

But if that behavior is not required, some library designer might have decided to return something else from seekoff in such a case. Perhaps the number of characters fed through the firehose so far. Or gptr()-eback() (useless). Or a random number.

The streambuf type I have the most uncertainty about is basic_filebuf. You should certainly be able to seek within a disk file, but the OS can also encapsulate firehose type streams within the 'file' concept.

Spencer
  • 1,924
  • 15
  • 27
  • Possible duplicate of [C++ how to check if a stream (iostream) is seekable](http://stackoverflow.com/questions/9451005/c-how-to-check-if-a-stream-iostream-is-seekable) – sigy Jan 18 '17 at 14:55

0 Answers0