@@ -669,17 +669,44 @@ connect_event_cb (struct bufferevent *bev, short what, void *ctx)
669
669
}
670
670
}
671
671
672
- static void
673
- keep_control_alive ()
672
+ static int init_ping_ticker (struct control * ctl ) {
673
+ if (!ctl || !ctl -> connect_base ) {
674
+ debug (LOG_ERR , "Invalid control structure or event base" );
675
+ return -1 ;
676
+ }
677
+
678
+ struct event * ticker = evtimer_new (ctl -> connect_base , hb_sender_cb , NULL );
679
+ if (!ticker ) {
680
+ debug (LOG_ERR , "Failed to create ping ticker event" );
681
+ return -1 ;
682
+ }
683
+
684
+ ctl -> ticker_ping = ticker ;
685
+ return 0 ;
686
+ }
687
+
688
+ static void keep_control_alive ()
674
689
{
675
- debug (LOG_DEBUG , "start keep_control_alive" );
676
- main_ctl -> ticker_ping = evtimer_new (main_ctl -> connect_base , hb_sender_cb , NULL );
677
- if ( !main_ctl -> ticker_ping ) {
678
- debug (LOG_ERR , "Ping Ticker init failed!" );
690
+ debug (LOG_DEBUG , "Initializing control keepalive" );
691
+
692
+ // Initialize ping ticker
693
+ if (init_ping_ticker (main_ctl ) != 0 ) {
694
+ debug (LOG_ERR , "Failed to initialize control keepalive" );
679
695
return ;
680
696
}
697
+
698
+ // Set initial pong time
681
699
pong_time = time (NULL );
700
+ if (pong_time == (time_t )- 1 ) {
701
+ debug (LOG_ERR , "Failed to get current time" );
702
+ event_free (main_ctl -> ticker_ping );
703
+ main_ctl -> ticker_ping = NULL ;
704
+ return ;
705
+ }
706
+
707
+ // Start ticker timer
682
708
set_ticker_ping_timer (main_ctl -> ticker_ping );
709
+ debug (LOG_DEBUG , "Control keepalive initialized successfully" );
683
710
}
684
711
685
712
static int init_server_connection (struct bufferevent * * bev_out ,
0 commit comments