Add name parameter to uasync_set_timeout for timer identification in dumps
This commit is contained in:
1 parent
d413412f55
commit
170f079485
28 files changed
+102
-93
No files matched your search
+20
-12
@@ -32,6 +32,7 @@
|
||||
|
||||
// Timeout node with safe cancellation
|
||||
struct timeout_node {
|
||||
char name[16];
|
||||
void* arg;
|
||||
timeout_callback_t callback;
|
||||
uint64_t expiration_ms; // absolute expiration time in milliseconds
|
||||
@@ -491,22 +492,28 @@ static void get_next_timeout(struct UASYNC* ua, struct timeval* tv) {
|
||||
|
||||
|
||||
|
||||
// Instance version
|
||||
void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* arg, timeout_callback_t callback) {
|
||||
if (!ua || timeout_tb < 0 || !callback) return NULL;
|
||||
if (!ua->timeout_heap) return NULL;
|
||||
|
||||
// DEBUG_DEBUG(DEBUG_CATEGORY_TIMERS, "uasync_set_timeout: timeout=%d.%d ms, arg=%p, callback=%p", timeout_tb/10, timeout_tb%10, arg, callback);
|
||||
|
||||
// Instance version
|
||||
void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* arg, timeout_callback_t callback, const char* name) {
|
||||
if (!ua || timeout_tb < 0 || !callback) return NULL;
|
||||
if (!ua->timeout_heap) return NULL;
|
||||
|
||||
// DEBUG_DEBUG(DEBUG_CATEGORY_TIMERS, "uasync_set_timeout: timeout=%d.%d ms, arg=%p, callback=%p", timeout_tb/10, timeout_tb%10, arg, callback);
|
||||
|
||||
struct timeout_node* node = memory_pool_alloc(ua->timeout_pool);
|
||||
if (!node) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_TIMERS, "uasync_set_timeout: failed to allocate node");
|
||||
return NULL;
|
||||
}
|
||||
ua->timer_alloc_count++;
|
||||
|
||||
node->arg = arg;
|
||||
node->callback = callback;
|
||||
}
|
||||
ua->timer_alloc_count++;
|
||||
|
||||
if (name) {
|
||||
strncpy(node->name, name, sizeof(node->name) - 1);
|
||||
node->name[sizeof(node->name) - 1] = '\0';
|
||||
} else {
|
||||
node->name[0] = '\0';
|
||||
}
|
||||
node->arg = arg;
|
||||
node->callback = callback;
|
||||
node->ua = ua;
|
||||
|
||||
// Calculate expiration time in milliseconds
|
||||
@@ -538,6 +545,7 @@ void* uasync_call_soon(struct UASYNC* ua, void* user_arg, timeout_callback_t cal
|
||||
}
|
||||
ua->timer_alloc_count++;
|
||||
|
||||
node->name[0] = '\0';
|
||||
node->arg = user_arg;
|
||||
node->callback = callback;
|
||||
node->ua = ua;
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ void uasync_destroy(struct UASYNC* ua, int close_fds);
|
||||
uint64_t get_time_tb(void);
|
||||
|
||||
// Timeouts, timebase = 0.1 mS
|
||||
void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* user_arg, timeout_callback_t callback);
|
||||
void* uasync_set_timeout(struct UASYNC* ua, int timeout_tb, void* user_arg, timeout_callback_t callback, const char* name);
|
||||
err_t uasync_cancel_timeout(struct UASYNC* ua, void* t_id);
|
||||
|
||||
// Immediate execution in next mainloop (FIFO order)
|
||||
|
||||
@@ -376,7 +376,7 @@ static void socket_callback(int fd, void *user_arg) {
|
||||
u_free(packet);
|
||||
return;
|
||||
}
|
||||
uasync_set_timeout(ep->emulator->ua, delay_tb, packet, (timeout_callback_t)send_delayed_packet);
|
||||
uasync_set_timeout(ep->emulator->ua, delay_tb, packet, (timeout_callback_t)send_delayed_packet, "netem_delay");
|
||||
}
|
||||
|
||||
// Callback for sending delayed packet
|
||||
|
||||
+3
-3
@@ -158,7 +158,7 @@ static void dummynet_process_queue(struct dummynet* dn, int dir_idx) {
|
||||
if (sarg) {
|
||||
sarg->dn = dn;
|
||||
sarg->dir_idx = dir_idx;
|
||||
dir->shaper_timer = uasync_set_timeout(dn->ua, delay_tb, sarg, dummynet_shaper_callback);
|
||||
dir->shaper_timer = uasync_set_timeout(dn->ua, delay_tb, sarg, dummynet_shaper_callback, "dummynet_shaper");
|
||||
if (dir->shaper_timer) {
|
||||
dir->shaper_timer_set++;
|
||||
} else {
|
||||
@@ -270,7 +270,7 @@ static void dummynet_read_callback(socket_t sock, void* user_arg) {
|
||||
targ->dn = dn;
|
||||
targ->entry = entry;
|
||||
|
||||
void* timer = uasync_set_timeout(dn->ua, delay_tb, targ, dummynet_delay_callback);
|
||||
void* timer = uasync_set_timeout(dn->ua, delay_tb, targ, dummynet_delay_callback, "dummynet_delay");
|
||||
if (!timer) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_DUMMYNET, "Failed to set delay timer");
|
||||
dir->stats.dropped++;
|
||||
@@ -326,7 +326,7 @@ static void dummynet_delay_callback(void* user_arg) {
|
||||
if (sarg) {
|
||||
sarg->dn = dn;
|
||||
sarg->dir_idx = dir_idx;
|
||||
dir->shaper_timer = uasync_set_timeout(dn->ua, 0, sarg, dummynet_shaper_callback);
|
||||
dir->shaper_timer = uasync_set_timeout(dn->ua, 0, sarg, dummynet_shaper_callback, "dummynet_shaper0");
|
||||
} else {
|
||||
dir->shaper_pending = 0;
|
||||
}
|
||||
|
||||
+3
-3
@@ -606,7 +606,7 @@ static void ack_timeout_check(struct ETCP_CONN* etcp) {
|
||||
// shedule timer
|
||||
int64_t next_timeout=timeout - elapsed;
|
||||
if (next_timeout<0) next_timeout=0;
|
||||
etcp->retrans_timer = uasync_set_timeout(etcp->instance->ua, next_timeout+10, etcp, ack_timeout_cb);
|
||||
etcp->retrans_timer = uasync_set_timeout(etcp->instance->ua, next_timeout+10, etcp, ack_timeout_cb, "etcp_retrans");
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "[%s] retransmission timer set for %llu units", etcp->log_name, next_timeout);
|
||||
return;
|
||||
}
|
||||
@@ -670,7 +670,7 @@ static void ack_response_timer_cb(void* arg) {// проверяем неотпр
|
||||
if (etcp->ack_q->count==0) return;// нечего отправлять
|
||||
etcp_conn_process_send_queue(etcp);// проталкиваем (она же должна отправлять только ack если больше ничего нет)
|
||||
// если ack все еще заняты - обновляем таймаут
|
||||
if (etcp->ack_q->count) etcp->ack_resp_timer = uasync_set_timeout(etcp->instance->ua, ACK_DELAY_TB, etcp, ack_response_timer_cb);
|
||||
if (etcp->ack_q->count) etcp->ack_resp_timer = uasync_set_timeout(etcp->instance->ua, ACK_DELAY_TB, etcp, ack_response_timer_cb, "etcp_ack_resp");
|
||||
// else etcp->ack_resp_timer=NULL;
|
||||
}
|
||||
|
||||
@@ -1152,7 +1152,7 @@ void etcp_conn_input(struct ETCP_DGRAM* pkt) {
|
||||
|
||||
queue_data_put_with_index(etcp->ack_q, (struct ll_entry*)p, 0, 4);
|
||||
if (etcp->ack_resp_timer == NULL) {
|
||||
etcp->ack_resp_timer = uasync_set_timeout(etcp->instance->ua, ACK_DELAY_TB, etcp, ack_response_timer_cb);
|
||||
etcp->ack_resp_timer = uasync_set_timeout(etcp->instance->ua, ACK_DELAY_TB, etcp, ack_response_timer_cb, "etcp_ack_resp");
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_ETCP, "[%s] set ack_timer for delayed ACK send", etcp->log_name);
|
||||
}
|
||||
if (((int32_t)(etcp->last_delivered_id-seq)<0) && (queue_find_data_by_index(etcp->recv_q, &seq, 4)==NULL)) {// проверяем есть ли пакет с этим seq
|
||||
|
||||
@@ -144,7 +144,7 @@ static void etcp_link_init_timer_cbk(void* arg) {
|
||||
link->init_timeout += link->init_timeout/4 +1;
|
||||
if (link->init_timeout > INIT_TIMEOUT_MAX) link->init_timeout = INIT_TIMEOUT_MAX;
|
||||
}
|
||||
link->init_timer = uasync_set_timeout(link->etcp->instance->ua, link->init_timeout, link, etcp_link_init_timer_cbk);
|
||||
link->init_timer = uasync_set_timeout(link->etcp->instance->ua, link->init_timeout, link, etcp_link_init_timer_cbk, "link_init");
|
||||
|
||||
if (link->link_state == 1) etcp_link_send_init(link,1);// init (with etcp reset)
|
||||
else etcp_link_send_init(link,0);// no etcp reset (reinit)
|
||||
@@ -154,7 +154,7 @@ void etcp_link_restart_init_timer(struct ETCP_LINK* link) {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "");
|
||||
if (link->init_timer) uasync_cancel_timeout(link->etcp->instance->ua, link->init_timer);
|
||||
link->init_timeout = INIT_TIMEOUT_INITIAL;
|
||||
link->init_timer = uasync_set_timeout(link->etcp->instance->ua, link->init_timeout, link, etcp_link_init_timer_cbk);
|
||||
link->init_timer = uasync_set_timeout(link->etcp->instance->ua, link->init_timeout, link, etcp_link_init_timer_cbk, "link_init");
|
||||
}
|
||||
|
||||
void etcp_link_enter_init(struct ETCP_LINK* link) {//
|
||||
@@ -231,7 +231,7 @@ static void start_keepalive_timer(struct ETCP_LINK* link) {
|
||||
}
|
||||
|
||||
if (link->keepalive_timer == NULL) {
|
||||
link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->keepalive_interval * 10, link, keepalive_timer_cb);
|
||||
link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->keepalive_interval * 10, link, keepalive_timer_cb, "link_keepalive");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "[%s] Keepalive timer started on link %p (interval=%d ms)", link->etcp->log_name, link, link->keepalive_interval);
|
||||
}
|
||||
}
|
||||
@@ -286,7 +286,7 @@ static void keepalive_timer_cb(void* arg) {
|
||||
link->pkt_sent_since_keepalive = 0;
|
||||
|
||||
restart_timer:
|
||||
link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->keepalive_interval * 10, link, keepalive_timer_cb);
|
||||
link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->keepalive_interval * 10, link, keepalive_timer_cb, "link_keepalive");
|
||||
}
|
||||
|
||||
static uint32_t sockaddr_hash(struct sockaddr_storage* addr) {
|
||||
@@ -766,7 +766,8 @@ void start_stats_timer(struct ETCP_LINK* link) {
|
||||
link->etcp->instance->ua,
|
||||
tb,
|
||||
link,
|
||||
link_stats_timer_cb
|
||||
link_stats_timer_cb,
|
||||
"link_stats"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1039,7 +1040,7 @@ int etcp_send_ping_to_socket(struct UTUN_INSTANCE* instance, struct ETCP_SOCKET*
|
||||
while (last->next) last = last->next;
|
||||
last->next = ctx;
|
||||
}
|
||||
ctx->timeout_timer = uasync_set_timeout(instance->ua, timeout_ms * 10, ctx, ping_timeout_cbk);
|
||||
ctx->timeout_timer = uasync_set_timeout(instance->ua, timeout_ms * 10, ctx, ping_timeout_cbk, "ping_timeout");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "ping sent nonce=%016llx timeout=%d ulen=%zu",
|
||||
(unsigned long long)ctx->nonce, timeout_ms, user_data_len);
|
||||
return 0;
|
||||
|
||||
@@ -136,7 +136,7 @@ void etcp_loadbalancer_send(struct ETCP_DGRAM* dgram) {
|
||||
uint64_t now_tb=get_time_tb();
|
||||
if (link->shaper_load_time_tb >= now_tb + SHAPER_BURST_DELAY_TB) {
|
||||
uint64_t wait_tb = link->shaper_load_time_tb - now_tb;
|
||||
link->shaper_timer = uasync_set_timeout(link->etcp->instance->ua, wait_tb, link, shaper_timer_cb);
|
||||
link->shaper_timer = uasync_set_timeout(link->etcp->instance->ua, wait_tb, link, shaper_timer_cb, "shaper");
|
||||
if (link->shaper_timer == NULL) DEBUG_ERROR(DEBUG_CATEGORY_TIMERS, "Filed to allocate timer");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] scheduled shaper timer (wait_tb=%llu) BW=%d pkt_size=%d", etcp->log_name, (unsigned long long)wait_tb, link->bandwidth, pkt_size);
|
||||
}
|
||||
|
||||
+2
-2
@@ -117,7 +117,7 @@ int route_ping_send_req(struct ROUTE_BGP* bgp, struct ETCP_CONN* to_conn, uint64
|
||||
pending->next = bgp->ping_pending;
|
||||
bgp->ping_pending = pending;
|
||||
|
||||
pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout);
|
||||
pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout, "route_ping");
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "request_id=%016llx node=%016llx count=%u interval=%u timeout=%u wait=%u",
|
||||
(unsigned long long)pending->request_id, (unsigned long long)node_id,
|
||||
@@ -220,7 +220,7 @@ int route_ping_send_req_addr(struct ROUTE_BGP* bgp, struct ETCP_CONN* to_conn, u
|
||||
pending->next = bgp->ping_pending;
|
||||
bgp->ping_pending = pending;
|
||||
|
||||
pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout);
|
||||
pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout, "route_ping");
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "request_id=%016llx node=%016llx ip=%s port=%u pubkey=%s",
|
||||
(unsigned long long)pending->request_id, (unsigned long long)node_id,
|
||||
|
||||
+1
-1
@@ -258,7 +258,7 @@ static void signal_handler(int sig) {
|
||||
|
||||
void test_tmr(void* arg) {
|
||||
struct UASYNC* ua = (struct UASYNC*)arg;
|
||||
uasync_set_timeout(ua, 10000, ua, test_tmr);
|
||||
uasync_set_timeout(ua, 10000, ua, test_tmr, "utun_test");
|
||||
// DEBUG_INFO(DEBUG_CATEGORY_ETCP, "tick ...");
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ static void benchmark_without_sockets(void) {
|
||||
// Set 100 zero timeouts
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < NUM_TIMEOUTS; i++) {
|
||||
timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback);
|
||||
timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback, "bench0");
|
||||
if (!timeout_ids[i]) {
|
||||
fprintf(stderr, "Failed to set timeout at iteration %d\n", i);
|
||||
uasync_destroy(ua, 0);
|
||||
@@ -147,7 +147,7 @@ static void benchmark_with_sockets(void) {
|
||||
// Set 100 zero timeouts WITH sockets already open
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < NUM_TIMEOUTS; i++) {
|
||||
timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback);
|
||||
timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback, "bench0");
|
||||
if (!timeout_ids[i]) {
|
||||
fprintf(stderr, "Failed to set timeout at iteration %d\n", i);
|
||||
for (int j = 0; j < NUM_SOCKETS; j++) {
|
||||
@@ -215,7 +215,7 @@ int main(void) {
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < NUM_TIMEOUTS; i++) {
|
||||
timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback);
|
||||
timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback, "bench0");
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
set_time_no_sockets = measure_time_diff(&start, &end);
|
||||
@@ -266,7 +266,7 @@ int main(void) {
|
||||
// Set timeouts WITH sockets open
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < NUM_TIMEOUTS; i++) {
|
||||
timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback);
|
||||
timeout_ids[i] = uasync_set_timeout(ua, 0, (void*)(uintptr_t)(i + 1), timeout_callback, "bench0");
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
set_time_with_sockets = measure_time_diff(&start, &end);
|
||||
|
||||
@@ -102,9 +102,9 @@ static void test_basic_timers(void) {
|
||||
ctx.timeout_ms = 10; // Non-zero to avoid immediate timeout counting
|
||||
|
||||
/* Set multiple timers with different timeouts */
|
||||
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback); /* 2ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback); /* 3ms */
|
||||
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback, "test_t1"); /* 1ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback, "test_t2"); /* 2ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback, "test_t3"); /* 3ms */
|
||||
|
||||
ASSERT_NOT_NULL(timer1, "Failed to set timer 1");
|
||||
ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
|
||||
@@ -136,9 +136,9 @@ static void test_timer_cancellation_races(void) {
|
||||
ctx.timeout_ms = 5; // Non-zero to avoid immediate timeout counting
|
||||
|
||||
/* Create timers that will be cancelled at different stages */
|
||||
void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback); /* 0.5ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback); /* 5ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback); /* 10ms */
|
||||
void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback, "test_t1"); /* 0.5ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback, "test_t2"); /* 5ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback, "test_t3"); /* 10ms */
|
||||
|
||||
ASSERT_NOT_NULL(timer1, "Failed to set timer 1");
|
||||
ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
|
||||
@@ -192,7 +192,7 @@ static void test_immediate_timeouts(void) {
|
||||
|
||||
/* Set multiple immediate timeouts (0ms) */
|
||||
for (int i = 0; i < 5; i++) {
|
||||
void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback);
|
||||
void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback, "test_imm");
|
||||
ASSERT_NOT_NULL(timer, "Failed to set immediate timer");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ int main() {
|
||||
test_context_t ctx1 = {.timeout_ms = 10};
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
uasync_set_timeout(ua1, 10 + i*10, &ctx1, test_timer_callback);
|
||||
uasync_set_timeout(ua1, 10 + i*10, &ctx1, test_timer_callback, "test_d1");
|
||||
}
|
||||
|
||||
int polls = 0;
|
||||
@@ -55,7 +55,7 @@ int main() {
|
||||
test_context_t ctx2 = {.timeout_ms = 0};
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
uasync_set_timeout(ua2, 0, &ctx2, test_timer_callback);
|
||||
uasync_set_timeout(ua2, 0, &ctx2, test_timer_callback, "test_d2");
|
||||
}
|
||||
|
||||
printf("Before poll: ctx2.callback_count = %d, immediate_timeouts = %d\n", ctx2.callback_count, test_stats.immediate_timeouts);
|
||||
@@ -73,7 +73,7 @@ int main() {
|
||||
test_context_t ctx3 = {.timeout_ms = 0};
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
uasync_set_timeout(ua3, 0, &ctx3, test_timer_callback);
|
||||
uasync_set_timeout(ua3, 0, &ctx3, test_timer_callback, "test_d3");
|
||||
}
|
||||
|
||||
uasync_poll(ua3, 1);
|
||||
|
||||
@@ -284,7 +284,7 @@ static void monitor_connections(void* arg) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "=== Connection established! Waiting for BGP exchange... ===");
|
||||
test_phase = 1;
|
||||
// Schedule next check after BGP exchange time
|
||||
monitor_timeout_id = uasync_set_timeout(ua, BGP_EXCHANGE_WAIT_MS, NULL, monitor_connections);
|
||||
monitor_timeout_id = uasync_set_timeout(ua, BGP_EXCHANGE_WAIT_MS, NULL, monitor_connections, "test_monitor");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -317,7 +317,7 @@ static void monitor_connections(void* arg) {
|
||||
|
||||
// Schedule next check
|
||||
if (test_phase < 3) {
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections);
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections, "test_monitor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,8 +400,8 @@ int main() {
|
||||
|
||||
// Start monitoring
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Starting connection monitoring...");
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections);
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout);
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections, "test_monitor");
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
|
||||
|
||||
// Main event loop - use uasync timers only, no artificial timing
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Running event loop...");
|
||||
|
||||
@@ -114,7 +114,7 @@ static void send_timer_callback(void* arg) {
|
||||
st->next_seq++;
|
||||
|
||||
/* Перезапускаем таймер на следующую отправку (10 timebase = 1ms) */
|
||||
st->send_timer = uasync_set_timeout(st->ua, 10, st, send_timer_callback);
|
||||
st->send_timer = uasync_set_timeout(st->ua, 10, st, send_timer_callback, "test_dummynet");
|
||||
}
|
||||
|
||||
/* Burst отправка - все пакеты сразу */
|
||||
@@ -259,7 +259,7 @@ static int run_scenario(const char* name,
|
||||
printf("Sending %d packets (fast)...\n", PKT_COUNT);
|
||||
|
||||
/* Запускаем таймер отправки с интервалом 1 timebase (0.1ms) */
|
||||
st.send_timer = uasync_set_timeout(st.ua, 1, &st, send_timer_callback);
|
||||
st.send_timer = uasync_set_timeout(st.ua, 1, &st, send_timer_callback, "test_dummynet");
|
||||
|
||||
/* Умное ожидание завершения: ранний выход при готовности + watchdog */
|
||||
uint64_t start_time = get_time_us();
|
||||
|
||||
@@ -361,7 +361,7 @@ static void monitor_and_send(void* arg) {
|
||||
}
|
||||
|
||||
if (!test_completed) {
|
||||
packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send, "test_monitor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,8 +419,8 @@ int main() {
|
||||
printf("✅ Client ready\n\n");
|
||||
|
||||
printf("Sending %d packets in each direction (max queue size: %d)...\n", TOTAL_PACKETS, MAX_QUEUE_SIZE);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send);
|
||||
void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send, "test_monitor");
|
||||
void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
|
||||
|
||||
while (!test_completed) {
|
||||
uasync_poll(ua, 100);
|
||||
|
||||
@@ -437,7 +437,7 @@ static void monitor_and_send(void* arg) {
|
||||
connection_delay++;
|
||||
if (connection_delay < 50) { // Ждем 50 циклов (~500ms)
|
||||
if (!test_completed) {
|
||||
packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send, "test_monitor");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -506,7 +506,7 @@ static void monitor_and_send(void* arg) {
|
||||
}
|
||||
|
||||
if (!test_completed) {
|
||||
packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send, "test_monitor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,8 +586,8 @@ int main() {
|
||||
DATA_PACKET_ID, (void*)server_recv_callback, (void*)client_recv_callback);
|
||||
|
||||
printf("Sending %d packets in each direction via etcp_send...\n", TOTAL_PACKETS);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 1000, NULL, monitor_and_send);
|
||||
void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 1000, NULL, monitor_and_send, "test_monitor");
|
||||
void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout, "test_timeout");
|
||||
|
||||
while (!test_completed) {
|
||||
uasync_poll(ua, 100); // 100ms timeout to allow timer processing
|
||||
|
||||
@@ -94,7 +94,7 @@ static void send_pkt(void* arg) {
|
||||
|
||||
/* Schedule next packet with 5ms delay for rate limiting (~200 pkt/sec)
|
||||
* Note: uasync_set_timeout uses 0.1ms units, so 50 = 5ms */
|
||||
uasync_set_timeout(ua, 50, NULL, send_pkt);
|
||||
uasync_set_timeout(ua, 50, NULL, send_pkt, "test_dnet");
|
||||
}
|
||||
|
||||
static struct UTUN_INSTANCE* create_instance(struct UASYNC* u, uint64_t node_id,
|
||||
|
||||
@@ -169,8 +169,8 @@ int main(void) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Client init_connections failed with code %d", ret);
|
||||
goto cleanup;
|
||||
}
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections);
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout);
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections, "test_monitor");
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
|
||||
while (!test_completed) {
|
||||
uasync_poll(ua, 10);
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ static void monitor_and_send(void* arg) {
|
||||
|
||||
// Schedule next check
|
||||
if (!test_completed) {
|
||||
void* new_timeout = uasync_set_timeout(server_instance->ua, 100, NULL, monitor_and_send);
|
||||
void* new_timeout = uasync_set_timeout(server_instance->ua, 100, NULL, monitor_and_send, "test_monitor");
|
||||
if (!new_timeout) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "monitor_and_send: Failed to set timeout - uasync_set_timeout returned NULL");
|
||||
printf("[ERROR] Failed to set timeout in monitor_and_send\n");
|
||||
@@ -472,8 +472,8 @@ int main() {
|
||||
|
||||
// Start monitoring and packet transmission
|
||||
printf("Starting packet transmission test...\n");
|
||||
packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send);
|
||||
void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send, "test_monitor");
|
||||
void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
|
||||
|
||||
// Main event loop
|
||||
printf("Running event loop...\n\n");
|
||||
|
||||
@@ -231,7 +231,7 @@ static void monitor_connections(void* arg) {
|
||||
uasync_cancel_timeout(ua, monitor_timeout_id);
|
||||
monitor_timeout_id = NULL;
|
||||
}
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 200, NULL, monitor_connections);
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 200, NULL, monitor_connections, "test_monitor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,8 +341,8 @@ int main() {
|
||||
|
||||
// Start monitoring
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Starting connection monitoring...\n");
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections);
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout);
|
||||
monitor_timeout_id = uasync_set_timeout(ua, 100, NULL, monitor_connections, "test_monitor");
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
|
||||
|
||||
// Main event loop
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Running event loop...\n\n");
|
||||
|
||||
@@ -223,7 +223,7 @@ int main(void) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout_cb);
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout_cb, "test_nat");
|
||||
|
||||
// 1. Wait for links C1->S and C2->S to initialize
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Waiting for ETCP links to initialize...");
|
||||
|
||||
@@ -482,7 +482,7 @@ static void monitor_and_send(void* arg) {
|
||||
}
|
||||
|
||||
if (!test_completed) {
|
||||
packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 10, NULL, monitor_and_send, "test_monitor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,8 +550,8 @@ int main() {
|
||||
printf("Client created\n\n");
|
||||
|
||||
printf("Sending %d packets in each direction via normalizer...\n", TOTAL_PACKETS);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send);
|
||||
void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout);
|
||||
packet_timeout_id = uasync_set_timeout(ua, 500, NULL, monitor_and_send, "test_monitor");
|
||||
void* global_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS*10, NULL, test_timeout, "test_timeout");
|
||||
|
||||
while (!test_completed) {
|
||||
uasync_poll(ua, 100); // 100ms timeout to allow timer processing
|
||||
|
||||
@@ -159,7 +159,7 @@ static void monitor(void* arg) {
|
||||
}
|
||||
|
||||
// Schedule next check
|
||||
uasync_set_timeout(mock_instance.ua, 10, NULL, monitor);
|
||||
uasync_set_timeout(mock_instance.ua, 10, NULL, monitor, "test_monitor");
|
||||
}
|
||||
|
||||
// Timeout handler
|
||||
@@ -298,8 +298,8 @@ int main() {
|
||||
printf("Normalizer created (frag_size=%d)\n\n", pn->frag_size);
|
||||
|
||||
// Set up monitoring and timeout FIRST (before sending)
|
||||
uasync_set_timeout(mock_instance.ua, 10, NULL, monitor);
|
||||
uasync_set_timeout(mock_instance.ua, TEST_TIMEOUT_MS, NULL, test_timeout);
|
||||
uasync_set_timeout(mock_instance.ua, 10, NULL, monitor, "test_monitor");
|
||||
uasync_set_timeout(mock_instance.ua, TEST_TIMEOUT_MS, NULL, test_timeout, "test_timeout");
|
||||
|
||||
// Give uasync a chance to process any pending callbacks
|
||||
uasync_poll(mock_instance.ua, 1);
|
||||
|
||||
@@ -221,7 +221,7 @@ int main(void) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout_cb);
|
||||
test_timeout_id = uasync_set_timeout(ua, TEST_TIMEOUT_MS * 10, NULL, test_timeout_cb, "test_route_ping");
|
||||
|
||||
// 1. Wait for links A->B and B->C to initialize
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Waiting for ETCP links to initialize...");
|
||||
|
||||
@@ -105,7 +105,7 @@ static void check_mesh_state(void* arg) {
|
||||
return;
|
||||
}
|
||||
|
||||
timeout_id = uasync_set_timeout(ua, 500, NULL, check_mesh_state);
|
||||
timeout_id = uasync_set_timeout(ua, 500, NULL, check_mesh_state, "test_mesh");
|
||||
}
|
||||
|
||||
static void timeout_handler(void* arg) {
|
||||
|
||||
@@ -147,9 +147,9 @@ static void test_basic_timers(void) {
|
||||
ctx.expected_count = 3;
|
||||
|
||||
/* Set multiple timers with different timeouts */
|
||||
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback); /* 2ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback); /* 3ms */
|
||||
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback, "test_t1"); /* 1ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback, "test_t2"); /* 2ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback, "test_t3"); /* 3ms */
|
||||
|
||||
ASSERT_NOT_NULL(timer1, "Failed to set timer 1");
|
||||
ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
|
||||
@@ -181,9 +181,9 @@ static void test_timer_cancellation_races(void) {
|
||||
ctx.expected_count = 2;
|
||||
|
||||
/* Create timers that will be cancelled at different stages */
|
||||
void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback); /* 0.5ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback); /* 5ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback); /* 10ms */
|
||||
void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback, "test_t1"); /* 0.5ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback, "test_t2"); /* 5ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback, "test_t3"); /* 10ms */
|
||||
|
||||
ASSERT_NOT_NULL(timer1, "Failed to set timer 1");
|
||||
ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
|
||||
@@ -238,7 +238,7 @@ static void test_immediate_timeouts(void) {
|
||||
|
||||
/* Set multiple immediate timeouts (0ms) */
|
||||
for (int i = 0; i < 5; i++) {
|
||||
void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback);
|
||||
void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback, "test_imm");
|
||||
ASSERT_NOT_NULL(timer, "Failed to set immediate timer");
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ static void test_memory_leak_detection(void) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
test_context_t timer_ctx = {0};
|
||||
timer_ctx.timeout_ms = 100; // Set proper timeout to avoid immediate timeout
|
||||
void* timer = uasync_set_timeout(ua, 100, &timer_ctx, test_timer_callback);
|
||||
void* timer = uasync_set_timeout(ua, 100, &timer_ctx, test_timer_callback, "test_cancel");
|
||||
ASSERT_NOT_NULL(timer, "Failed to set timer");
|
||||
|
||||
/* Cancel some, leave others to timeout */
|
||||
@@ -350,7 +350,7 @@ static void test_error_handling(void) {
|
||||
ASSERT_NOT_NULL(ua, "Failed to create uasync instance");
|
||||
|
||||
/* Test invalid parameters */
|
||||
void* null_timer = uasync_set_timeout(NULL, 10, NULL, NULL);
|
||||
void* null_timer = uasync_set_timeout(NULL, 10, NULL, NULL, "test_null");
|
||||
ASSERT_NULL(null_timer, "Should fail with NULL uasync");
|
||||
|
||||
err_t cancel_result = uasync_cancel_timeout(NULL, NULL);
|
||||
@@ -364,7 +364,7 @@ static void test_error_handling(void) {
|
||||
test_context_t ctx = {0};
|
||||
ctx.callback_arg = -1; /* Error injection flag */
|
||||
|
||||
void* error_timer = uasync_set_timeout(ua, 5, &ctx, test_error_callback);
|
||||
void* error_timer = uasync_set_timeout(ua, 5, &ctx, test_error_callback, "test_err");
|
||||
ASSERT_NOT_NULL(error_timer, "Failed to set error timer");
|
||||
|
||||
uasync_poll(ua, 10);
|
||||
@@ -434,7 +434,7 @@ static void test_concurrent_operations(void) {
|
||||
individual_ctx->timeout_ms = (i + 1) * 5; // Different timeouts: 5, 10, 15, ..., 50ms
|
||||
individual_ctx->callback_arg = 0;
|
||||
|
||||
timers[i] = uasync_set_timeout(ua, (i + 1) * 5, individual_ctx, test_timer_callback);
|
||||
timers[i] = uasync_set_timeout(ua, (i + 1) * 5, individual_ctx, test_timer_callback, "test_stress");
|
||||
ASSERT_NOT_NULL(timers[i], "Failed to set timer");
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ static void timer_callback(void* arg) {
|
||||
new_ctx->stop_flag = ctx->stop_flag;
|
||||
new_ctx->ua = ctx->ua;
|
||||
|
||||
void* new_timer = uasync_set_timeout(ctx->ua, random_delay, new_ctx, timer_callback);
|
||||
void* new_timer = uasync_set_timeout(ctx->ua, random_delay, new_ctx, timer_callback, "test_timer");
|
||||
if (new_timer) {
|
||||
ctx->timer_data[ctx->timer_number].timer_id = new_timer;
|
||||
} else {
|
||||
@@ -122,7 +122,7 @@ int main(void) {
|
||||
ctx->ua = ua;
|
||||
|
||||
int random_delay = rand() % 101; /* 0-100 (0-10ms) */
|
||||
void* timer_id = uasync_set_timeout(ua, random_delay, ctx, timer_callback);
|
||||
void* timer_id = uasync_set_timeout(ua, random_delay, ctx, timer_callback, "test_timer");
|
||||
|
||||
if (!timer_id) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_TEST, "Failed to set timer %d", i);
|
||||
@@ -152,7 +152,7 @@ int main(void) {
|
||||
stop_ctx->stop_flag = &stop_flag;
|
||||
stop_ctx->ua = ua;
|
||||
|
||||
void* stop_timer = uasync_set_timeout(ua, STOP_TIMEOUT_TB, stop_ctx, stop_callback);
|
||||
void* stop_timer = uasync_set_timeout(ua, STOP_TIMEOUT_TB, stop_ctx, stop_callback, "test_stop");
|
||||
if (!stop_timer) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_TEST, "Failed to set stop timer");
|
||||
u_free(stop_ctx);
|
||||
|
||||
+4
-4
@@ -89,9 +89,9 @@ static void test_basic_timers(void) {
|
||||
ctx.timeout_ms = 10; // Non-zero timeout
|
||||
|
||||
/* Set multiple timers with different timeouts */
|
||||
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback); /* 2ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback); /* 3ms */
|
||||
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback, "test_t1"); /* 1ms */
|
||||
void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback, "test_t2"); /* 2ms */
|
||||
void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback, "test_t3"); /* 3ms */
|
||||
|
||||
ASSERT_NOT_NULL(timer1, "Failed to set timer 1");
|
||||
ASSERT_NOT_NULL(timer2, "Failed to set timer 2");
|
||||
@@ -124,7 +124,7 @@ static void test_immediate_timeouts(void) {
|
||||
|
||||
/* Set multiple immediate timeouts (0ms) */
|
||||
for (int i = 0; i < 5; i++) {
|
||||
void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback);
|
||||
void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback, "test_imm");
|
||||
ASSERT_NOT_NULL(timer, "Failed to set immediate timer");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user