On 3/4/06, Christian Biesinger <[EMAIL PROTECTED]> wrote: > Jon Smirl wrote: > > The header for the available() method says it will return > > NS_BASE_STREAM_CLOSED but it doesn't seem to be doing that. > > It says it will return that if the stream is closed. It also says that > it returns 0 if the stream if at EOF but not closed. You didn't close it > presumably, so it's not closed. > > Hm, the documentation here doesn't seem to be so great... > > > And in my code it isn't returning > > NS_BASE_STREAM_CLOSED, it just returns zero available and I loop. > > Sounds like a bug in your code :-) The docs say that 0 means EOF.
I was basing the code on this. With a zero for EOF you can't tell whether their isn't data available or if the socket is closed. Zero at EOF is fine, but it needs to return NS_BASE_STREAM_CLOSED for the result value. /** * Determine number of bytes available in the stream. A non-blocking * stream that does not yet have any data to read should return 0 bytes * from this method (i.e., it must not throw the NS_BASE_STREAM_WOULD_BLOCK * exception). * * In addition to the number of bytes available in the stream, this method * also informs the caller of the current status of the stream. A stream * that is closed will throw an exception when this method is called. That * enables the caller to know the condition of the stream before attempting * to read from it. If a stream is at end-of-file, but not closed, then * this method should return 0 bytes available. * * @return number of bytes currently available in the stream, or * PR_UINT32_MAX if the size of the stream exceeds PR_UINT32_MAX. * * @throws NS_BASE_STREAM_CLOSED if the stream is closed normally or at * end-of-file * @throws <other-error> if the stream is closed due to some error * condition */ /* unsigned long available (); */ NS_IMETHOD Available(PRUint32 *_retval) = 0; If I am using a low level input stream from rv = aTransport->OpenInputStream(0, 0, 0, getter_AddRefs(instream)); Is there any way to peek at the data? If I can't peek at the data I need to implement my own buffering. With a peek function I can leave it in the stream buffer. I'm looking for the \n\n\ at the end of the headers so that I can start header parsing. -- Jon Smirl [EMAIL PROTECTED] _______________________________________________ dev-tech-network mailing list dev-tech-network@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-tech-network