summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sapsocket.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/sapsocket.cc b/sapsocket.cc
index 25e956f..cc6ea2e 100644
--- a/sapsocket.cc
+++ b/sapsocket.cc
@@ -102,7 +102,7 @@ void SAPSocket::acceptIncomingData(const QByteArray &data)
<< "(expected " << expectedSeqNum << ")";
} else {
_inLastSeqNum = frame.seqNum;
- qDebug() << _sessionId << "Got seqNum" << frame.seqNum;
+ qDebug() << _sessionId << "Got seqNum" << frame.seqNum << " size=" << data.size();
if (!_ackTimer.isActive()) {
_ackTimer.start(DELAYED_ACK_TIME, Qt::CoarseTimer, this);
@@ -142,6 +142,7 @@ int SAPSocket::sessionId() const
void SAPSocket::timerEvent(QTimerEvent *event)
{
if (event->timerId() == _ackTimer.timerId()) {
+ qDebug() << "Ack timer tick";
if (_inLastSeqNum != _inLastAck) {
sendBlockAck(_inLastSeqNum);
@@ -149,6 +150,7 @@ void SAPSocket::timerEvent(QTimerEvent *event)
}
_ackTimer.stop();
} else if (event->timerId() == _resendTimer.timerId()) {
+ qDebug() << "Resend timer tick";
if (!_out.isEmpty()) {
_outFlyingPkts = 0; // Assume everything went wrong
sendPacketsFromQueue();
@@ -211,6 +213,8 @@ void SAPSocket::handleBlockAck(int seqNum)
qDebug() << _sessionId << "pending" << _out.size() << " flying" << _outFlyingPkts;
+ Q_ASSERT(_outFlyingPkts <= _out.size());
+
if (_outFlyingPkts == 0 || _out.size() == 0) {
qDebug() << _sessionId << "Stopping resend timer";
_resendTimer.stop();
@@ -221,9 +225,11 @@ void SAPSocket::handleBlockAck(int seqNum)
void SAPSocket::sendPacketsFromQueue()
{
- const int n = qMin(WINDOW_SIZE_MSGS - _outFlyingPkts, _out.size());
+ const int n = qMin(WINDOW_SIZE_MSGS, _out.size()) - _outFlyingPkts;
+
+ Q_ASSERT(n >= 0);
- for (int i = 0; i < n; i++) {
+ for (int i = _outFlyingPkts; i < _outFlyingPkts + n; i++) {
int seqNum = _outLastAck + i + 1;
const QByteArray &pkt = _out.at(i);
qDebug() << _sessionId << "Sending packet" << seqNum << "size=" << pkt.size();
@@ -232,6 +238,8 @@ void SAPSocket::sendPacketsFromQueue()
_outFlyingPkts += n;
+ Q_ASSERT(_outFlyingPkts <= _out.size());
+
qDebug() << _sessionId << "pending" << _out.size() << " flying" << _outFlyingPkts << " n" << n;
if (n > 0 && !_resendTimer.isActive()) {