mirror of https://github.com/Icinga/icinga2.git
Fix a case where NetString::ReadStringFromStream might incorrectly return StatusEof
refs #6109
This commit is contained in:
parent
9e936cbea4
commit
1c7a0d03a1
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue