M
Matt Chaplain
Hi there.
I'm writing a program that uses the Telnet protocol over TCP/IP
sockets. Of course, that has no bearing here, so I'll rephrase that
in Standard C++
In essense, I'm trying to manipulate a data stream by using a custom
streambuf, so that I can access this as "just another iostream".
Alas, this data stream has a couple of "interesting" properties:
1) It is non-blocking. There is a chance that, when reading from this
stream, there will be a flag of "no data". This doesn't mean "there
will not ever be any data", just "nothing right now, check back
later".
2) 0 is a meaningful value.
Combined, I am unsure of how to proceed. Sending negative numbers
seems not to work: Returning -1 in the case of no data sets fail bits
and looks identical to EOF (indeed, I believe it is the value returned
in the case of an EOF, at least on my platform). Returning -2 is
detectable when reading from the stream as strm.getc(), but tends
towards garbage when using the >> operator.
In short, does anybody know how to communicate "no data" from
streambuf to stream, or would I have to write a custom stream too?
Thanks,
Matt Chaplain
I'm writing a program that uses the Telnet protocol over TCP/IP
sockets. Of course, that has no bearing here, so I'll rephrase that
in Standard C++
In essense, I'm trying to manipulate a data stream by using a custom
streambuf, so that I can access this as "just another iostream".
Alas, this data stream has a couple of "interesting" properties:
1) It is non-blocking. There is a chance that, when reading from this
stream, there will be a flag of "no data". This doesn't mean "there
will not ever be any data", just "nothing right now, check back
later".
2) 0 is a meaningful value.
Combined, I am unsure of how to proceed. Sending negative numbers
seems not to work: Returning -1 in the case of no data sets fail bits
and looks identical to EOF (indeed, I believe it is the value returned
in the case of an EOF, at least on my platform). Returning -2 is
detectable when reading from the stream as strm.getc(), but tends
towards garbage when using the >> operator.
In short, does anybody know how to communicate "no data" from
streambuf to stream, or would I have to write a custom stream too?
Thanks,
Matt Chaplain