mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 05:34:48 +02:00
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;
|
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++;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user