@ -33,6 +33,7 @@ static void read_queue_drain_cb(struct ll_queue* q, void* arg);
static void pause_resume_cb ( struct ll_queue * q , void * arg ) ;
static void close_retry_cb ( void * arg ) ;
static void diag_timer_cb ( void * arg ) ;
static void retry_timer_cb ( void * arg ) ;
static int send_msg ( struct UTUN_INSTANCE * inst , uint64_t dst , uint8_t subcmd ,
uint32_t sid , const uint8_t * data , size_t len , int force ) ;
static void send_close ( struct tcp_proxy_server_conn * rc ) ;
@ -214,8 +215,10 @@ static void read_queue_drain_cb(struct ll_queue* q, void* arg) {
if ( rc - > tx_buf ) {
int ret = send_msg ( inst , rc - > peer_node_id , TCP_PROXY_SUBCMD_DATA , rc - > stream_id , rc - > tx_buf , rc - > tx_len , 0 ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_SOCKET , " TPS TXBUF RETRY: sid=%08x len=%u ret=%d " , rc - > stream_id , rc - > tx_len , ret ) ;
if ( ret = = 0 ) {
u_free ( rc - > tx_buf ) ; rc - > tx_buf = NULL ; rc - > tx_len = 0 ;
if ( rc - > retry_timer ) { uasync_cancel_timeout ( rc - > ua , rc - > retry_timer ) ; rc - > retry_timer = NULL ; }
if ( rc - > dst_fin_deferred & & ! q - > head ) {
rc - > dst_fin_deferred = 0 ;
send_fin ( rc ) ;
@ -224,6 +227,8 @@ static void read_queue_drain_cb(struct ll_queue* q, void* arg) {
} else {
etcp_router_on_send_ready ( inst , rc - > peer_node_id , ETCP_RT_ID_TCP_PROXY ,
& rc - > pause_waiter , pause_resume_cb , rc ) ;
if ( ! rc - > retry_timer ) rc - > retry_timer = uasync_set_timeout ( rc - > ua , 5000 , rc , retry_timer_cb , " tps_retry " ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_SOCKET , " TPS TXBUF BP AGAIN: sid=%08x waiter_reg " , rc - > stream_id ) ;
return ;
}
}
@ -261,6 +266,7 @@ static void read_queue_drain_cb(struct ll_queue* q, void* arg) {
( int ) rc - > tc - > sock , rc - > stream_id , rc - > tx_len ) ;
etcp_router_on_send_ready ( inst , rc - > peer_node_id , ETCP_RT_ID_TCP_PROXY ,
& rc - > pause_waiter , pause_resume_cb , rc ) ;
if ( ! rc - > retry_timer ) rc - > retry_timer = uasync_set_timeout ( rc - > ua , 5000 , rc , retry_timer_cb , " tps_retry " ) ;
}
}
@ -268,12 +274,32 @@ static void pause_resume_cb(struct ll_queue* q, void* arg) {
( void ) q ;
struct tcp_proxy_server_conn * rc = ( struct tcp_proxy_server_conn * ) arg ;
if ( ! rc - > tc | | rc - > tc - > sock = = SOCKET_INVALID | | rc - > cli_closed ) return ;
DEBUG_TRACE ( DEBUG_CATEGORY_SOCKET , " TPS RESUME sid=%08x tx_buf=%s rq=%d " ,
DEBUG_DEBUG ( DEBUG_CATEGORY_SOCKET , " TPS RESUME sid=%08x tx_buf=%s rq=%d " ,
rc - > stream_id , rc - > tx_buf ? " y " : " n " ,
rc - > tc - > read_queue ? rc - > tc - > read_queue - > count : 0 ) ;
queue_resume_callback ( rc - > tc - > read_queue ) ;
}
static void retry_timer_cb ( void * arg ) {
struct tcp_proxy_server_conn * rc = ( struct tcp_proxy_server_conn * ) arg ;
rc - > retry_timer = NULL ;
if ( ! rc - > tx_buf | | ! rc - > tc | | rc - > tc - > sock = = SOCKET_INVALID | | rc - > cli_closed ) return ;
struct UTUN_INSTANCE * inst = rc - > ctx ? rc - > ctx - > inst : NULL ;
int ret = send_msg ( inst , rc - > peer_node_id , TCP_PROXY_SUBCMD_DATA , rc - > stream_id , rc - > tx_buf , rc - > tx_len , 1 ) ;
DEBUG_DEBUG ( DEBUG_CATEGORY_SOCKET , " TPS RETRY TIMER: sid=%08x len=%u force=1 ret=%d " , rc - > stream_id , rc - > tx_len , ret ) ;
if ( ret = = 0 ) {
u_free ( rc - > tx_buf ) ; rc - > tx_buf = NULL ; rc - > tx_len = 0 ;
if ( rc - > dst_fin_deferred & & rc - > tc - > read_queue & & ! rc - > tc - > read_queue - > head ) {
rc - > dst_fin_deferred = 0 ;
send_fin ( rc ) ;
return ;
}
queue_resume_callback ( rc - > tc - > read_queue ) ;
} else {
rc - > retry_timer = uasync_set_timeout ( rc - > ua , 5000 , rc , retry_timer_cb , " tps_retry " ) ;
}
}
// ====================================================================
// Управление жизненным циклом коннекта
// ====================================================================
@ -307,6 +333,7 @@ void tcp_proxy_server_conn_free(struct tcp_proxy_server_conn* rc) {
}
if ( rc - > ctx & & rc - > ctx - > inst ) etcp_router_cancel_send_ready ( rc - > ctx - > inst , rc - > peer_node_id , ETCP_RT_ID_TCP_PROXY , & rc - > pause_waiter ) ;
if ( rc - > tx_buf ) { u_free ( rc - > tx_buf ) ; rc - > tx_buf = NULL ; rc - > tx_len = 0 ; }
if ( rc - > retry_timer ) { uasync_cancel_timeout ( rc - > ua , rc - > retry_timer ) ; rc - > retry_timer = NULL ; }
if ( rc - > close_timer ) { uasync_cancel_timeout ( rc - > ua , rc - > close_timer ) ; rc - > close_timer = NULL ; }
if ( rc - > diag_timer ) { uasync_cancel_timeout ( rc - > ua , rc - > diag_timer ) ; rc - > diag_timer = NULL ; }
if ( rc - > tc ) { tcp_conn_destroy ( rc - > tc ) ; rc - > tc = NULL ; }