blob: 8941f4a79d1fd94eea876bb76bbd94e2caee90ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/StreamManagement/StanzaAckRequester.h>
#include <boost/numeric/conversion/cast.hpp>
#include <Swiften/Base/Log.h>
#include <Swiften/Elements/Message.h>
namespace Swift {
static const unsigned int MAX_HANDLED_STANZA_COUNT = boost::numeric_cast<unsigned int>((1ULL<<32) - 1);
StanzaAckRequester::StanzaAckRequester() : lastHandledStanzasCount(0) {
}
void StanzaAckRequester::handleStanzaSent(std::shared_ptr<Stanza> stanza) {
unackedStanzas.push_back(stanza);
if (std::dynamic_pointer_cast<Message>(stanza)) {
onRequestAck();
}
}
void StanzaAckRequester::handleAckReceived(unsigned int handledStanzasCount) {
unsigned int i = lastHandledStanzasCount;
while (i != handledStanzasCount) {
if (unackedStanzas.empty()) {
SWIFT_LOG(warning) << "Server acked more stanzas than we sent" << std::endl;
break;
}
std::shared_ptr<Stanza> ackedStanza = unackedStanzas.front();
unackedStanzas.pop_front();
onStanzaAcked(ackedStanza);
i = (i == MAX_HANDLED_STANZA_COUNT ? 0 : i + 1);
}
lastHandledStanzasCount = handledStanzasCount;
}
}
|