feat: Implemented requeueing of packets to busy tasks

This commit is contained in:
2026-06-30 12:00:11 +01:00
parent a5f79f5eac
commit 7edc2e21da
2 changed files with 36 additions and 18 deletions

View File

@@ -20,6 +20,8 @@
#define INCPHUB_EAGAIN (5)
/// @brief Could not allocate memory
#define INCPHUB_ENOMEM (6)
/// @brief Packet failed integrity checks
#define INCPHUB_BAD_PACKET (7)
typedef struct {
nil_addr_t addr;

View File

@@ -38,8 +38,8 @@ static StaticQueue_t _ingest_queue_static;
// === Private functions ===
static nil_packet_t *extract_nil_packet(uint8_t *buffer, size_t length);
static ntl_packet_t *extract_ntl_packet(nil_packet_t *nil);
static void handle_nil_packet(nil_packet_t *nil);
static void handle_ntl_packet(nil_packet_t *nil, ntl_packet_t *ntl);
static int handle_nil_packet(nil_packet_t *nil);
static int handle_ntl_packet(nil_packet_t *nil, ntl_packet_t *ntl);
@@ -54,6 +54,7 @@ void incphub_task_preinit()
void incphub_task_main(void *params)
{
(void)params;
int err;
while (1)
{
@@ -70,7 +71,27 @@ void incphub_task_main(void *params)
}
// Process or route
handle_nil_packet(nil);
err = handle_nil_packet(nil);
if (err == INCPHUB_EAGAIN)
{
// Failed but only temporarily
// Could be target task not ready
// Attempt requeue to allow retries
enqueue_message_ingest(buffer, 0);
// If failed to requeue (no space), discard message
// This avoids clogging the system due to a single unresponsive task
continue;
}
else if (err != INCPHUB_OK)
{
// Failed for some other reason
// Do not retry
continue;
}
// Successfully processed, no need to retry by requeueing
dequeue_message_ingest(&buffer, portMAX_DELAY);
}
}
@@ -117,7 +138,7 @@ static ntl_packet_t *extract_ntl_packet(nil_packet_t *nil)
return ntl;
}
static void handle_nil_packet(nil_packet_t *nil)
static int handle_nil_packet(nil_packet_t *nil)
{
if (nil->header.dst_addr == INCPHUB_LOCAL_NIL_ADDR)
{
@@ -125,33 +146,28 @@ static void handle_nil_packet(nil_packet_t *nil)
if (ntl == NULL)
{
//TODO: Error
return;
return INCPHUB_BAD_PACKET;
}
handle_ntl_packet(nil, ntl);
return;
return handle_ntl_packet(nil, ntl);
}
//TODO: Route to external interface
return;
return INCPHUB_ERR;
}
static void handle_ntl_packet(nil_packet_t *nil, ntl_packet_t *ntl)
static int handle_ntl_packet(nil_packet_t *nil, ntl_packet_t *ntl)
{
int err;
ntl_port_t port = ntl_get_dst(&ntl->header);
incphub_cli_t *client;
if (get_client_with_port(port, &client) != INCPHUB_OK)
err = get_client_with_port(port, &client);
if (err != INCPHUB_OK)
{
//TODO: Error
return;
return err;
}
if (do_message_dispatch(client, (uint8_t*)nil) != INCPHUB_OK)
{
//TODO: Error
return;
}
return;
return do_message_dispatch(client, (uint8_t*)nil);
}