Skip to content

Commit

Permalink
Couple soft reset and reset start message
Browse files Browse the repository at this point in the history
Into a single operation when adding them to the history in the server
when starting a streamed reset, instead of doing two size checks and
emitting the new messages signal twice.
  • Loading branch information
askmeaboutlo0m committed Aug 30, 2024
1 parent e44cc40 commit 7059950
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/libserver/sessionhistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ bool SessionHistory::addMessage(const net::Message &msg)
size_t bytes = msg.length();
if(hasRegularSpaceFor(bytes)) {
addMessageInternal(msg, bytes);
emit newMessagesAvailable();
return true;
} else {
return false;
Expand All @@ -101,6 +102,7 @@ bool SessionHistory::addEmergencyMessage(const net::Message &msg)
uint bytes = uint(msg.length());
if(hasEmergencySpaceFor(bytes)) {
addMessageInternal(msg, bytes);
emit newMessagesAvailable();
return true;
} else {
return false;
Expand All @@ -112,7 +114,6 @@ void SessionHistory::addMessageInternal(const net::Message &msg, size_t bytes)
m_sizeInBytes += bytes;
++m_lastIndex;
historyAdd(msg);
emit newMessagesAvailable();
}

bool SessionHistory::reset(const net::MessageList &newHistory)
Expand Down Expand Up @@ -143,12 +144,18 @@ StreamResetStartResult SessionHistory::startStreamedReset(
return StreamResetStartResult::AlreadyActive;
}

if(!addMessage(net::makeSoftResetMessage(0)) ||
!addMessage(
net::ServerReply::makeStreamedResetStart(ctxId, correlator))) {
net::Message softResetMsg = net::makeSoftResetMessage(0);
net::Message resetStartMsg =
net::ServerReply::makeStreamedResetStart(ctxId, correlator);
size_t softResetBytes = softResetMsg.length();
size_t resetStartBytes = resetStartMsg.length();
if(!hasRegularSpaceFor(softResetBytes + resetStartBytes)) {
return StreamResetStartResult::OutOfSpace;
}

addMessageInternal(softResetMsg, softResetBytes);
addMessageInternal(resetStartMsg, resetStartBytes);

StreamResetStartResult result = openResetStream(serverSideStateMessages);
if(result == StreamResetStartResult::Ok) {
m_resetStreamState = ResetStreamState::Streaming;
Expand All @@ -158,6 +165,7 @@ StreamResetStartResult SessionHistory::startStreamedReset(
m_resetStreamMessageCount = 0;
}

emit newMessagesAvailable();
return result;
}

Expand Down

0 comments on commit 7059950

Please sign in to comment.