From 8c3eca658c35d4341a2ecf96511c6caf64d7ecc8 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sun, 22 Sep 2024 15:56:43 +0200 Subject: [PATCH] connection: do not send ACKs for empty packets --- impl/src/layer2/connection.c | 8 ++++---- impl/src/layer2/connection.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/impl/src/layer2/connection.c b/impl/src/layer2/connection.c index 3464eed..afa371e 100644 --- a/impl/src/layer2/connection.c +++ b/impl/src/layer2/connection.c @@ -115,7 +115,7 @@ result_t connection_handle_packet(connection_ctx_t *ctx, const uint8_t *buf, siz case L2_MSG_TYPE_EMPTY: LOG(LVL_DEBUG, "Empty packet: accepted ACK for %u.", ctx->last_acked_seq); // handle the acknowledgement internally - connection_handle_ack(ctx, header.rx_seq_nr); + connection_handle_ack(ctx, header.rx_seq_nr, false); return OK; // do not ACK and call back case L2_MSG_TYPE_CONN_MGMT: @@ -142,7 +142,7 @@ result_t connection_handle_packet(connection_ctx_t *ctx, const uint8_t *buf, siz LOG(LVL_INFO, "Received ACK for seq_nr %u in packet seq_nr %u.", header.rx_seq_nr, header.tx_seq_nr); // handle the acknowledgement internally - connection_handle_ack(ctx, header.rx_seq_nr); + connection_handle_ack(ctx, header.rx_seq_nr, true); size_t header_size = layer2_get_encoded_header_size(&header); @@ -332,7 +332,7 @@ void connection_tx_clean_empty_packet(connection_ctx_t *ctx) } -void connection_handle_ack(connection_ctx_t *ctx, uint8_t acked_seq) +void connection_handle_ack(connection_ctx_t *ctx, uint8_t acked_seq, bool do_ack) { // check the connection state switch(ctx->conn_state) { @@ -369,7 +369,7 @@ void connection_handle_ack(connection_ctx_t *ctx, uint8_t acked_seq) LOG(LVL_DEBUG, "handling ack for seq_nr %u, removing %zu packets, %zu packets remaining.", acked_seq, packets_to_remove, packets_available); - if(packets_available == 0) { + if(do_ack && packets_available == 0) { // no packets left in queue, but an acknowledgement must be // transmitted. Add an empty packet to do that. result_t res = connection_add_empty_packet(ctx, false); diff --git a/impl/src/layer2/connection.h b/impl/src/layer2/connection.h index a10e627..0d7669f 100644 --- a/impl/src/layer2/connection.h +++ b/impl/src/layer2/connection.h @@ -123,7 +123,7 @@ void connection_tx_clean_empty_packet(connection_ctx_t *ctx); * \param acked_seq The acknowledged (= next expected) sequence number. * \param do_ack Whether an empty packet shall be generated if the queue is empty. */ -void connection_handle_ack(connection_ctx_t *ctx, uint8_t acked_seq); +void connection_handle_ack(connection_ctx_t *ctx, uint8_t acked_seq, bool do_ack); /*!\brief Check if there are packets queued for transmission. */