Skip to content

Commit

Permalink
feat: add local lazy query timeout check
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Oct 24, 2024
1 parent e205682 commit 33034ae
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/transport/unicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "zenoh-pico/transport/unicast/lease.h"

#include "zenoh-pico/session/utils.h"
#include "zenoh-pico/transport/unicast/transport.h"
#include "zenoh-pico/transport/unicast/tx.h"
#include "zenoh-pico/utils/logging.h"
Expand All @@ -38,6 +39,28 @@ z_result_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) {

#if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1

bool _z_pending_query_timeout(const _z_pending_query_t *foo, const _z_pending_query_t *pq) {
_ZP_UNUSED(foo);
bool result = z_clock_elapsed_ms((z_clock_t *)&pq->_start_time) >= pq->_timeout;
if (result) {
_Z_INFO("Dropping query because of timeout");
}
return result;
}

static void _z_process_query_timeout(_z_transport_unicast_t *ztu) {
#if Z_FEATURE_QUERY == 1
_z_session_t *zn = _Z_RC_IN_VAL(ztu->_session);
_z_session_mutex_lock(zn);
// Drop all queries with timeout elapsed
zn->_pending_queries = _z_pending_query_list_drop_filter(zn->_pending_queries, _z_pending_query_timeout, NULL);
_z_session_mutex_unlock(zn);
#else
_ZP_UNUSED(ztu);
return;
#endif
}

void *_zp_unicast_lease_task(void *ztu_arg) {
_z_transport_unicast_t *ztu = (_z_transport_unicast_t *)ztu_arg;

Expand Down Expand Up @@ -66,14 +89,15 @@ void *_zp_unicast_lease_task(void *ztu_arg) {
// Check if need to send a keep alive
if (ztu->_transmitted == false) {
if (_zp_unicast_send_keep_alive(ztu) < 0) {
// TODO: Handle retransmission or error
_Z_INFO("Send keep alive failed.");
}
}

// Reset the keep alive parameters
ztu->_transmitted = false;
next_keep_alive = (int)(ztu->_lease / Z_TRANSPORT_LEASE_EXPIRE_FACTOR);
}
// Query timeout process
_z_process_query_timeout(ztu);

// Compute the target interval
int interval;
Expand Down

0 comments on commit 33034ae

Please sign in to comment.