diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-06-25 12:44:12 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-06-30 20:15:36 -0400 |
commit | c957e4ba86e43147d717b7bf9901c8cc6a6cf87f (patch) | |
tree | cafc55f75c57c6783c831d48b5e88a30620becf4 | |
parent | c8dca0a56cc9be84c43b6e16266411196f51656c (diff) | |
download | kutter-c957e4ba86e43147d717b7bf9901c8cc6a6cf87f.tar.gz kutter-c957e4ba86e43147d717b7bf9901c8cc6a6cf87f.tar.xz kutter-c957e4ba86e43147d717b7bf9901c8cc6a6cf87f.zip |
serialqueue: Clarify code that associates sent messages to received messages
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | klippy/serialqueue.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/klippy/serialqueue.c b/klippy/serialqueue.c index cb24d523..0810c717 100644 --- a/klippy/serialqueue.c +++ b/klippy/serialqueue.c @@ -427,19 +427,26 @@ static void update_receive_seq(struct serialqueue *sq, double eventtime, uint64_t rseq) { // Remove from sent queue - int ack_count = rseq - sq->receive_seq; uint64_t sent_seq = sq->receive_seq; - while (!list_empty(&sq->sent_queue) && ack_count--) { + for (;;) { struct queue_message *sent = list_first_entry( &sq->sent_queue, struct queue_message, node); - if (rseq == ++sent_seq) - sq->last_receive_sent_time = sent->receive_time; + if (list_empty(&sq->sent_queue)) { + // Got an ack for a message not sent; must be connection init + sq->send_seq = rseq; + sq->last_receive_sent_time = 0.; + break; + } list_del(&sent->node); debug_queue_add(&sq->old_sent, sent); + sent_seq++; + if (rseq == sent_seq) { + // Found sent message corresponding with the received sequence + sq->last_receive_sent_time = sent->receive_time; + break; + } } sq->receive_seq = rseq; - if (rseq > sq->send_seq) - sq->send_seq = rseq; pollreactor_update_timer(&sq->pr, SQPT_COMMAND, PR_NOW); // Update retransmit info |