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; String message;
StreamReadContext src; 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)); upq.Enqueue(boost::bind(&DynamicObject::RestoreObject, message, attributeTypes));
restored++; restored++;
} }

View File

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

View File

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