@ -2954,7 +2954,7 @@ static int sip_check_authtimeout(time_t start)
*/
static void * _sip_tcp_helper_thread ( struct sip_pvt * pvt , struct ast_tcptls_session_instance * tcptls_session )
{
int res , cl , timeout = - 1 , authenticated = 0 , flags ;
int res , cl , timeout = - 1 , authenticated = 0 , flags , after_poll = 0 , need_poll = 1 ;
time_t start ;
struct sip_request req = { 0 , } , reqcpy = { 0 , } ;
struct sip_threadinfo * me = NULL ;
@ -3065,6 +3065,7 @@ static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_sessi
/* handle the socket event, check for both reads from the socket fd,
* and writes from alert_pipe fd */
if ( fds [ 0 ] . revents ) { /* there is data on the socket to be read */
after_poll = 1 ;
fds [ 0 ] . revents = 0 ;
@ -3105,22 +3106,32 @@ static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_sessi
timeout = - 1 ;
}
res = ast_wait_for_input ( tcptls_session - > fd , timeout ) ;
if ( res < 0 ) {
ast_debug ( 2 , " SIP %s server :: ast_wait_for_input returned %d \n " , tcptls_session - > ssl ? " SSL " : " TCP " , res ) ;
goto cleanup ;
} else if ( res = = 0 ) {
/* timeout */
ast_debug ( 2 , " SIP %s server timed out \n " , tcptls_session - > ssl ? " SSL " : " TCP " ) ;
goto cleanup ;
if ( ! tcptls_session - > ssl | | need_poll ) {
need_poll = 0 ;
after_poll = 1 ;
res = ast_wait_for_input ( tcptls_session - > fd , timeout ) ;
if ( res < 0 ) {
ast_debug ( 2 , " SIP %s server :: ast_wait_for_input returned %d \n " , tcptls_session - > ssl ? " SSL " : " TCP " , res ) ;
goto cleanup ;
} else if ( res = = 0 ) {
/* timeout */
ast_debug ( 2 , " SIP %s server timed out \n " , tcptls_session - > ssl ? " SSL " : " TCP " ) ;
goto cleanup ;
}
}
ast_mutex_lock ( & tcptls_session - > lock ) ;
if ( ! fgets ( buf , sizeof ( buf ) , tcptls_session - > f ) ) {
ast_mutex_unlock ( & tcptls_session - > lock ) ;
goto cleanup ;
if ( after_poll ) {
goto cleanup ;
} else {
need_poll = 1 ;
continue ;
}
}
ast_mutex_unlock ( & tcptls_session - > lock ) ;
after_poll = 0 ;
if ( me - > stop )
goto cleanup ;
ast_str_append ( & req . data , 0 , " %s " , buf ) ;
@ -3138,30 +3149,38 @@ static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_sessi
}
if ( timeout = = 0 ) {
ast_debug ( 2 , " SIP %s server timed out " , tcptls_session - > ssl ? " SSL " : " TCP " ) ;
ast_debug ( 2 , " SIP %s server timed out \n " , tcptls_session - > ssl ? " SSL " : " TCP " ) ;
goto cleanup ;
}
} else {
timeout = - 1 ;
}
res = ast_wait_for_input ( tcptls_session - > fd , timeout ) ;
if ( res < 0 ) {
ast_debug ( 2 , " SIP %s server :: ast_wait_for_input returned %d \n " , tcptls_session - > ssl ? " SSL " : " TCP " , res ) ;
goto cleanup ;
} else if ( res = = 0 ) {
/* timeout */
ast_debug ( 2 , " SIP %s server timed out " , tcptls_session - > ssl ? " SSL " : " TCP " ) ;
goto cleanup ;
if ( ! tcptls_session - > ssl | | need_poll ) {
res = ast_wait_for_input ( tcptls_session - > fd , timeout ) ;
if ( res < 0 ) {
ast_debug ( 2 , " SIP %s server :: ast_wait_for_input returned %d \n " , tcptls_session - > ssl ? " SSL " : " TCP " , res ) ;
goto cleanup ;
} else if ( res = = 0 ) {
/* timeout */
ast_debug ( 2 , " SIP %s server timed out \n " , tcptls_session - > ssl ? " SSL " : " TCP " ) ;
goto cleanup ;
}
}
ast_mutex_lock ( & tcptls_session - > lock ) ;
if ( ! ( bytes_read = fread ( buf , 1 , MIN ( sizeof ( buf ) - 1 , cl ) , tcptls_session - > f ) ) ) {
ast_mutex_unlock ( & tcptls_session - > lock ) ;
goto cleanup ;
if ( after_poll ) {
goto cleanup ;
} else {
need_poll = 1 ;
continue ;
}
}
buf [ bytes_read ] = ' \0 ' ;
ast_mutex_unlock ( & tcptls_session - > lock ) ;
after_poll = 0 ;
if ( me - > stop )
goto cleanup ;
cl - = strlen ( buf ) ;