@ -22,11 +22,13 @@
static int g_udp_fd = - 1 ;
static int g_udp_fd = - 1 ;
static struct sockaddr_in g_udp_addr ;
static struct sockaddr_in g_udp_addr ;
static int g_udp_has_addr = 0 ;
static int g_udp_has_addr = 0 ;
static int g_udp_stopping = 0 ;
static char g_udp_buf [ UDP_BUF_SIZE ] ;
static char g_udp_buf [ UDP_BUF_SIZE ] ;
static int g_udp_buf_len = 0 ;
static int g_udp_buf_len = 0 ;
static void * g_udp_timer = NULL ;
static void * g_udp_timer = NULL ;
static void udp_reschedule_timer ( void ) {
static void udp_reschedule_timer ( void ) {
if ( g_udp_stopping ) return ;
struct UASYNC * ua = instance_lite_get_uasync ( ) ;
struct UASYNC * ua = instance_lite_get_uasync ( ) ;
if ( ua ) g_udp_timer = uasync_set_timeout ( ua , UDP_FLUSH_TB , NULL , udp_trampoline , " udp_log_flush " ) ;
if ( ua ) g_udp_timer = uasync_set_timeout ( ua , UDP_FLUSH_TB , NULL , udp_trampoline , " udp_log_flush " ) ;
}
}
@ -63,6 +65,7 @@ void udp_trampoline(void* arg) {
void udp_log_set_target ( const char * ip , int port ) {
void udp_log_set_target ( const char * ip , int port ) {
g_udp_buf_len = 0 ;
g_udp_buf_len = 0 ;
g_udp_stopping = 0 ;
if ( ip & & port > 0 ) {
if ( ip & & port > 0 ) {
memset ( & g_udp_addr , 0 , sizeof ( g_udp_addr ) ) ;
memset ( & g_udp_addr , 0 , sizeof ( g_udp_addr ) ) ;
g_udp_addr . sin_family = AF_INET ;
g_udp_addr . sin_family = AF_INET ;
@ -90,11 +93,16 @@ void udp_log_write(const char* data, int len) {
}
}
}
}
void udp_log_stop ( void ) {
void udp_log_cancel_timer ( void ) {
g_udp_stopping = 1 ;
struct UASYNC * ua = instance_lite_get_uasync ( ) ;
struct UASYNC * ua = instance_lite_get_uasync ( ) ;
if ( ua & & g_udp_timer ) uasync_cancel_timeout ( ua , g_udp_timer ) ;
if ( ua & & g_udp_timer ) uasync_cancel_timeout ( ua , g_udp_timer ) ;
g_udp_timer = NULL ;
g_udp_timer = NULL ;
}
void udp_log_stop ( void ) {
g_udp_stopping = 1 ;
if ( g_udp_buf_len > 0 ) { udp_do_send ( g_udp_buf , g_udp_buf_len ) ; g_udp_buf_len = 0 ; }
if ( g_udp_fd > = 0 ) { close ( g_udp_fd ) ; g_udp_fd = - 1 ; }
if ( g_udp_fd > = 0 ) { close ( g_udp_fd ) ; g_udp_fd = - 1 ; }
g_udp_has_addr = 0 ;
g_udp_has_addr = 0 ;
g_udp_buf_len = 0 ;
}
}