Fix for message upload stats.

This commit is contained in:
Andrzej Kapolka 2014-12-05 15:02:35 -08:00
parent a3fbaab957
commit 08373f8b1e
2 changed files with 23 additions and 9 deletions

View file

@ -707,8 +707,9 @@ void ReliableChannel::endMessage() {
quint32 length = _buffer.pos() - _messageLengthPlaceholder; quint32 length = _buffer.pos() - _messageLengthPlaceholder;
_buffer.writeBytes(_messageLengthPlaceholder, sizeof(quint32), (const char*)&length); _buffer.writeBytes(_messageLengthPlaceholder, sizeof(quint32), (const char*)&length);
_messageReceivedOffset = getBytesWritten();
_messageSize = length; pruneOutgoingMessageStats();
_outgoingMessageStats.append(OffsetSizePair(getBytesWritten(), length));
} }
void ReliableChannel::sendMessage(const QVariant& message) { void ReliableChannel::sendMessage(const QVariant& message) {
@ -717,12 +718,14 @@ void ReliableChannel::sendMessage(const QVariant& message) {
endMessage(); endMessage();
} }
bool ReliableChannel::getMessageSendProgress(int& sent, int& total) const { bool ReliableChannel::getMessageSendProgress(int& sent, int& total) {
if (!_messagesEnabled || _offset >= _messageReceivedOffset) { pruneOutgoingMessageStats();
if (!_messagesEnabled || _outgoingMessageStats.isEmpty()) {
return false; return false;
} }
sent = qMax(0, _messageSize - (_messageReceivedOffset - _offset)); const OffsetSizePair& stat = _outgoingMessageStats.first();
total = _messageSize; sent = qMax(0, stat.second - (stat.first - _offset));
total = stat.second;
return true; return true;
} }
@ -762,8 +765,7 @@ ReliableChannel::ReliableChannel(DatagramSequencer* sequencer, int index, bool o
_offset(0), _offset(0),
_writePosition(0), _writePosition(0),
_writePositionResetPacketNumber(0), _writePositionResetPacketNumber(0),
_messagesEnabled(true), _messagesEnabled(true) {
_messageReceivedOffset(0) {
_buffer.open(output ? QIODevice::WriteOnly : QIODevice::ReadOnly); _buffer.open(output ? QIODevice::WriteOnly : QIODevice::ReadOnly);
_dataStream.setByteOrder(QDataStream::LittleEndian); _dataStream.setByteOrder(QDataStream::LittleEndian);
@ -934,3 +936,9 @@ void ReliableChannel::readData(QDataStream& in) {
} }
} }
void ReliableChannel::pruneOutgoingMessageStats() {
while (!_outgoingMessageStats.isEmpty() && _offset >= _outgoingMessageStats.first().first) {
_outgoingMessageStats.removeFirst();
}
}

View file

@ -384,7 +384,7 @@ public:
/// Determines the number of bytes uploaded towards the currently pending message. /// Determines the number of bytes uploaded towards the currently pending message.
/// \return true if there is a message pending, in which case the sent and total arguments will be set /// \return true if there is a message pending, in which case the sent and total arguments will be set
bool getMessageSendProgress(int& sent, int& total) const; bool getMessageSendProgress(int& sent, int& total);
/// Determines the number of bytes downloaded towards the currently pending message. /// Determines the number of bytes downloaded towards the currently pending message.
/// \return true if there is a message pending, in which case the received and total arguments will be set /// \return true if there is a message pending, in which case the received and total arguments will be set
@ -416,6 +416,8 @@ private:
void readData(QDataStream& in); void readData(QDataStream& in);
void pruneOutgoingMessageStats();
int _index; int _index;
bool _output; bool _output;
CircularBuffer _buffer; CircularBuffer _buffer;
@ -430,6 +432,10 @@ private:
SpanList _acknowledged; SpanList _acknowledged;
bool _messagesEnabled; bool _messagesEnabled;
int _messageLengthPlaceholder; ///< the location in the buffer of the message length for the current message int _messageLengthPlaceholder; ///< the location in the buffer of the message length for the current message
typedef QPair<int, int> OffsetSizePair;
QVector<OffsetSizePair> _outgoingMessageStats;
int _messageReceivedOffset; ///< when reached, indicates that the most recent sent message has been received int _messageReceivedOffset; ///< when reached, indicates that the most recent sent message has been received
int _messageSize; ///< the size of the most recent sent message; only valid when _messageReceivedOffset has been set int _messageSize; ///< the size of the most recent sent message; only valid when _messageReceivedOffset has been set
}; };