Fix a case where NetString::ReadStringFromStream might incorrectly return StatusEof

refs #6109
This commit is contained in:
Gunnar Beutner 2015-02-14 18:48:33 +01:00
parent 9e936cbea4
commit 1c7a0d03a1
3 changed files with 22 additions and 5 deletions

View File

@ -315,7 +315,15 @@ void DynamicObject::RestoreObjects(const String& filename, int attributeTypes)
String message;
StreamReadContext src;
while (NetString::ReadStringFromStream(sfp, &message, src) == StatusNewItem) {
for (;;) {
StreamReadStatus srs = NetString::ReadStringFromStream(sfp, &message, src);
if (srs == StatusEof)
break;
if (srs != StatusNewItem)
continue;
upq.Enqueue(boost::bind(&DynamicObject::RestoreObject, message, attributeTypes));
restored++;
}

View File

@ -37,9 +37,13 @@ StreamReadStatus NetString::ReadStringFromStream(const Stream::Ptr& stream, Stri
if (context.Eof)
return StatusEof;
if (context.MustRead && !context.FillFromStream(stream)) {
context.Eof = true;
return StatusEof;
if (context.MustRead) {
if (!context.FillFromStream(stream)) {
context.Eof = true;
return StatusEof;
}
context.MustRead = false;
}
size_t header_length = 0;

View File

@ -691,9 +691,14 @@ void ApiListener::ReplayLog(const ApiClient::Ptr& client)
Dictionary::Ptr pmessage;
try {
if (NetString::ReadStringFromStream(logStream, &message, src) != StatusNewItem)
StreamReadStatus srs = NetString::ReadStringFromStream(logStream, &message, src);
if (srs == StatusEof)
break;
if (srs != StatusNewItem)
continue;
pmessage = JsonDecode(message);
} catch (const std::exception&) {
Log(LogWarning, "ApiListener")