diff options
Diffstat (limited to 'Swiften/StreamManagement/StanzaAckRequester.cpp')
-rw-r--r-- | Swiften/StreamManagement/StanzaAckRequester.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Swiften/StreamManagement/StanzaAckRequester.cpp b/Swiften/StreamManagement/StanzaAckRequester.cpp new file mode 100644 index 0000000..b007675 --- /dev/null +++ b/Swiften/StreamManagement/StanzaAckRequester.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/StreamManagement/StanzaAckRequester.h" + +#include <boost/numeric/conversion/cast.hpp> + +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(boost::shared_ptr<Stanza> stanza) { + unackedStanzas.push_back(stanza); + onRequestAck(); +} + +void StanzaAckRequester::handleAckReceived(unsigned int handledStanzasCount) { + unsigned int i = lastHandledStanzasCount; + while (i != handledStanzasCount) { + if (unackedStanzas.size() == 0) { + std::cerr << "Warning: Server acked more stanzas than we sent" << std::endl; + break; + } + boost::shared_ptr<Stanza> ackedStanza = unackedStanzas.front(); + unackedStanzas.pop_front(); + onStanzaAcked(ackedStanza); + i = (i == MAX_HANDLED_STANZA_COUNT ? 0 : i + 1); + } + lastHandledStanzasCount = handledStanzasCount; +} + +} |