[Scummvm-cvs-logs] SF.net SVN: scummvm:[52389] scummvm/trunk/common
wjpalenstijn at users.sourceforge.net
wjpalenstijn at users.sourceforge.net
Wed Aug 25 16:43:42 CEST 2010
Revision: 52389
http://scummvm.svn.sourceforge.net/scummvm/?rev=52389&view=rev
Author: wjpalenstijn
Date: 2010-08-25 14:43:42 +0000 (Wed, 25 Aug 2010)
Log Message:
-----------
COMMON: Fix eos handling in BufferedReadStream
This makes it pass the test added in r52382.
Modified Paths:
--------------
scummvm/trunk/common/stream.cpp
scummvm/trunk/common/stream.h
Modified: scummvm/trunk/common/stream.cpp
===================================================================
--- scummvm/trunk/common/stream.cpp 2010-08-25 13:31:14 UTC (rev 52388)
+++ scummvm/trunk/common/stream.cpp 2010-08-25 14:43:42 UTC (rev 52389)
@@ -256,7 +256,6 @@
// Check whether the data left in the buffer suffices....
if (dataSize > bufBytesLeft) {
// Nope, we need to read more data
- _eos = true; // we tried to read past the buffer
// First, flush the buffer, if it is non-empty
if (0 < bufBytesLeft) {
@@ -269,8 +268,12 @@
// At this point the buffer is empty. Now if the read request
// exceeds the buffer size, just satisfy it directly.
- if (dataSize > _realBufSize)
- return alreadyRead + _parentStream->read(dataPtr, dataSize);
+ if (dataSize > _realBufSize) {
+ uint32 n = _parentStream->read(dataPtr, dataSize);
+ if (_parentStream->eos())
+ _eos = true;
+ return alreadyRead + n;
+ }
// Refill the buffer.
// If we didn't read as many bytes as requested, the reason
@@ -279,10 +282,12 @@
// return to the caller.
_bufSize = _parentStream->read(_buf, _realBufSize);
_pos = 0;
- if (_bufSize)
- _eos = false; // we've managed to replenish our buffer
- if (dataSize > _bufSize)
+ if (_bufSize < dataSize) {
+ // we didn't get enough data from parent
+ if (_parentStream->eos())
+ _eos = true;
dataSize = _bufSize;
+ }
}
if (dataSize) {
@@ -307,10 +312,12 @@
if (whence == SEEK_CUR && (int)_pos + offset >= 0 && _pos + offset <= _bufSize) {
_pos += offset;
-
+
+ // Note: we do not need to reset parent's eos flag here. It is
+ // sufficient that it is reset when actually seeking in the parent.
} else {
// Seek was not local enough, so we reset the buffer and
- // just seeks normally in the parent stream.
+ // just seek normally in the parent stream.
if (whence == SEEK_CUR)
offset -= (_bufSize - _pos);
_pos = _bufSize;
Modified: scummvm/trunk/common/stream.h
===================================================================
--- scummvm/trunk/common/stream.h 2010-08-25 13:31:14 UTC (rev 52388)
+++ scummvm/trunk/common/stream.h 2010-08-25 14:43:42 UTC (rev 52389)
@@ -494,7 +494,7 @@
DisposeAfterUse::Flag _disposeParentStream;
byte *_buf;
uint32 _pos;
- bool _eos; // in this context it means: have we tried to read beyond the end of the buffer
+ bool _eos; // end of stream
uint32 _bufSize;
uint32 _realBufSize;
virtual void allocBuf(uint32 bufSize); // virtual functions to allocate/deallocate the buffer
@@ -504,9 +504,9 @@
BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
virtual ~BufferedReadStream();
- virtual bool eos() const { return _eos && _parentStream->eos(); }
+ virtual bool eos() const { return _eos; }
virtual bool err() const { return _parentStream->err(); }
- virtual void clearErr() { _parentStream->clearErr(); }
+ virtual void clearErr() { _eos = false; _parentStream->clearErr(); }
virtual uint32 read(void *dataPtr, uint32 dataSize);
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list