[Scummvm-devel] ReadStream::ioFailed/EOF - StdioStream::read

Max Horn max at quendi.de
Sun Feb 22 05:16:06 CET 2009


Am 21.02.2009 um 20:14 schrieb sunmax at libero.it:

> Hi there ScummVM world!
>
> Couple of questions:
>
> a) how do we handle ReadStream::ioFailed() and eof() there
>   [common/stream.h]
>
>   it's deprecated but used by the unzip engine when parsing
>   the zipped theme

Yeah, well, not all code has been transitioned to the new APIs yet,  
sadly. As usual, a lack of manpower and interest :-(

>   -> the very last unzlocal_getShort in unzOpen -succeeds-
>      cause it reads the last two bytes of the zip file, but
>      then triggers the EOF condition (it's in fin->ioFailed in
>      unzlocal_getShort) which on return sets err=UNZ_ERRNO and
>      causes the theme not to be used on the PS2 backend :-(

Some context would be helpful, you know :-). Not everybody read your  
earlier mails to me and knows that you are having some troubles  
loading theme .zip files in the PS2 port. :)

>
>
>   It sounds as a dumb question but when should the backend
>   implementation return EOF? When we read the last byte, right?
>   That's what I am doing now, but causes it to fail. I wonder
>   if this could be the cause of some games no longer starting
>   on PS2 in 0.13.0 too. I will keep investigating.

The idea is that our stream class should behave *exactly* like the  
standard I/O code in C. Hence, our eos() method should behave like  
feof(), to quote our doxygen for the method:

"
Returns true if a read failed because the stream has been reached.
This flag is cleared by clearErr().
For a SeekableReadStream, it is also cleared by a successful seek.
"

To quote MSDN:
"The feof function returns a nonzero value after the first read  
operation that attempts to read past the end of the file. It returns 0  
if the current position is not end of file. There is no error return."

So, after reading the last byte, then the EOF flag should *not* be  
set. Only after trying to read *beyond* the last byte should it be set.


> b) Why are most of StdioStream::read when reading game data 1 (!)
>   byte long ?
>
>   This forces us to do quite some trickery with read-ahead and
>   cache on PS2.


A lot of code just happens to read stuff bytewise. Which is why you  
may want to do *buffering* in your backend's StdioStream  
implementation. Either by enabling it in your OS, if you have that  
luxury (this is done on AmigaOS and the Wii, see  
StdioStream::makeFromPath in backends/fs/stdiostream.cpp). Or by using  
the BufferedReadStream wrapper class. Or by rolling your own buffering  
code if for some reason you don't like the one we provide you with.  
Please search the archives of this list (look for BufferedReadStream)  
for a discussion on this.


Bye,
Max




More information about the Scummvm-devel mailing list