@ -29,6 +29,10 @@ static uint8_t test_packet_data[PACKET_SIZE];
static int packet_sent = 0 ;
static int packet_sent = 0 ;
static int packet_received = 0 ;
static int packet_received = 0 ;
// State variables for monitor_and_send (non-static to avoid issues with multiple test runs in same process)
static int connection_checked = 0 ;
static int packet_sent_flag = 0 ;
// Function to check if connection is established - UPDATED WITH DEBUG
// Function to check if connection is established - UPDATED WITH DEBUG
static int is_connection_established ( struct UTUN_INSTANCE * inst ) {
static int is_connection_established ( struct UTUN_INSTANCE * inst ) {
printf ( " [DEBUG] is_connection_established: Checking instance %p \n " , inst ) ;
printf ( " [DEBUG] is_connection_established: Checking instance %p \n " , inst ) ;
@ -198,9 +202,6 @@ static void monitor_and_send(void* arg) {
return ;
return ;
}
}
static int connection_checked = 0 ;
static int packet_sent_flag = 0 ;
// Check connection
// Check connection
if ( ! connection_checked ) {
if ( ! connection_checked ) {
int server_ready = is_connection_established ( server_instance ) ;
int server_ready = is_connection_established ( server_instance ) ;
@ -242,7 +243,13 @@ static void monitor_and_send(void* arg) {
// Schedule next check
// Schedule next check
if ( ! test_completed ) {
if ( ! test_completed ) {
packet_timeout_id = 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 ) ;
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 " ) ;
fflush ( stdout ) ;
}
packet_timeout_id = new_timeout ;
}
}
}
}
@ -387,10 +394,18 @@ int main() {
int elapsed = 0 ;
int elapsed = 0 ;
int poll_interval = 5 ;
int poll_interval = 5 ;
int check_counter = 0 ;
while ( ! test_completed & & elapsed < TEST_TIMEOUT_MS + 1000 ) {
while ( ! test_completed & & elapsed < TEST_TIMEOUT_MS + 1000 ) {
if ( ua ) uasync_poll ( ua , poll_interval ) ;
if ( ua ) uasync_poll ( ua , poll_interval ) ;
elapsed + = poll_interval ;
elapsed + = poll_interval ;
check_counter + + ;
// Check for received packet every 10 iterations (every 50ms)
// This ensures we check even if the timeout callback doesn't fire
if ( packet_sent & & ! packet_received & & ( check_counter % 10 = = 0 ) ) {
check_packet_received ( ) ;
}
// Quick exit if packet received
// Quick exit if packet received
if ( test_completed = = 1 ) {
if ( test_completed = = 1 ) {